Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
rpc/tests: Check all pinned blocks are unpinned on drop
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
  • Loading branch information
lexnv committed Jan 25, 2023
1 parent 6bc2e87 commit 9015061
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion client/rpc-spec-v2/src/chain_head/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ async fn pin_block_references() {
backend.clone(),
Arc::new(TaskExecutor::default()),
CHAIN_GENESIS,
2,
3,
)
.into_rpc();

Expand Down Expand Up @@ -1102,4 +1102,48 @@ async fn pin_block_references() {
// Make sure unpin clears out the reference.
let refs = backend.pin_refs(&hash).unwrap();
assert_eq!(refs, 0);

tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;

// Add another 2 blocks and make sure we drop the subscription with the blocks pinned.
let mut hashes = Vec::new();
for _ in 0..2 {
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
let hash = block.header.hash();
client.import(BlockOrigin::Own, block.clone()).await.unwrap();

// Ensure the imported block is propagated for this subscription.
assert_matches!(
get_next_event::<FollowEvent<String>>(&mut sub).await,
FollowEvent::NewBlock(_)
);
assert_matches!(
get_next_event::<FollowEvent<String>>(&mut sub).await,
FollowEvent::BestBlockChanged(_)
);

hashes.push(hash);
}

tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;

// Make sure the pin was propagated.
for hash in &hashes {
let refs = backend.pin_refs(&hash).unwrap();
assert_eq!(refs, 1);
}

// Drop the subscription and expect the pinned blocks to be released.
drop(sub);
// The `chainHead` detects the subscription was terminated when it tries
// to send another block.
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
client.import(BlockOrigin::Own, block.clone()).await.unwrap();

tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;

for hash in &hashes {
let refs = backend.pin_refs(&hash).unwrap();
assert_eq!(refs, 0);
}
}

0 comments on commit 9015061

Please sign in to comment.