forked from Silverfish/proton-bridge
test: Fix race condition with initialization of messageIDs
Need to make sure the messageIDs slice is created properly before it is used async in a different goroutine.
This commit is contained in:
@ -113,12 +113,13 @@ func TestBridge_User_BadMessage_NoBadEvent(t *testing.T) {
|
|||||||
|
|
||||||
var messageIDs []string
|
var messageIDs []string
|
||||||
|
|
||||||
|
// Create 10 more messages for the user, generating events.
|
||||||
|
withClient(ctx, t, s, "user", password, func(ctx context.Context, c *proton.Client) {
|
||||||
|
messageIDs = createNumMessages(ctx, t, c, addrID, proton.InboxLabel, 10)
|
||||||
|
})
|
||||||
|
|
||||||
// If bridge attempts to sync the new messages, it should get a BadRequest error.
|
// If bridge attempts to sync the new messages, it should get a BadRequest error.
|
||||||
s.AddStatusHook(func(req *http.Request) (int, bool) {
|
s.AddStatusHook(func(req *http.Request) (int, bool) {
|
||||||
if len(messageIDs) < 3 {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.Contains(req.URL.Path, "/mail/v4/messages/"+messageIDs[2]) {
|
if strings.Contains(req.URL.Path, "/mail/v4/messages/"+messageIDs[2]) {
|
||||||
return http.StatusUnprocessableEntity, true
|
return http.StatusUnprocessableEntity, true
|
||||||
}
|
}
|
||||||
@ -126,11 +127,6 @@ func TestBridge_User_BadMessage_NoBadEvent(t *testing.T) {
|
|||||||
return 0, false
|
return 0, false
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create 10 more messages for the user, generating events.
|
|
||||||
withClient(ctx, t, s, "user", password, func(ctx context.Context, c *proton.Client) {
|
|
||||||
messageIDs = createNumMessages(ctx, t, c, addrID, proton.InboxLabel, 10)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Remove messages
|
// Remove messages
|
||||||
withClient(ctx, t, s, "user", password, func(ctx context.Context, c *proton.Client) {
|
withClient(ctx, t, s, "user", password, func(ctx context.Context, c *proton.Client) {
|
||||||
require.NoError(t, c.DeleteMessage(ctx, messageIDs...))
|
require.NoError(t, c.DeleteMessage(ctx, messageIDs...))
|
||||||
|
|||||||
@ -420,9 +420,7 @@ func (user *User) handleMessageEvents(ctx context.Context, messageEvents []proto
|
|||||||
|
|
||||||
switch event.Action {
|
switch event.Action {
|
||||||
case proton.EventCreate:
|
case proton.EventCreate:
|
||||||
updates, err := user.handleCreateMessageEvent(
|
updates, err := user.handleCreateMessageEvent(logging.WithLogrusField(ctx, "action", "create message"), event)
|
||||||
logging.WithLogrusField(ctx, "action", "create message"),
|
|
||||||
event)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if rerr := user.reporter.ReportMessageWithContext("Failed to apply create message event", reporter.Context{
|
if rerr := user.reporter.ReportMessageWithContext("Failed to apply create message event", reporter.Context{
|
||||||
"error": err,
|
"error": err,
|
||||||
|
|||||||
Reference in New Issue
Block a user