Skip to content

RUST-1757 Fix final cursor batch handling #951

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

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/cursor/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ where
let result = self.provider.execute(spec, client, pin).await;
self.handle_get_more_result(result)?;

if self.is_exhausted() {
Ok(AdvanceResult::Exhausted)
} else {
match self.state_mut().buffer.advance() {
true => Ok(AdvanceResult::Advanced),
false => Ok(AdvanceResult::Waiting),
match self.state_mut().buffer.advance() {
true => Ok(AdvanceResult::Advanced),
false => {
if self.is_exhausted() {
Ok(AdvanceResult::Exhausted)
} else {
Ok(AdvanceResult::Waiting)
}
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/test/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,34 @@ async fn session_cursor_with_type() {

let _ = cursor_with_type.next(&mut session).await.unwrap().unwrap();
}

#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
async fn cursor_final_batch() {
let client = TestClient::new().await;
let coll = client
.create_fresh_collection("test_cursor_final_batch", "test", None)
.await;
coll.insert_many(
vec![
doc! { "foo": 1 },
doc! { "foo": 2 },
doc! { "foo": 3 },
doc! { "foo": 4 },
doc! { "foo": 5 },
],
None,
)
.await
.unwrap();

let mut cursor = coll
.find(None, FindOptions::builder().batch_size(3).build())
.await
.unwrap();
let mut found = 0;
while cursor.advance().await.unwrap() {
found += 1;
}
assert_eq!(found, 5);
}