-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Test] Add unit test for validator Router connections #3198
Changes from all commits
f654dae
9c03d9f
2974612
f038b45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ use core::time::Duration; | |
#[tokio::test] | ||
async fn test_connect_without_handshake() { | ||
// Create 2 routers. | ||
let node0 = validator(0, 2).await; | ||
let node0 = validator(0, 2, &[], true).await; | ||
let node1 = client(0, 2).await; | ||
assert_eq!(node0.number_of_connected_peers(), 0); | ||
assert_eq!(node1.number_of_connected_peers(), 0); | ||
|
@@ -78,7 +78,7 @@ async fn test_connect_without_handshake() { | |
#[tokio::test] | ||
async fn test_connect_with_handshake() { | ||
// Create 2 routers. | ||
let node0 = validator(0, 2).await; | ||
let node0 = validator(0, 2, &[], true).await; | ||
let node1 = client(0, 2).await; | ||
assert_eq!(node0.number_of_connected_peers(), 0); | ||
assert_eq!(node1.number_of_connected_peers(), 0); | ||
|
@@ -150,11 +150,64 @@ async fn test_connect_with_handshake() { | |
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_validator_connection() { | ||
// Create first router and start listening. | ||
let node0 = validator(0, 2, &[], false).await; | ||
assert_eq!(node0.number_of_connected_peers(), 0); | ||
node0.enable_handshake().await; | ||
node0.tcp().enable_listener().await.unwrap(); | ||
|
||
// Get the local IP address from the first router. | ||
let addr0 = node0.local_ip(); | ||
|
||
// Create second router, trusting the first router, and start listening. | ||
let node1 = validator(0, 2, &[addr0], false).await; | ||
assert_eq!(node1.number_of_connected_peers(), 0); | ||
node1.enable_handshake().await; | ||
node1.tcp().enable_listener().await.unwrap(); | ||
|
||
{ | ||
// Connect node0 to node1. | ||
node0.connect(node1.local_ip()); | ||
// Sleep briefly. | ||
tokio::time::sleep(Duration::from_millis(200)).await; | ||
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.
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. Will keep it in mind for future tests, for now I'll keep the logic similar to the rest of the tests in the file. 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. IIRC 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. Just tried it. Just awaiting node0's connect is not enough, because node1 might not be connected yet. I suggest we leave refactoring this file for later. |
||
|
||
print_tcp!(node0); | ||
print_tcp!(node1); | ||
|
||
// Check the TCP level - connection was accepted. | ||
assert_eq!(node0.tcp().num_connected(), 1); | ||
assert_eq!(node1.tcp().num_connected(), 1); | ||
|
||
// Check the router level - connection was accepted. | ||
assert_eq!(node0.number_of_connected_peers(), 1); | ||
assert_eq!(node1.number_of_connected_peers(), 1); | ||
|
||
// Disconnect the nodes. | ||
node0.disconnect(node1.local_ip()); | ||
node1.disconnect(node0.local_ip()); | ||
|
||
// Connect node1 to node0. | ||
node1.connect(node0.local_ip()); | ||
// Sleep briefly. | ||
tokio::time::sleep(Duration::from_millis(200)).await; | ||
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. ditto 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. ditto comment above |
||
|
||
// Check the TCP level - connection was not accepted. | ||
assert_eq!(node0.tcp().num_connected(), 0); | ||
assert_eq!(node1.tcp().num_connected(), 0); | ||
|
||
// Check the router level - connection was not accepted. | ||
assert_eq!(node0.number_of_connected_peers(), 0); | ||
assert_eq!(node1.number_of_connected_peers(), 0); | ||
} | ||
} | ||
|
||
#[ignore] | ||
#[tokio::test] | ||
async fn test_connect_simultaneously_with_handshake() { | ||
// Create 2 routers. | ||
let node0 = validator(0, 2).await; | ||
let node0 = validator(0, 2, &[], true).await; | ||
let node1 = client(0, 2).await; | ||
assert_eq!(node0.number_of_connected_peers(), 0); | ||
assert_eq!(node1.number_of_connected_peers(), 0); | ||
|
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.
aren't we racing against the
Heartbeat
(that might causenode1
to attempt to connect tonode0
) here? then again, that direction should fail, so it's probably fineThere 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.
heartbeat is not turned on, only if we call
initialize_routing
.