@@ -2,7 +2,7 @@ use cid::{Cid, Codec};
2
2
use ipfs:: Block ;
3
3
use multihash:: Sha2_256 ;
4
4
use std:: time:: Duration ;
5
- use tokio:: time:: timeout;
5
+ use tokio:: time:: { sleep , timeout} ;
6
6
7
7
mod common;
8
8
use common:: { spawn_nodes, Topology } ;
@@ -29,6 +29,44 @@ async fn two_node_put_get() {
29
29
assert_eq ! ( block. data, found_block. data) ;
30
30
}
31
31
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
+
32
70
// check that a long line of nodes still works with get_block
33
71
#[ tokio:: test]
34
72
#[ ignore]
0 commit comments