Skip to content

Commit

Permalink
Add assertion of Change and clientInfo.Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kokodak committed Sep 7, 2024
1 parent 402a51c commit 84d2ce0
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions server/packs/packs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,17 @@ func TestPacks(t *testing.T) {
}, true)
assert.ErrorIs(t, err, packs.ErrCheckpointTest)

// 2-2. docInfo.ServerSeq increases from 1 to 2
// 2-2. pushed change is stored in the database
changes, err := packs.FindChanges(ctx, testBackend, docInfo, 2, 2)
assert.NoError(t, err)
assert.Len(t, changes, 1)

// 2-3. docInfo.ServerSeq increases from 1 to 2
docInfo, err = documents.FindDocInfoByRefKey(ctx, testBackend, docRefKey)
assert.NoError(t, err)
assert.Equal(t, int64(2), docInfo.ServerSeq)

// 2-3. clientInfo.Checkpoint has not been updated
// 2-4. clientInfo.Checkpoint has not been updated
clientInfo, err = clients.FindActiveClientInfo(ctx, testBackend.DB, types.ClientRefKey{
ProjectID: project.ID,
ClientID: types.IDFromActorID(actorID),
Expand All @@ -224,9 +229,23 @@ func TestPacks(t *testing.T) {
}, false)
assert.NoError(t, err)

// 3-2. The server should detect the duplication and not update docInfo.ServerSeq
// 3-2. duplicated change is not stored in the database
changes, err = packs.FindChanges(ctx, testBackend, docInfo, 3, 3)
assert.NoError(t, err)
assert.Len(t, changes, 0)

// 3-3. The server should detect the duplication and not update docInfo.ServerSeq
docInfo, err = documents.FindDocInfoByRefKey(ctx, testBackend, docRefKey)
assert.NoError(t, err)
assert.Equal(t, int64(2), docInfo.ServerSeq)

// 3-4. clientInfo.Checkpoint has been updated properly
clientInfo, err = clients.FindActiveClientInfo(ctx, testBackend.DB, types.ClientRefKey{
ProjectID: project.ID,
ClientID: types.IDFromActorID(actorID),
})
assert.NoError(t, err)
assert.Equal(t, int64(2), clientInfo.Checkpoint(docID).ServerSeq)
assert.Equal(t, uint32(2), clientInfo.Checkpoint(docID).ClientSeq)
})
}

0 comments on commit 84d2ce0

Please sign in to comment.