Skip to content

Commit 648c449

Browse files
committed
Validate correct behaviour of iter.next_item() for small and bigger batches.
1 parent 2a5cff6 commit 648c449

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/test_async.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,15 @@ fn test_transaction_multiplexed_connection() {
226226
.unwrap();
227227
}
228228

229-
#[test]
230-
fn test_async_scanning() {
229+
fn test_async_scanning(batch_size: usize) {
231230
let ctx = TestContext::new();
232231
block_on_all(async move {
233232
ctx.multiplexed_async_connection()
234233
.and_then(|mut con| {
235234
async move {
236235
let mut unseen = std::collections::HashSet::new();
237236

238-
for x in 0..1000 {
237+
for x in 0..batch_size {
239238
redis::cmd("SADD")
240239
.arg("foo")
241240
.arg(x)
@@ -255,7 +254,8 @@ fn test_async_scanning() {
255254
while let Some(x) = iter.next_item().await {
256255
// type inference limitations
257256
let x: usize = x;
258-
unseen.remove(&x);
257+
// if this assertion fails, too many items were returned by the iterator.
258+
assert!(unseen.remove(&x));
259259
}
260260

261261
assert_eq!(unseen.len(), 0);
@@ -268,6 +268,16 @@ fn test_async_scanning() {
268268
.unwrap();
269269
}
270270

271+
#[test]
272+
fn test_async_scanning_big_batch() {
273+
test_async_scanning(1000)
274+
}
275+
276+
#[test]
277+
fn test_async_scanning_small_batch() {
278+
test_async_scanning(2)
279+
}
280+
271281
#[test]
272282
#[cfg(feature = "script")]
273283
fn test_script() {

0 commit comments

Comments
 (0)