This repository has been archived by the owner on Oct 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 165
Add connect integration test #108
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cd7a416
add: test case for connecting two nodes
307a724
fix: poll swarm first, use SwarmEvents
90bf986
wip: use println instead of log in test
71df1d9
fix: wakeup when adding the dial action on swarm
4829f01
refactor: minor cleanup in tests and swarm
512c34a
chore: cargo fmt
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use async_std::task; | ||
|
||
/// Make sure two instances of ipfs can be connected. | ||
#[test] | ||
fn connect_two_nodes() { | ||
// env_logger::init(); | ||
|
||
// make sure the connection will only happen through explicit connect | ||
let mdns = false; | ||
|
||
let (tx, rx) = futures::channel::oneshot::channel(); | ||
|
||
let node_a = task::spawn(async move { | ||
let opts = ipfs::IpfsOptions::inmemory_with_generated_keys(mdns); | ||
let (ipfs, fut) = ipfs::UninitializedIpfs::new(opts) | ||
.await | ||
.start() | ||
.await | ||
.unwrap(); | ||
|
||
let jh = task::spawn(fut); | ||
|
||
let (pk, addrs) = ipfs | ||
.identity() | ||
.await | ||
.expect("failed to read identity() on node_a"); | ||
assert!(!addrs.is_empty()); | ||
tx.send((pk, addrs, ipfs, jh)).unwrap(); | ||
}); | ||
|
||
task::block_on(async move { | ||
let (other_pk, other_addrs, other_ipfs, other_jh) = rx.await.unwrap(); | ||
|
||
println!("got back from the other node: {:?}", other_addrs); | ||
|
||
let opts = ipfs::IpfsOptions::inmemory_with_generated_keys(mdns); | ||
let (ipfs, fut) = ipfs::UninitializedIpfs::new(opts) | ||
.await | ||
.start() | ||
.await | ||
.unwrap(); | ||
let jh = task::spawn(fut); | ||
|
||
let _other_peerid = other_pk.into_peer_id(); | ||
|
||
let mut connected = None; | ||
|
||
for addr in other_addrs { | ||
println!("trying {}", addr); | ||
match ipfs.connect(addr.clone()).await { | ||
Ok(_) => { | ||
connected = Some(addr); | ||
break; | ||
} | ||
Err(e) => { | ||
println!("Failed connecting to {}: {}", addr, e); | ||
} | ||
} | ||
Comment on lines
+50
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My initial thinking for the |
||
} | ||
|
||
let connected = connected.expect("Failed to connect to anything"); | ||
println!("connected to {}", connected); | ||
|
||
other_ipfs.exit_daemon().await; | ||
other_jh.await; | ||
node_a.await; | ||
|
||
ipfs.exit_daemon().await; | ||
jh.await; | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no harm in keeping this because it's easy to put
dbg!(inner)
on line 436 here.