imapserver: Prevent spurious test failures due to compression layer being closed and TLS close-writes failing

This commit is contained in:
Mechiel Lukkien 2025-02-26 15:41:46 +01:00
parent 062c3ac182
commit 9c40205343
No known key found for this signature in database
2 changed files with 15 additions and 0 deletions

View File

@ -170,10 +170,20 @@ func (c *Conn) xflush() {
}
}
// SetPanic sets whether errors cause a panic instead of returning errors.
func (c *Conn) SetPanic(panic bool) {
c.panic = panic
}
// Close closes the connection, flushing and closing any compression and TLS layer.
//
// You may want to call Logout first. Closing a connection with a mailbox with
// deleted messages not yet expunged will not expunge those messages.
//
// Closing a TLS connection that is logged out, or closing a TLS connection with
// compression enabled (i.e. two layered streams), may cause spurious errors
// because the server may immediate close the underlying connection when it sees
// the connection is being closed.
func (c *Conn) Close() (rerr error) {
defer c.recover(&rerr)

View File

@ -40,6 +40,11 @@ func TestCompressStartTLS(t *testing.T) {
tc.transactf("ok", "append inbox (\\seen) {%d+}\r\n%s", len(exampleMsg), exampleMsg)
tc.transactf("ok", "noop")
tc.transactf("ok", "fetch 1 body.peek[1]")
// Prevent client.Close from failing the test. The client first closes the
// compression stream, which causes the server to close the connection, after which
// the messages to close the TLS connection are written to a closed socket.
tc.client.SetPanic(false)
}
func TestCompressBreak(t *testing.T) {