mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 01:48:15 +03:00
fix flaky test where closing the imapclient connection fails because the server has also closed the tls connection
This commit is contained in:
parent
14af5bbb12
commit
53f391ad18
@ -188,14 +188,15 @@ func mockUIDValidity() func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type testconn struct {
|
type testconn struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
client *imapclient.Conn
|
client *imapclient.Conn
|
||||||
uidonly bool
|
uidonly bool
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
serverConn net.Conn
|
serverConn net.Conn
|
||||||
account *store.Account
|
account *store.Account
|
||||||
switchStop func()
|
switchStop func()
|
||||||
|
clientPanic bool
|
||||||
|
|
||||||
// Result of last command.
|
// Result of last command.
|
||||||
lastResponse imapclient.Response
|
lastResponse imapclient.Response
|
||||||
@ -400,6 +401,7 @@ func (tc *testconn) close0(waitclose bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if tc.client != nil {
|
if tc.client != nil {
|
||||||
|
tc.clientPanic = false // Ignore errors writing to TLS connection the server also closed.
|
||||||
tc.client.Close()
|
tc.client.Close()
|
||||||
}
|
}
|
||||||
err := tc.account.Close()
|
err := tc.account.Close()
|
||||||
@ -557,12 +559,20 @@ func startArgsMore(t *testing.T, uidonly, first, immediateTLS bool, serverConfig
|
|||||||
serve("test", cid, serverConfig, serverConn, immediateTLS, allowLoginWithoutTLS, viaHTTPS, "")
|
serve("test", cid, serverConfig, serverConn, immediateTLS, allowLoginWithoutTLS, viaHTTPS, "")
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
opts := imapclient.Opts{
|
var tc *testconn
|
||||||
|
var opts imapclient.Opts
|
||||||
|
opts = imapclient.Opts{
|
||||||
Logger: slog.Default().With("cid", connCounter),
|
Logger: slog.Default().With("cid", connCounter),
|
||||||
Error: func(err error) { panic(err) },
|
Error: func(err error) {
|
||||||
|
if tc.clientPanic {
|
||||||
|
panic(err)
|
||||||
|
} else {
|
||||||
|
opts.Logger.Error("imapclient error", "err", err)
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, _ := imapclient.New(clientConn, &opts)
|
client, _ := imapclient.New(clientConn, &opts)
|
||||||
tc := &testconn{t: t, conn: clientConn, client: client, uidonly: uidonly, done: done, serverConn: serverConn, account: acc}
|
tc = &testconn{t: t, conn: clientConn, client: client, uidonly: uidonly, done: done, serverConn: serverConn, account: acc, clientPanic: true}
|
||||||
if first {
|
if first {
|
||||||
tc.switchStop = switchStop
|
tc.switchStop = switchStop
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user