Skip to content

Commit

Permalink
Add test code
Browse files Browse the repository at this point in the history
  • Loading branch information
kokodak committed Aug 23, 2024
1 parent d30abf3 commit ab3888c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/backend/database/memory/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,9 @@ func (d *DB) FindChangeInfosBetweenServerSeqs(
txn := d.db.Txn(false)
defer txn.Abort()

if from > to {
return nil, nil
}
var infos []*database.ChangeInfo

iterator, err := txn.LowerBound(
Expand Down
4 changes: 4 additions & 0 deletions server/backend/database/memory/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func TestDB(t *testing.T) {
testcases.RunFindChangesBetweenServerSeqsTest(t, db, projectID)
})

t.Run("RunFindChangeInfosBetweenServerSeqsTest test", func(t *testing.T) {
testcases.RunFindChangeInfosBetweenServerSeqsTest(t, db, projectID)
})

t.Run("RunFindClosestSnapshotInfo test", func(t *testing.T) {
testcases.RunFindClosestSnapshotInfoTest(t, db, projectID)
})
Expand Down
4 changes: 4 additions & 0 deletions server/backend/database/mongo/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func TestClient(t *testing.T) {
testcases.RunFindChangesBetweenServerSeqsTest(t, cli, dummyProjectID)
})

t.Run("RunFindChangeInfosBetweenServerSeqsTest test", func(t *testing.T) {
testcases.RunFindChangeInfosBetweenServerSeqsTest(t, cli, dummyProjectID)
})

t.Run("RunFindClosestSnapshotInfo test", func(t *testing.T) {
testcases.RunFindClosestSnapshotInfoTest(t, cli, dummyProjectID)
})
Expand Down
37 changes: 37 additions & 0 deletions server/backend/database/testcases/testcases.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,43 @@ func RunFindChangesBetweenServerSeqsTest(
})
}

// RunFindChangeInfosBetweenServerSeqsTest runs the FindChangeInfosBetweenServerSeqs test for the given db.
func RunFindChangeInfosBetweenServerSeqsTest(
t *testing.T,
db database.Database,
projectID types.ID,
) {
t.Run("continues editing without any interference from other users test", func(t *testing.T) {
ctx := context.Background()

docKey := key.Key(fmt.Sprintf("tests$%s", t.Name()))

clientInfo, _ := db.ActivateClient(ctx, projectID, t.Name())
docInfo, _ := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), docKey, true)
assert.NoError(t, clientInfo.AttachDocument(docInfo.ID, false))
assert.NoError(t, db.UpdateClientInfoAfterPushPull(ctx, clientInfo, docInfo))

updatedClientInfo, err := db.FindClientInfoByRefKey(ctx, clientInfo.RefKey())

Check failure on line 362 in server/backend/database/testcases/testcases.go

View workflow job for this annotation

GitHub Actions / build

ineffectual assignment to err (ineffassign)

// Record the serverSeq value at the time the PushPull request came in.
initialServerSeq := docInfo.ServerSeq

// The serverSeq of the checkpoint that the server has should always be the same as
// the serverSeq of the user's checkpoint that came in as a request, if no other user interfered.
reqPackCheckpointServerSeq := updatedClientInfo.Checkpoint(docInfo.ID).ServerSeq

changeInfos, err := db.FindChangeInfosBetweenServerSeqs(
ctx,
docInfo.RefKey(),
reqPackCheckpointServerSeq+1,
initialServerSeq,
)

assert.NoError(t, err)
assert.Len(t, changeInfos, 0)
})
}

// RunFindClosestSnapshotInfoTest runs the FindClosestSnapshotInfo test for the given db.
func RunFindClosestSnapshotInfoTest(t *testing.T, db database.Database, projectID types.ID) {
t.Run("store and find snapshots test", func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions test/sharding/mongo_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func TestClientWithShardedDB(t *testing.T) {
testcases.RunFindChangesBetweenServerSeqsTest(t, cli, dummyProjectID)
})

t.Run("RunFindChangeInfosBetweenServerSeqsTest test", func(t *testing.T) {
testcases.RunFindChangeInfosBetweenServerSeqsTest(t, cli, dummyProjectID)
})

t.Run("RunFindClosestSnapshotInfo test", func(t *testing.T) {
testcases.RunFindClosestSnapshotInfoTest(t, cli, dummyProjectID)
})
Expand Down

0 comments on commit ab3888c

Please sign in to comment.