test: fix panic on concurrent map write

This commit is contained in:
James Houlahan
2020-12-29 07:39:00 +01:00
parent 7b112fc448
commit 36a6f1ed4b
4 changed files with 27 additions and 8 deletions

View File

@ -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(),
}

View File

@ -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]
}

View File

@ -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]
}

View File

@ -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.