-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(GODT-1760): Fix out of order UID panics
Extendend snapshot with `appendMessageFromOtherState` to enable out of order UID insertion. Please check the comments in `TestAppendCanHandleOutOfOrderUIDUpdates` for why this is necessary.
- Loading branch information
1 parent
5e4c79b
commit a7e75bf
Showing
4 changed files
with
126 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package tests | |
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"github.com/ProtonMail/gluon/connector" | ||
"github.com/ProtonMail/gluon/imap" | ||
"os" | ||
|
@@ -261,3 +262,53 @@ func TestAppendConnectorReturnsSameRemoteIDDifferentMBox(t *testing.T) { | |
} | ||
}) | ||
} | ||
|
||
func TestAppendCanHandleOutOfOrderUIDUpdates(t *testing.T) { | ||
// Make sure we are correctly handling the case where we have to clients doing append at the same time. | ||
// Both clients append a message and get assigned UID according to whichever got there first: | ||
// | ||
// * Client A -> Append -> UID 1 | ||
// * Client B -> Append -> UID 2 | ||
// | ||
// All Clients apply their changes to their local state immediately and will receive a deferred updates for the | ||
// same mailbox if other clients make updates. | ||
// In the case of client B, it appends UID2 as the first message and then later receives an update from A with | ||
// an UID lower than the last UID which caused unnecessary panics in the past. | ||
// | ||
runManyToOneTestWithAuth(t, defaultServerOptions(t, withDisableParallelism()), []int{1, 2}, func(c map[int]*testConnection, session *testSession) { | ||
const MessageCount = 20 | ||
|
||
// Select mailbox so that both clients get updates. | ||
c[1].C("A001 SELECT INBOX").OK("A001") | ||
c[2].C("A002 SELECT INBOX").OK("A002") | ||
|
||
appendFN := func(clientIndex int) { | ||
for i := 0; i < MessageCount; i++ { | ||
c[clientIndex+1].doAppend("INBOX", "To: [email protected]\r\n", "\\Seen").expect("OK") | ||
} | ||
} | ||
|
||
wg := sync.WaitGroup{} | ||
wg.Add(2) | ||
|
||
for i := 0; i < 2; i++ { | ||
go func(index int) { | ||
defer wg.Done() | ||
appendFN(index) | ||
}(i) | ||
} | ||
|
||
wg.Wait() | ||
|
||
validateUIDListFn := func(index int) { | ||
c[index].C("F001 FETCH 1:* (UID)") | ||
for i := 1; i <= MessageCount; i++ { | ||
c[index].S(fmt.Sprintf("* %v FETCH (UID %v)", i, i)) | ||
} | ||
c[index].OK("F001") | ||
} | ||
|
||
validateUIDListFn(1) | ||
validateUIDListFn(2) | ||
}) | ||
} |