diff --git a/appservice/appservice_test.go b/appservice/appservice_test.go index d2e5f903e..679b132df 100644 --- a/appservice/appservice_test.go +++ b/appservice/appservice_test.go @@ -18,7 +18,6 @@ import ( "github.com/matrix-org/dendrite/roomserver" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/jetstream" - "github.com/matrix-org/dendrite/setup/process" "github.com/matrix-org/dendrite/test" "github.com/matrix-org/dendrite/userapi" @@ -109,8 +108,8 @@ func TestAppserviceInternalAPI(t *testing.T) { } test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) { - cfg, closeDb := testrig.CreateConfig(t, dbType) - defer closeDb() + cfg, ctx, close := testrig.CreateConfig(t, dbType) + defer close() // Create a dummy application service cfg.AppServiceAPI.Derived.ApplicationServices = []config.ApplicationService{ @@ -128,7 +127,10 @@ func TestAppserviceInternalAPI(t *testing.T) { }, } - ctx := process.NewProcessContext() + t.Cleanup(func() { + ctx.ShutdownDendrite() + ctx.WaitForShutdown() + }) caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics) // Create required internal APIs natsInstance := jetstream.NATSInstance{} diff --git a/clientapi/admin_test.go b/clientapi/admin_test.go index ea0be64dc..84cdba7ce 100644 --- a/clientapi/admin_test.go +++ b/clientapi/admin_test.go @@ -16,7 +16,6 @@ import ( "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/jetstream" - "github.com/matrix-org/dendrite/setup/process" "github.com/matrix-org/dendrite/syncapi" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -35,16 +34,14 @@ func TestAdminResetPassword(t *testing.T) { ctx := context.Background() test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) { - cfg, closeDB := testrig.CreateConfig(t, dbType) - defer closeDB() + cfg, processCtx, close := testrig.CreateConfig(t, dbType) + defer close() natsInstance := jetstream.NATSInstance{} // add a vhost cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{ SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"}, }) - t.Logf("XXX: %#v", cfg.Global.VirtualHosts) - processCtx := process.NewProcessContext() routers := httputil.NewRouters() cm := sqlutil.NewConnectionManager(cfg.Global.DatabaseOptions) caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics) @@ -158,11 +155,11 @@ func TestPurgeRoom(t *testing.T) { ctx := context.Background() test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) { - cfg, closeDB := testrig.CreateConfig(t, dbType) + cfg, processCtx, close := testrig.CreateConfig(t, dbType) caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics) natsInstance := jetstream.NATSInstance{} - defer closeDB() - processCtx := process.NewProcessContext() + defer close() + routers := httputil.NewRouters() cm := sqlutil.NewConnectionManager(cfg.Global.DatabaseOptions) rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics) diff --git a/clientapi/routing/joinroom_test.go b/clientapi/routing/joinroom_test.go index bc7207450..b98b8558f 100644 --- a/clientapi/routing/joinroom_test.go +++ b/clientapi/routing/joinroom_test.go @@ -10,7 +10,6 @@ import ( "github.com/matrix-org/dendrite/internal/caching" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/setup/jetstream" - "github.com/matrix-org/dendrite/setup/process" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/dendrite/appservice" @@ -28,10 +27,9 @@ func TestJoinRoomByIDOrAlias(t *testing.T) { ctx := context.Background() test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) { - cfg, dbClose := testrig.CreateConfig(t, dbType) - defer dbClose() + cfg, processCtx, close := testrig.CreateConfig(t, dbType) + defer close() - processCtx := process.NewProcessContext() cm := sqlutil.NewConnectionManager(cfg.Global.DatabaseOptions) caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics) natsInstance := jetstream.NATSInstance{} diff --git a/clientapi/routing/login_test.go b/clientapi/routing/login_test.go index 9481a9c04..3c0f2afe4 100644 --- a/clientapi/routing/login_test.go +++ b/clientapi/routing/login_test.go @@ -16,7 +16,6 @@ import ( "github.com/matrix-org/dendrite/roomserver" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/jetstream" - "github.com/matrix-org/dendrite/setup/process" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -34,15 +33,15 @@ func TestLogin(t *testing.T) { ctx := context.Background() test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) { - cfg, closeDB := testrig.CreateConfig(t, dbType) - defer closeDB() + cfg, processCtx, close := testrig.CreateConfig(t, dbType) + defer close() cfg.ClientAPI.RateLimiting.Enabled = false natsInstance := jetstream.NATSInstance{} // add a vhost cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{ SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"}, }) - processCtx := process.NewProcessContext() + cm := sqlutil.NewConnectionManager(cfg.Global.DatabaseOptions) routers := httputil.NewRouters() caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics) diff --git a/clientapi/routing/register_test.go b/clientapi/routing/register_test.go index 51d0648c1..c866f0dfb 100644 --- a/clientapi/routing/register_test.go +++ b/clientapi/routing/register_test.go @@ -35,7 +35,6 @@ import ( "github.com/matrix-org/dendrite/roomserver" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/jetstream" - "github.com/matrix-org/dendrite/setup/process" "github.com/matrix-org/dendrite/test" "github.com/matrix-org/dendrite/test/testrig" "github.com/matrix-org/dendrite/userapi" @@ -408,12 +407,12 @@ func Test_register(t *testing.T) { } test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) { - cfg, dbClose := testrig.CreateConfig(t, dbType) - defer dbClose() + cfg, processCtx, close := testrig.CreateConfig(t, dbType) + defer close() caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics) natsInstance := jetstream.NATSInstance{} - processCtx := process.NewProcessContext() + cm := sqlutil.NewConnectionManager(cfg.Global.DatabaseOptions) rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics) userAPI := userapi.NewInternalAPI(processCtx, cfg, cm, &natsInstance, rsAPI, nil) @@ -582,11 +581,10 @@ func Test_register(t *testing.T) { func TestRegisterUserWithDisplayName(t *testing.T) { test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) { - cfg, baseClose := testrig.CreateConfig(t, dbType) - defer baseClose() + cfg, processCtx, close := testrig.CreateConfig(t, dbType) + defer close() cfg.Global.ServerName = "server" - processCtx := process.NewProcessContext() caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics) natsInstance := jetstream.NATSInstance{} cm := sqlutil.NewConnectionManager(cfg.Global.DatabaseOptions) @@ -623,13 +621,13 @@ func TestRegisterUserWithDisplayName(t *testing.T) { func TestRegisterAdminUsingSharedSecret(t *testing.T) { test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) { - cfg, closeDb := testrig.CreateConfig(t, dbType) - defer closeDb() + cfg, processCtx, close := testrig.CreateConfig(t, dbType) + defer close() natsInstance := jetstream.NATSInstance{} cfg.Global.ServerName = "server" sharedSecret := "dendritetest" cfg.ClientAPI.RegistrationSharedSecret = sharedSecret - processCtx := process.NewProcessContext() + cm := sqlutil.NewConnectionManager(cfg.Global.DatabaseOptions) caches := caching.NewRistrettoCache(128*1024*1024, time.Hour, caching.DisableMetrics) rsAPI := roomserver.NewInternalAPI(processCtx, cfg, cm, &natsInstance, caches, caching.DisableMetrics) diff --git a/setup/config/config_global.go b/setup/config/config_global.go index 4f461368f..7d3ab6a40 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -8,7 +8,6 @@ import ( "time" "github.com/matrix-org/gomatrixserverlib" - "github.com/sirupsen/logrus" "golang.org/x/crypto/ed25519" ) @@ -126,7 +125,6 @@ func (c *Global) IsLocalServerName(serverName gomatrixserverlib.ServerName) bool if c.ServerName == serverName { return true } - logrus.Infof("XXX: %#v", c.VirtualHosts) for _, v := range c.VirtualHosts { if v.ServerName == serverName { return true diff --git a/test/testrig/base.go b/test/testrig/base.go index 2a7bb8ba0..5e56242fc 100644 --- a/test/testrig/base.go +++ b/test/testrig/base.go @@ -22,6 +22,7 @@ import ( "github.com/matrix-org/dendrite/setup/base" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/jetstream" + "github.com/matrix-org/dendrite/setup/process" "github.com/matrix-org/dendrite/test" "github.com/nats-io/nats.go" ) @@ -99,7 +100,7 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f return nil, nil } -func CreateConfig(t *testing.T, dbType test.DBType) (*config.Dendrite, func()) { +func CreateConfig(t *testing.T, dbType test.DBType) (*config.Dendrite, *process.ProcessContext, func()) { var cfg config.Dendrite cfg.Defaults(config.DefaultOpts{ Generate: false, @@ -107,6 +108,7 @@ func CreateConfig(t *testing.T, dbType test.DBType) (*config.Dendrite, func()) { }) cfg.Global.JetStream.InMemory = true cfg.FederationAPI.KeyPerspectives = nil + ctx := process.NewProcessContext() switch dbType { case test.DBTypePostgres: cfg.Global.Defaults(config.DefaultOpts{ // autogen a signing key @@ -133,7 +135,11 @@ func CreateConfig(t *testing.T, dbType test.DBType) (*config.Dendrite, func()) { MaxIdleConnections: 2, ConnMaxLifetimeSeconds: 60, } - return &cfg, closeDb + return &cfg, ctx, func() { + closeDb() + ctx.ShutdownDendrite() + ctx.WaitForShutdown() + } case test.DBTypeSQLite: cfg.Defaults(config.DefaultOpts{ Generate: true, @@ -156,11 +162,14 @@ func CreateConfig(t *testing.T, dbType test.DBType) (*config.Dendrite, func()) { cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(filepath.Join("file://", tempDir, "userapi.db")) cfg.RelayAPI.Database.ConnectionString = config.DataSource(filepath.Join("file://", tempDir, "relayapi.db")) - return &cfg, func() {} + return &cfg, ctx, func() { + ctx.ShutdownDendrite() + ctx.WaitForShutdown() + } default: t.Fatalf("unknown db type: %v", dbType) } - return &config.Dendrite{}, func() {} + return &config.Dendrite{}, nil, func() {} } func Base(cfg *config.Dendrite) (*base.BaseDendrite, nats.JetStreamContext, *nats.Conn) {