Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pragmaxim committed Jun 11, 2024
1 parent 0b170f6 commit cc86a28
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,18 @@ mod tests {
async fn test_batch_stream_of_blocks() {
let mut queue: VecDeque<char> = ('a'..='z').collect();

let batches: Vec<Vec<BlockOfTxs>> = tokio_stream::iter(1..=4)
let batches: Vec<Vec<BlockOfTxs>> = tokio_stream::iter(1..=7)
.map(|x| BlockOfTxs {
name: queue.pop_front().unwrap(),
txs_count: x,
txs_count: if x >= 4 { 1 } else { x },
})
.min_batch(3, |block: &BlockOfTxs| block.txs_count)
.collect()
.await;

// Verify the batches
assert_eq!(batches.len(), 3);
// collect first two Blocks of Transactions until the total count of transactions is >= 3
assert_eq!(batches.len(), 4);
// collect first Blocks of Transactions until the total count of transactions is >= 3
assert_eq!(
batches[0],
vec![
Expand All @@ -268,11 +268,30 @@ mod tests {
txs_count: 3
}],
);
// collect 3 more blocks with a single transaction
assert_eq!(
batches[2],
vec![
BlockOfTxs {
name: 'd',
txs_count: 1
},
BlockOfTxs {
name: 'e',
txs_count: 1
},
BlockOfTxs {
name: 'f',
txs_count: 1
}
],
);
// and so on
assert_eq!(
batches[3],
vec![BlockOfTxs {
name: 'd',
txs_count: 4
name: 'g',
txs_count: 1
}],
);
}
Expand Down

0 comments on commit cc86a28

Please sign in to comment.