mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Fix federation tests, NewBaseDendrite can accept freeform options
This commit is contained in:
parent
0123ed60fe
commit
906d744983
|
|
@ -54,7 +54,7 @@ type P2PDendrite struct {
|
||||||
// The componentName is used for logging purposes, and should be a friendly name
|
// The componentName is used for logging purposes, and should be a friendly name
|
||||||
// of the component running, e.g. SyncAPI.
|
// of the component running, e.g. SyncAPI.
|
||||||
func NewP2PDendrite(cfg *config.Dendrite, componentName string) *P2PDendrite {
|
func NewP2PDendrite(cfg *config.Dendrite, componentName string) *P2PDendrite {
|
||||||
baseDendrite := base.NewBaseDendrite(cfg, componentName, false)
|
baseDendrite := base.NewBaseDendrite(cfg, componentName)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
base := base.NewBaseDendrite(cfg, "Monolith", false)
|
base := base.NewBaseDendrite(cfg, "Monolith")
|
||||||
defer base.Close() // nolint: errcheck
|
defer base.Close() // nolint: errcheck
|
||||||
|
|
||||||
accountDB := base.CreateAccountsDB()
|
accountDB := base.CreateAccountsDB()
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
base := base.NewBaseDendrite(cfg, "Monolith", false)
|
base := base.NewBaseDendrite(cfg, "Monolith")
|
||||||
defer base.Close() // nolint: errcheck
|
defer base.Close() // nolint: errcheck
|
||||||
|
|
||||||
accountDB := base.CreateAccountsDB()
|
accountDB := base.CreateAccountsDB()
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ func main() {
|
||||||
httpAddr := config.HTTPAddress("http://" + *httpBindAddr)
|
httpAddr := config.HTTPAddress("http://" + *httpBindAddr)
|
||||||
httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr)
|
httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr)
|
||||||
httpAPIAddr := httpAddr
|
httpAPIAddr := httpAddr
|
||||||
|
options := []basepkg.BaseDendriteOptions{}
|
||||||
if *enableHTTPAPIs {
|
if *enableHTTPAPIs {
|
||||||
logrus.Warnf("DANGER! The -api option is enabled, exposing internal APIs on %q!", *apiBindAddr)
|
logrus.Warnf("DANGER! The -api option is enabled, exposing internal APIs on %q!", *apiBindAddr)
|
||||||
httpAPIAddr = config.HTTPAddress("http://" + *apiBindAddr)
|
httpAPIAddr = config.HTTPAddress("http://" + *apiBindAddr)
|
||||||
|
|
@ -67,9 +67,10 @@ func main() {
|
||||||
cfg.MediaAPI.InternalAPI.Connect = httpAPIAddr
|
cfg.MediaAPI.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.RoomServer.InternalAPI.Connect = httpAPIAddr
|
cfg.RoomServer.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.SyncAPI.InternalAPI.Connect = httpAPIAddr
|
cfg.SyncAPI.InternalAPI.Connect = httpAPIAddr
|
||||||
|
options = append(options, basepkg.UseHTTPAPIs)
|
||||||
}
|
}
|
||||||
|
|
||||||
base := basepkg.NewBaseDendrite(cfg, "Monolith", *enableHTTPAPIs)
|
base := basepkg.NewBaseDendrite(cfg, "Monolith", options...)
|
||||||
defer base.Close() // nolint: errcheck
|
defer base.Close() // nolint: errcheck
|
||||||
|
|
||||||
accountDB := base.CreateAccountsDB()
|
accountDB := base.CreateAccountsDB()
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ func main() {
|
||||||
|
|
||||||
logrus.Infof("Starting %q component", component)
|
logrus.Infof("Starting %q component", component)
|
||||||
|
|
||||||
base := base.NewBaseDendrite(cfg, component, false) // TODO
|
base := base.NewBaseDendrite(cfg, component) // TODO
|
||||||
defer base.Close() // nolint: errcheck
|
defer base.Close() // nolint: errcheck
|
||||||
|
|
||||||
go start(base, cfg)
|
go start(base, cfg)
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ func startup() {
|
||||||
if err := cfg.Derive(); err != nil {
|
if err := cfg.Derive(); err != nil {
|
||||||
logrus.Fatalf("Failed to derive values from config: %s", err)
|
logrus.Fatalf("Failed to derive values from config: %s", err)
|
||||||
}
|
}
|
||||||
base := base.NewBaseDendrite(cfg, "Monolith", false)
|
base := base.NewBaseDendrite(cfg, "Monolith")
|
||||||
defer base.Close() // nolint: errcheck
|
defer base.Close() // nolint: errcheck
|
||||||
|
|
||||||
accountDB := base.CreateAccountsDB()
|
accountDB := base.CreateAccountsDB()
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ func main() {
|
||||||
if err := cfg.Derive(); err != nil {
|
if err := cfg.Derive(); err != nil {
|
||||||
logrus.Fatalf("Failed to derive values from config: %s", err)
|
logrus.Fatalf("Failed to derive values from config: %s", err)
|
||||||
}
|
}
|
||||||
base := setup.NewBaseDendrite(cfg, "Monolith", false)
|
base := setup.NewBaseDendrite(cfg, "Monolith")
|
||||||
defer base.Close() // nolint: errcheck
|
defer base.Close() // nolint: errcheck
|
||||||
|
|
||||||
accountDB := base.CreateAccountsDB()
|
accountDB := base.CreateAccountsDB()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package federationapi
|
package federationapi
|
||||||
|
|
||||||
/*
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -17,6 +16,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/federationapi/api"
|
"github.com/matrix-org/dendrite/federationapi/api"
|
||||||
"github.com/matrix-org/dendrite/federationapi/routing"
|
"github.com/matrix-org/dendrite/federationapi/routing"
|
||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
|
"github.com/matrix-org/dendrite/setup/base"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
@ -74,6 +74,7 @@ func TestMain(m *testing.M) {
|
||||||
cfg.Defaults()
|
cfg.Defaults()
|
||||||
cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name)
|
cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name)
|
||||||
cfg.Global.PrivateKey = testPriv
|
cfg.Global.PrivateKey = testPriv
|
||||||
|
cfg.Global.Kafka.UseNaffka = true
|
||||||
cfg.Global.KeyID = serverKeyID
|
cfg.Global.KeyID = serverKeyID
|
||||||
cfg.Global.KeyValidityPeriod = s.validity
|
cfg.Global.KeyValidityPeriod = s.validity
|
||||||
cfg.FederationAPI.Database.ConnectionString = config.DataSource("file::memory:")
|
cfg.FederationAPI.Database.ConnectionString = config.DataSource("file::memory:")
|
||||||
|
|
@ -92,7 +93,8 @@ func TestMain(m *testing.M) {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Finally, build the server key APIs.
|
// Finally, build the server key APIs.
|
||||||
s.api = NewInternalAPI(s.config, s.fedclient, s.cache, true)
|
sbase := base.NewBaseDendrite(cfg, "Monolith", base.NoCacheMetrics)
|
||||||
|
s.api = NewInternalAPI(sbase, s.fedclient, nil, s.cache, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we have built our server key APIs, start the
|
// Now that we have built our server key APIs, start the
|
||||||
|
|
@ -316,4 +318,3 @@ func TestRenewalBehaviour(t *testing.T) {
|
||||||
}
|
}
|
||||||
t.Log(res)
|
t.Log(res)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
@ -26,7 +26,7 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
|
||||||
cfg.Global.Kafka.UseNaffka = true
|
cfg.Global.Kafka.UseNaffka = true
|
||||||
cfg.Global.Kafka.Database.ConnectionString = config.DataSource("file::memory:")
|
cfg.Global.Kafka.Database.ConnectionString = config.DataSource("file::memory:")
|
||||||
cfg.FederationAPI.Database.ConnectionString = config.DataSource("file::memory:")
|
cfg.FederationAPI.Database.ConnectionString = config.DataSource("file::memory:")
|
||||||
base := base.NewBaseDendrite(cfg, "Monolith", false)
|
base := base.NewBaseDendrite(cfg, "Monolith", base.NoCacheMetrics)
|
||||||
keyRing := &test.NopJSONVerifier{}
|
keyRing := &test.NopJSONVerifier{}
|
||||||
fsAPI := base.FederationAPIHTTPClient()
|
fsAPI := base.FederationAPIHTTPClient()
|
||||||
// TODO: This is pretty fragile, as if anything calls anything on these nils this test will break.
|
// TODO: This is pretty fragile, as if anything calls anything on these nils this test will break.
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,28 @@ const NoListener = ""
|
||||||
const HTTPServerTimeout = time.Minute * 5
|
const HTTPServerTimeout = time.Minute * 5
|
||||||
const HTTPClientTimeout = time.Second * 30
|
const HTTPClientTimeout = time.Second * 30
|
||||||
|
|
||||||
|
type BaseDendriteOptions int
|
||||||
|
|
||||||
|
const (
|
||||||
|
NoCacheMetrics BaseDendriteOptions = iota
|
||||||
|
UseHTTPAPIs
|
||||||
|
)
|
||||||
|
|
||||||
// NewBaseDendrite creates a new instance to be used by a component.
|
// NewBaseDendrite creates a new instance to be used by a component.
|
||||||
// The componentName is used for logging purposes, and should be a friendly name
|
// The componentName is used for logging purposes, and should be a friendly name
|
||||||
// of the compontent running, e.g. "SyncAPI"
|
// of the compontent running, e.g. "SyncAPI"
|
||||||
func NewBaseDendrite(cfg *config.Dendrite, componentName string, useHTTPAPIs bool) *BaseDendrite {
|
func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...BaseDendriteOptions) *BaseDendrite {
|
||||||
|
useHTTPAPIs := false
|
||||||
|
cacheMetrics := true
|
||||||
|
for _, opt := range options {
|
||||||
|
switch opt {
|
||||||
|
case NoCacheMetrics:
|
||||||
|
cacheMetrics = false
|
||||||
|
case UseHTTPAPIs:
|
||||||
|
useHTTPAPIs = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
configErrors := &config.ConfigErrors{}
|
configErrors := &config.ConfigErrors{}
|
||||||
cfg.Verify(configErrors, componentName == "Monolith") // TODO: better way?
|
cfg.Verify(configErrors, componentName == "Monolith") // TODO: better way?
|
||||||
if len(*configErrors) > 0 {
|
if len(*configErrors) > 0 {
|
||||||
|
|
@ -131,7 +149,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, useHTTPAPIs boo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache, err := caching.NewInMemoryLRUCache(true)
|
cache, err := caching.NewInMemoryLRUCache(cacheMetrics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Warnf("Failed to create cache")
|
logrus.WithError(err).Warnf("Failed to create cache")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue