Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
test: case for bitswap timeouts and retrying
Browse files Browse the repository at this point in the history
  • Loading branch information
koivunej committed Jan 26, 2021
1 parent a89b0c9 commit ca5228e
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion tests/block_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use cid::{Cid, Codec};
use ipfs::Block;
use multihash::Sha2_256;
use std::time::Duration;
use tokio::time::timeout;
use tokio::time::{sleep, timeout};

mod common;
use common::{spawn_nodes, Topology};
Expand All @@ -29,6 +29,44 @@ async fn two_node_put_get() {
assert_eq!(block.data, found_block.data);
}

// start fetching the cid before storing the block on the source, causing a need for a retry which
// we dont yet have.
#[tokio::test]
async fn two_node_get_put() {
let nodes = spawn_nodes(2, Topology::Line).await;
let block = create_block();

let downloaded = nodes[1].get_block(&block.cid);
tokio::pin!(downloaded);

{
let deadline = sleep(Duration::from_secs(1));
tokio::pin!(deadline);
loop {
tokio::select! {
_ = &mut deadline => {
// FIXME(flaky time assumption): we now assume that the want has been
// propagated, and that our nodes[0] has not found it locally. perhaps if swarm
// could propagate all of the events up, we could notify this via event. alas,
// we dont have such an event, nor can we hope to get this information over
// bitswap 1.0
break;
},
_ = &mut downloaded => unreachable!("cannot complete get_block before block exists"),
}
}
}

nodes[0].put_block(block.clone()).await.unwrap();

let found_block = timeout(Duration::from_secs(10), downloaded)
.await
.expect("get_block did not complete in time")
.unwrap();

assert_eq!(block.data, found_block.data);
}

// check that a long line of nodes still works with get_block
#[tokio::test]
#[ignore]
Expand Down

0 comments on commit ca5228e

Please sign in to comment.