Fix federation tests, NewBaseDendrite can accept freeform options

This commit is contained in:
Neil Alexander 2021-11-23 13:31:35 +00:00
parent 0123ed60fe
commit 906d744983
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
10 changed files with 35 additions and 15 deletions

View file

@ -54,7 +54,7 @@ type P2PDendrite struct {
// The componentName is used for logging purposes, and should be a friendly name
// of the component running, e.g. SyncAPI.
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())

View file

@ -161,7 +161,7 @@ func main() {
panic(err)
}
base := base.NewBaseDendrite(cfg, "Monolith", false)
base := base.NewBaseDendrite(cfg, "Monolith")
defer base.Close() // nolint: errcheck
accountDB := base.CreateAccountsDB()

View file

@ -93,7 +93,7 @@ func main() {
panic(err)
}
base := base.NewBaseDendrite(cfg, "Monolith", false)
base := base.NewBaseDendrite(cfg, "Monolith")
defer base.Close() // nolint: errcheck
accountDB := base.CreateAccountsDB()

View file

@ -51,7 +51,7 @@ func main() {
httpAddr := config.HTTPAddress("http://" + *httpBindAddr)
httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr)
httpAPIAddr := httpAddr
options := []basepkg.BaseDendriteOptions{}
if *enableHTTPAPIs {
logrus.Warnf("DANGER! The -api option is enabled, exposing internal APIs on %q!", *apiBindAddr)
httpAPIAddr = config.HTTPAddress("http://" + *apiBindAddr)
@ -67,9 +67,10 @@ func main() {
cfg.MediaAPI.InternalAPI.Connect = httpAPIAddr
cfg.RoomServer.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
accountDB := base.CreateAccountsDB()

View file

@ -72,8 +72,8 @@ func main() {
logrus.Infof("Starting %q component", component)
base := base.NewBaseDendrite(cfg, component, false) // TODO
defer base.Close() // nolint: errcheck
base := base.NewBaseDendrite(cfg, component) // TODO
defer base.Close() // nolint: errcheck
go start(base, cfg)
base.WaitForShutdown()

View file

@ -180,7 +180,7 @@ func startup() {
if err := cfg.Derive(); err != nil {
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
accountDB := base.CreateAccountsDB()

View file

@ -187,7 +187,7 @@ func main() {
if err := cfg.Derive(); err != nil {
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
accountDB := base.CreateAccountsDB()

View file

@ -1,6 +1,5 @@
package federationapi
/*
import (
"bytes"
"context"
@ -17,6 +16,7 @@ import (
"github.com/matrix-org/dendrite/federationapi/api"
"github.com/matrix-org/dendrite/federationapi/routing"
"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/gomatrixserverlib"
)
@ -74,6 +74,7 @@ func TestMain(m *testing.M) {
cfg.Defaults()
cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name)
cfg.Global.PrivateKey = testPriv
cfg.Global.Kafka.UseNaffka = true
cfg.Global.KeyID = serverKeyID
cfg.Global.KeyValidityPeriod = s.validity
cfg.FederationAPI.Database.ConnectionString = config.DataSource("file::memory:")
@ -92,7 +93,8 @@ func TestMain(m *testing.M) {
)
// 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
@ -316,4 +318,3 @@ func TestRenewalBehaviour(t *testing.T) {
}
t.Log(res)
}
*/

View file

@ -26,7 +26,7 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
cfg.Global.Kafka.UseNaffka = true
cfg.Global.Kafka.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{}
fsAPI := base.FederationAPIHTTPClient()
// TODO: This is pretty fragile, as if anything calls anything on these nils this test will break.

View file

@ -92,10 +92,28 @@ const NoListener = ""
const HTTPServerTimeout = time.Minute * 5
const HTTPClientTimeout = time.Second * 30
type BaseDendriteOptions int
const (
NoCacheMetrics BaseDendriteOptions = iota
UseHTTPAPIs
)
// NewBaseDendrite creates a new instance to be used by a component.
// The componentName is used for logging purposes, and should be a friendly name
// 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{}
cfg.Verify(configErrors, componentName == "Monolith") // TODO: better way?
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 {
logrus.WithError(err).Warnf("Failed to create cache")
}