forked from Silverfish/proton-bridge
test: fix panic on concurrent map write
This commit is contained in:
@ -19,6 +19,8 @@
|
|||||||
package context
|
package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/ProtonMail/proton-bridge/internal/bridge"
|
"github.com/ProtonMail/proton-bridge/internal/bridge"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/importexport"
|
"github.com/ProtonMail/proton-bridge/internal/importexport"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/transfer"
|
"github.com/ProtonMail/proton-bridge/internal/transfer"
|
||||||
@ -56,16 +58,18 @@ type TestContext struct {
|
|||||||
lastError error
|
lastError error
|
||||||
|
|
||||||
// IMAP related variables.
|
// IMAP related variables.
|
||||||
imapAddr string
|
imapAddr string
|
||||||
imapServer server
|
imapServer server
|
||||||
imapClients map[string]*mocks.IMAPClient
|
imapClients map[string]*mocks.IMAPClient
|
||||||
imapLastResponses map[string]*mocks.IMAPResponse
|
imapLastResponses map[string]*mocks.IMAPResponse
|
||||||
|
imapResponseLocker sync.Locker
|
||||||
|
|
||||||
// SMTP related variables.
|
// SMTP related variables.
|
||||||
smtpAddr string
|
smtpAddr string
|
||||||
smtpServer server
|
smtpServer server
|
||||||
smtpClients map[string]*mocks.SMTPClient
|
smtpClients map[string]*mocks.SMTPClient
|
||||||
smtpLastResponses map[string]*mocks.SMTPResponse
|
smtpLastResponses map[string]*mocks.SMTPResponse
|
||||||
|
smtpResponseLocker sync.Locker
|
||||||
|
|
||||||
// Transfer related variables.
|
// Transfer related variables.
|
||||||
transferLocalRootForImport string
|
transferLocalRootForImport string
|
||||||
@ -102,8 +106,10 @@ func New(app string) *TestContext {
|
|||||||
credStore: newFakeCredStore(),
|
credStore: newFakeCredStore(),
|
||||||
imapClients: make(map[string]*mocks.IMAPClient),
|
imapClients: make(map[string]*mocks.IMAPClient),
|
||||||
imapLastResponses: make(map[string]*mocks.IMAPResponse),
|
imapLastResponses: make(map[string]*mocks.IMAPResponse),
|
||||||
|
imapResponseLocker: &sync.Mutex{},
|
||||||
smtpClients: make(map[string]*mocks.SMTPClient),
|
smtpClients: make(map[string]*mocks.SMTPClient),
|
||||||
smtpLastResponses: make(map[string]*mocks.SMTPResponse),
|
smtpLastResponses: make(map[string]*mocks.SMTPResponse),
|
||||||
|
smtpResponseLocker: &sync.Mutex{},
|
||||||
bddMessageIDsToAPIIDs: make(map[string]string),
|
bddMessageIDsToAPIIDs: make(map[string]string),
|
||||||
logger: logrus.StandardLogger(),
|
logger: logrus.StandardLogger(),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,10 +71,16 @@ func (ctx *TestContext) withIMAPServer() {
|
|||||||
|
|
||||||
// SetIMAPLastResponse sets the last IMAP response that was received.
|
// SetIMAPLastResponse sets the last IMAP response that was received.
|
||||||
func (ctx *TestContext) SetIMAPLastResponse(handle string, resp *mocks.IMAPResponse) {
|
func (ctx *TestContext) SetIMAPLastResponse(handle string, resp *mocks.IMAPResponse) {
|
||||||
|
ctx.imapResponseLocker.Lock()
|
||||||
|
defer ctx.imapResponseLocker.Unlock()
|
||||||
|
|
||||||
ctx.imapLastResponses[handle] = resp
|
ctx.imapLastResponses[handle] = resp
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIMAPLastResponse returns the last IMAP response that was received.
|
// GetIMAPLastResponse returns the last IMAP response that was received.
|
||||||
func (ctx *TestContext) GetIMAPLastResponse(handle string) *mocks.IMAPResponse {
|
func (ctx *TestContext) GetIMAPLastResponse(handle string) *mocks.IMAPResponse {
|
||||||
|
ctx.imapResponseLocker.Lock()
|
||||||
|
defer ctx.imapResponseLocker.Unlock()
|
||||||
|
|
||||||
return ctx.imapLastResponses[handle]
|
return ctx.imapLastResponses[handle]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,10 +72,16 @@ func (ctx *TestContext) withSMTPServer() {
|
|||||||
|
|
||||||
// SetSMTPLastResponse sets the last SMTP response that was received.
|
// SetSMTPLastResponse sets the last SMTP response that was received.
|
||||||
func (ctx *TestContext) SetSMTPLastResponse(handle string, resp *mocks.SMTPResponse) {
|
func (ctx *TestContext) SetSMTPLastResponse(handle string, resp *mocks.SMTPResponse) {
|
||||||
|
ctx.smtpResponseLocker.Lock()
|
||||||
|
defer ctx.smtpResponseLocker.Unlock()
|
||||||
|
|
||||||
ctx.smtpLastResponses[handle] = resp
|
ctx.smtpLastResponses[handle] = resp
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSMTPLastResponse returns the last IMAP response that was received.
|
// GetSMTPLastResponse returns the last IMAP response that was received.
|
||||||
func (ctx *TestContext) GetSMTPLastResponse(handle string) *mocks.SMTPResponse {
|
func (ctx *TestContext) GetSMTPLastResponse(handle string) *mocks.SMTPResponse {
|
||||||
|
ctx.smtpResponseLocker.Lock()
|
||||||
|
defer ctx.smtpResponseLocker.Unlock()
|
||||||
|
|
||||||
return ctx.smtpLastResponses[handle]
|
return ctx.smtpLastResponses[handle]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
|||||||
* GODT-338 GODT-781 GODT-857 GODT-866 Flaky tests.
|
* 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-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-922 Fix panic during restarting the bridge.
|
||||||
|
* GODT-945 Fix panic in integration tests caused by concurrent map writes.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* GODT-858 Bump go-rfc5322 dependency to v0.4.0 to handle some invalid RFC5322 groups.
|
* GODT-858 Bump go-rfc5322 dependency to v0.4.0 to handle some invalid RFC5322 groups.
|
||||||
|
|||||||
Reference in New Issue
Block a user