mirror of
https://github.com/mjl-/mox.git
synced 2025-07-13 08:54:38 +03:00
In tests, make initializing store/, its switchboard and an account more consistent.
Initialize store and switchboard first, then open account, and close in reverse order. Replace all "CheckClosed" calls with "WaitClosed", future changings will keep an account reference open for a bit after the last regular close, so we can't know that an account should be closed during tests. Remove one parameter from the (still too long) "start test server" function in imapserver testing code.
This commit is contained in:
@ -81,7 +81,7 @@ func TestAliasSubmitMsgFromDenied(t *testing.T) {
|
||||
tcheck(t, err, "set password")
|
||||
err = acc.Close()
|
||||
tcheck(t, err, "close account")
|
||||
acc.CheckClosed()
|
||||
acc.WaitClosed()
|
||||
|
||||
ts.submission = true
|
||||
ts.user = "☺@mox.example"
|
||||
|
@ -42,6 +42,7 @@ func FuzzServer(f *testing.F) {
|
||||
if err != nil {
|
||||
f.Fatalf("store init: %v", err)
|
||||
}
|
||||
defer store.Switchboard()()
|
||||
|
||||
acc, err := store.OpenAccount(log, "mjl", false)
|
||||
if err != nil {
|
||||
@ -55,7 +56,7 @@ func FuzzServer(f *testing.F) {
|
||||
if err != nil {
|
||||
f.Fatalf("set password: %v", err)
|
||||
}
|
||||
defer store.Switchboard()()
|
||||
|
||||
err = queue.Init()
|
||||
if err != nil {
|
||||
f.Fatalf("queue init: %v", err)
|
||||
|
@ -155,15 +155,15 @@ func newTestServer(t *testing.T, configPath string, resolver dns.Resolver) *test
|
||||
err = store.Init(ctxbg)
|
||||
tcheck(t, err, "store init")
|
||||
|
||||
ts.switchStop = store.Switchboard()
|
||||
err = queue.Init()
|
||||
tcheck(t, err, "queue init")
|
||||
|
||||
ts.acc, err = store.OpenAccount(log, "mjl", false)
|
||||
tcheck(t, err, "open account")
|
||||
err = ts.acc.SetPassword(log, password0)
|
||||
tcheck(t, err, "set password")
|
||||
|
||||
ts.switchStop = store.Switchboard()
|
||||
err = queue.Init()
|
||||
tcheck(t, err, "queue init")
|
||||
|
||||
ts.comm = store.RegisterComm(ts.acc)
|
||||
|
||||
return &ts
|
||||
@ -177,15 +177,15 @@ func (ts *testserver) close() {
|
||||
tcheck(ts.t, err, "dmarcdb close")
|
||||
err = tlsrptdb.Close()
|
||||
tcheck(ts.t, err, "tlsrptdb close")
|
||||
err = store.Close()
|
||||
tcheck(ts.t, err, "store close")
|
||||
ts.comm.Unregister()
|
||||
queue.Shutdown()
|
||||
ts.switchStop()
|
||||
err = ts.acc.Close()
|
||||
tcheck(ts.t, err, "closing account")
|
||||
ts.acc.WaitClosed()
|
||||
ts.acc = nil
|
||||
ts.switchStop()
|
||||
err = store.Close()
|
||||
tcheck(ts.t, err, "store close")
|
||||
}
|
||||
|
||||
func (ts *testserver) checkCount(mailboxName string, expect int) {
|
||||
@ -1505,7 +1505,7 @@ func TestCatchall(t *testing.T) {
|
||||
tcheck(t, err, "open account")
|
||||
defer func() {
|
||||
acc.Close()
|
||||
acc.CheckClosed()
|
||||
acc.WaitClosed()
|
||||
}()
|
||||
n, err = bstore.QueryDB[store.Message](ctxbg, acc.DB).Count()
|
||||
tcheck(t, err, "checking delivered messages to catchall account")
|
||||
|
Reference in New Issue
Block a user