diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2023-01-20 12:45:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-20 12:45:56 +0100 |
commit | ce2bfc3f2e507a012044906af7f25c9dc52873d7 (patch) | |
tree | dbfc33abaa3e03cff17886d085b45869ad81df44 /test | |
parent | 738686ae686004c5efa9fe2096502cdc426c6dd8 (diff) |
Make tests more reliable (#2948)
When using `testrig.CreateBase` and then using that base for other
`NewInternalAPI` calls, we never actually shutdown the components.
`testrig.CreateBase` returns a `close` function, which only removes the
database, so still running components have issues connecting to the
database, since we ripped it out underneath it - which can result in
"Disk I/O" or "pq deadlock detected" issues.
Diffstat (limited to 'test')
-rw-r--r-- | test/testrig/base.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/test/testrig/base.go b/test/testrig/base.go index 7bc26a5c..52e6ef5f 100644 --- a/test/testrig/base.go +++ b/test/testrig/base.go @@ -62,7 +62,12 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f MaxIdleConnections: 2, ConnMaxLifetimeSeconds: 60, } - return base.NewBaseDendrite(&cfg, "Test", base.DisableMetrics), close + base := base.NewBaseDendrite(&cfg, "Test", base.DisableMetrics) + return base, func() { + base.ShutdownDendrite() + base.WaitForShutdown() + close() + } case test.DBTypeSQLite: cfg.Defaults(config.DefaultOpts{ Generate: true, @@ -72,7 +77,10 @@ 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) - return base.NewBaseDendrite(&cfg, "Test", base.DisableMetrics), func() { + base := base.NewBaseDendrite(&cfg, "Test", base.DisableMetrics) + return base, func() { + base.ShutdownDendrite() + base.WaitForShutdown() // cleanup db files. This risks getting out of sync as we add more database strings :( dbFiles := []config.DataSource{ cfg.FederationAPI.Database.ConnectionString, |