Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an integration test for cursor not found #3768

Closed
wants to merge 19 commits into from
Prev Previous commit
Next Next commit
works as expected
  • Loading branch information
b1ron committed Dec 4, 2023
commit fb944540c890bff4ca73e9bcc8c7283a531f08d9
34 changes: 19 additions & 15 deletions integration/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,24 @@ func TestCursor(t *testing.T) {
_, err = collection2.InsertMany(ctx, arr)
require.NoError(t, err)

t.Run("CursorClosedAsExpected", func(t *testing.T) {
cur, err := collection2.Find(ctx, bson.D{}, opts)
require.NoError(t, err)
assert.Equal(t, 1, cur.RemainingBatchLength())

cur.Next(ctx)
cur.Next(ctx)
assert.NotEqual(t, int64(0), cur.ID())

assert.Equal(t, 0, cur.RemainingBatchLength())
cur.Next(ctx) // last getMore
assert.Equal(t, int64(0), cur.ID()) // ID is 0 if the cursor has been closed or exhausted

assert.False(t, cur.TryNext(ctx))
})

t.Run("CursorNotFoundAfterDisconnect", func(t *testing.T) {
t.Skip(t)
cur, err := collection2.Find(ctx, bson.D{}, opts)
require.NoError(t, err)

Expand Down Expand Up @@ -91,22 +108,9 @@ func TestCursor(t *testing.T) {

}()

// err = client2.Disconnect(ctx)
// require.NoError(t, err)

wg.Wait()
})

t.Run("CursorClosedAfterIDZero", func(t *testing.T) {
// test if an additional getMore is needed when the cursor ID is 0
// client2.Connect(ctx)
cur, err := collection2.Find(ctx, bson.D{}, opts)
err = client2.Disconnect(ctx)
require.NoError(t, err)

cur.Next(ctx)
cur.Next(ctx)

assert.False(t, cur.Next(ctx))
assert.Equal(t, int64(0), cur.ID())
wg.Wait()
})
}
Loading