aboutsummaryrefslogtreecommitdiff
path: root/test/testrig
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-03-22 09:21:32 +0100
committerGitHub <noreply@github.com>2023-03-22 09:21:32 +0100
commit5e85a00cb36c3d343cd5b6f6a18435989724a135 (patch)
treeb22c34dd0a6cdc04025b90086843f9084a876412 /test/testrig
parentec6879e5ae2919c903707475ce8d72244b2a6847 (diff)
Remove `BaseDendrite` (#3023)
Removes `BaseDendrite` to, hopefully, make testing and composing of components easier in the future.
Diffstat (limited to 'test/testrig')
-rw-r--r--test/testrig/base.go43
-rw-r--r--test/testrig/jetstream.go6
2 files changed, 16 insertions, 33 deletions
diff --git a/test/testrig/base.go b/test/testrig/base.go
index bb8fded2..fd85578e 100644
--- a/test/testrig/base.go
+++ b/test/testrig/base.go
@@ -19,13 +19,12 @@ import (
"path/filepath"
"testing"
- "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
+ "github.com/matrix-org/dendrite/setup/process"
"github.com/matrix-org/dendrite/test"
- "github.com/nats-io/nats.go"
)
-func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, func()) {
+func CreateConfig(t *testing.T, dbType test.DBType) (*config.Dendrite, *process.ProcessContext, func()) {
var cfg config.Dendrite
cfg.Defaults(config.DefaultOpts{
Generate: false,
@@ -33,6 +32,7 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f
})
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
@@ -51,18 +51,18 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f
// use a distinct prefix else concurrent postgres/sqlite runs will clash since NATS will use
// the file system event with InMemory=true :(
cfg.Global.JetStream.TopicPrefix = fmt.Sprintf("Test_%d_", dbType)
- connStr, close := test.PrepareDBConnectionString(t, dbType)
+
+ connStr, closeDb := test.PrepareDBConnectionString(t, dbType)
cfg.Global.DatabaseOptions = config.DatabaseOptions{
ConnectionString: config.DataSource(connStr),
MaxOpenConnections: 10,
MaxIdleConnections: 2,
ConnMaxLifetimeSeconds: 60,
}
- base := base.NewBaseDendrite(&cfg, base.DisableMetrics)
- return base, func() {
- base.ShutdownDendrite()
- base.WaitForShutdown()
- close()
+ return &cfg, ctx, func() {
+ ctx.ShutdownDendrite()
+ ctx.WaitForShutdown()
+ closeDb()
}
case test.DBTypeSQLite:
cfg.Defaults(config.DefaultOpts{
@@ -86,30 +86,13 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f
cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(filepath.Join("file://", tempDir, "userapi.db"))
cfg.RelayAPI.Database.ConnectionString = config.DataSource(filepath.Join("file://", tempDir, "relayapi.db"))
- base := base.NewBaseDendrite(&cfg, base.DisableMetrics)
- return base, func() {
- base.ShutdownDendrite()
- base.WaitForShutdown()
+ return &cfg, ctx, func() {
+ ctx.ShutdownDendrite()
+ ctx.WaitForShutdown()
t.Cleanup(func() {}) // removes t.TempDir, where all database files are created
}
default:
t.Fatalf("unknown db type: %v", dbType)
}
- return nil, nil
-}
-
-func Base(cfg *config.Dendrite) (*base.BaseDendrite, nats.JetStreamContext, *nats.Conn) {
- if cfg == nil {
- cfg = &config.Dendrite{}
- cfg.Defaults(config.DefaultOpts{
- Generate: true,
- SingleDatabase: false,
- })
- }
- cfg.Global.JetStream.InMemory = true
- cfg.SyncAPI.Fulltext.InMemory = true
- cfg.FederationAPI.KeyPerspectives = nil
- base := base.NewBaseDendrite(cfg, base.DisableMetrics)
- js, jc := base.NATS.Prepare(base.ProcessContext, &cfg.Global.JetStream)
- return base, js, jc
+ return &config.Dendrite{}, nil, func() {}
}
diff --git a/test/testrig/jetstream.go b/test/testrig/jetstream.go
index b880eea4..5f15cfb3 100644
--- a/test/testrig/jetstream.go
+++ b/test/testrig/jetstream.go
@@ -4,10 +4,10 @@ import (
"encoding/json"
"testing"
+ "github.com/matrix-org/dendrite/setup/config"
"github.com/nats-io/nats.go"
"github.com/matrix-org/dendrite/roomserver/api"
- "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/jetstream"
)
@@ -20,9 +20,9 @@ func MustPublishMsgs(t *testing.T, jsctx nats.JetStreamContext, msgs ...*nats.Ms
}
}
-func NewOutputEventMsg(t *testing.T, base *base.BaseDendrite, roomID string, update api.OutputEvent) *nats.Msg {
+func NewOutputEventMsg(t *testing.T, cfg *config.Dendrite, roomID string, update api.OutputEvent) *nats.Msg {
t.Helper()
- msg := nats.NewMsg(base.Cfg.Global.JetStream.Prefixed(jetstream.OutputRoomEvent))
+ msg := nats.NewMsg(cfg.Global.JetStream.Prefixed(jetstream.OutputRoomEvent))
msg.Header.Set(jetstream.RoomEventType, string(update.Type))
msg.Header.Set(jetstream.RoomID, roomID)
var err error