diff --git a/test/context/context.go b/test/context/context.go index 59f76737..b1538590 100644 --- a/test/context/context.go +++ b/test/context/context.go @@ -19,6 +19,8 @@ package context import ( + "sync" + "github.com/ProtonMail/proton-bridge/internal/bridge" "github.com/ProtonMail/proton-bridge/internal/importexport" "github.com/ProtonMail/proton-bridge/internal/transfer" @@ -56,16 +58,18 @@ type TestContext struct { lastError error // IMAP related variables. - imapAddr string - imapServer server - imapClients map[string]*mocks.IMAPClient - imapLastResponses map[string]*mocks.IMAPResponse + imapAddr string + imapServer server + imapClients map[string]*mocks.IMAPClient + imapLastResponses map[string]*mocks.IMAPResponse + imapResponseLocker sync.Locker // SMTP related variables. - smtpAddr string - smtpServer server - smtpClients map[string]*mocks.SMTPClient - smtpLastResponses map[string]*mocks.SMTPResponse + smtpAddr string + smtpServer server + smtpClients map[string]*mocks.SMTPClient + smtpLastResponses map[string]*mocks.SMTPResponse + smtpResponseLocker sync.Locker // Transfer related variables. transferLocalRootForImport string @@ -102,8 +106,10 @@ func New(app string) *TestContext { credStore: newFakeCredStore(), imapClients: make(map[string]*mocks.IMAPClient), imapLastResponses: make(map[string]*mocks.IMAPResponse), + imapResponseLocker: &sync.Mutex{}, smtpClients: make(map[string]*mocks.SMTPClient), smtpLastResponses: make(map[string]*mocks.SMTPResponse), + smtpResponseLocker: &sync.Mutex{}, bddMessageIDsToAPIIDs: make(map[string]string), logger: logrus.StandardLogger(), } diff --git a/test/context/imap.go b/test/context/imap.go index 6218eee4..0cccf10e 100644 --- a/test/context/imap.go +++ b/test/context/imap.go @@ -71,10 +71,16 @@ func (ctx *TestContext) withIMAPServer() { // SetIMAPLastResponse sets the last IMAP response that was received. func (ctx *TestContext) SetIMAPLastResponse(handle string, resp *mocks.IMAPResponse) { + ctx.imapResponseLocker.Lock() + defer ctx.imapResponseLocker.Unlock() + ctx.imapLastResponses[handle] = resp } // GetIMAPLastResponse returns the last IMAP response that was received. func (ctx *TestContext) GetIMAPLastResponse(handle string) *mocks.IMAPResponse { + ctx.imapResponseLocker.Lock() + defer ctx.imapResponseLocker.Unlock() + return ctx.imapLastResponses[handle] } diff --git a/test/context/smtp.go b/test/context/smtp.go index 52090788..cbcada94 100644 --- a/test/context/smtp.go +++ b/test/context/smtp.go @@ -72,10 +72,16 @@ func (ctx *TestContext) withSMTPServer() { // SetSMTPLastResponse sets the last SMTP response that was received. func (ctx *TestContext) SetSMTPLastResponse(handle string, resp *mocks.SMTPResponse) { + ctx.smtpResponseLocker.Lock() + defer ctx.smtpResponseLocker.Unlock() + ctx.smtpLastResponses[handle] = resp } // GetSMTPLastResponse returns the last IMAP response that was received. func (ctx *TestContext) GetSMTPLastResponse(handle string) *mocks.SMTPResponse { + ctx.smtpResponseLocker.Lock() + defer ctx.smtpResponseLocker.Unlock() + return ctx.smtpLastResponses[handle] } diff --git a/unreleased.md b/unreleased.md index 9f3b0c29..b74de3a8 100644 --- a/unreleased.md +++ b/unreleased.md @@ -13,6 +13,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) * GODT-338 GODT-781 GODT-857 GODT-866 Flaky tests. * GODT-773 Replace old dates with birthday of RFC822 to not crash Apple Mail. Original is available under `X-Original-Date` header. * GODT-922 Fix panic during restarting the bridge. +* GODT-945 Fix panic in integration tests caused by concurrent map writes. ### Changed * GODT-858 Bump go-rfc5322 dependency to v0.4.0 to handle some invalid RFC5322 groups.