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

test: case for bitswap timeouts and retrying #452

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
16 changes: 15 additions & 1 deletion src/p2p/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,21 @@ impl<Types: IpfsTypes> NetworkBehaviourEventProcess<PingEvent> for Behaviour<Typ

impl<Types: IpfsTypes> NetworkBehaviourEventProcess<IdentifyEvent> for Behaviour<Types> {
fn inject_event(&mut self, event: IdentifyEvent) {
trace!("identify: {:?}", event);
match event {
IdentifyEvent::Received {
peer_id,
observed_addr,
..
} => {
trace!("identify from {} at {}", peer_id, observed_addr);
}
IdentifyEvent::Sent { peer_id } => {
trace!("identify info sent to {}", peer_id);
}
IdentifyEvent::Error { peer_id, error } => {
trace!("identify error with {}: {}", peer_id, error);
}
}
}
}

Expand Down
41 changes: 40 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,10 +29,49 @@ 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]
async fn long_get_block() {
tracing_subscriber::fmt::init();
// this number could be higher, but it starts hanging above ~24
const N: usize = 10;
let nodes = spawn_nodes(N, Topology::Line).await;
Expand Down