@@ -2,7 +2,7 @@ use cid::{Cid, Codec};
22use ipfs:: Block ;
33use multihash:: Sha2_256 ;
44use std:: time:: Duration ;
5- use tokio:: time:: timeout;
5+ use tokio:: time:: { sleep , timeout} ;
66
77mod common;
88use common:: { spawn_nodes, Topology } ;
@@ -29,6 +29,44 @@ async fn two_node_put_get() {
2929 assert_eq ! ( block. data, found_block. data) ;
3030}
3131
32+ // start fetching the cid before storing the block on the source, causing a need for a retry which
33+ // we dont yet have.
34+ #[ tokio:: test]
35+ async fn two_node_get_put ( ) {
36+ let nodes = spawn_nodes ( 2 , Topology :: Line ) . await ;
37+ let block = create_block ( ) ;
38+
39+ let downloaded = nodes[ 1 ] . get_block ( & block. cid ) ;
40+ tokio:: pin!( downloaded) ;
41+
42+ {
43+ let deadline = sleep ( Duration :: from_secs ( 1 ) ) ;
44+ tokio:: pin!( deadline) ;
45+ loop {
46+ tokio:: select! {
47+ _ = & mut deadline => {
48+ // FIXME(flaky time assumption): we now assume that the want has been
49+ // propagated, and that our nodes[0] has not found it locally. perhaps if swarm
50+ // could propagate all of the events up, we could notify this via event. alas,
51+ // we dont have such an event, nor can we hope to get this information over
52+ // bitswap 1.0
53+ break ;
54+ } ,
55+ _ = & mut downloaded => unreachable!( "cannot complete get_block before block exists" ) ,
56+ }
57+ }
58+ }
59+
60+ nodes[ 0 ] . put_block ( block. clone ( ) ) . await . unwrap ( ) ;
61+
62+ let found_block = timeout ( Duration :: from_secs ( 10 ) , downloaded)
63+ . await
64+ . expect ( "get_block did not complete in time" )
65+ . unwrap ( ) ;
66+
67+ assert_eq ! ( block. data, found_block. data) ;
68+ }
69+
3270// check that a long line of nodes still works with get_block
3371#[ tokio:: test]
3472#[ ignore]
0 commit comments