mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 10:33:11 -06:00
Let CreateConfig return a ProcessContext
This commit is contained in:
parent
fffd2d9228
commit
edb5b4b637
|
|
@ -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{}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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{}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue