Skip to content
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

fix(test, priory): serially run tests #7

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
41 changes: 41 additions & 0 deletions sigil/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sigil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ tracing-subscriber = { version = "0.3.17", features = [
"env-filter",
] }
toml = "0.8.19"
serial_test = "3.1.1"
4 changes: 3 additions & 1 deletion sigil/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ It is our hope that we have successfully encapsulated this admittedly-convoluted

## Testing

Once built, the project may be tested as usual using the standard `cargo test`. Some integration tests rely on the ability to access a Docker image of the client to test inter-client communications.
Once built, the project may be tested as usual using the standard `cargo test`. Some integration tests rely on the ability to access a Docker image of the client to test inter-client communications.

* If the tests are manually cancelled, make sure to also manually stop any docker containers started by the test.

## Running

Expand Down
46 changes: 26 additions & 20 deletions sigil/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{Context, Result};
use reqwest::Client;
use serde_json::json;
use serial_test::serial;
use std::panic::AssertUnwindSafe;
use std::string::String;
use testcontainers::{
Expand All @@ -13,43 +14,47 @@ mod test_helper;
use test_helper::SigilTestInstance;

#[tokio::test]
#[serial]
async fn test_2_mdns_connections() {
let sigil_a = SigilTestInstance::new("a.toml").await;
let sigil_b = SigilTestInstance::new("b.toml").await;

// TODO: make assertions about all this
let peer_id_a = sigil_a.rpc("my_peer_id", None).await.unwrap();
println!("\npeer a id: {}", peer_id_a);
let sigil_a_peer_id = sigil_a.rpc("my_peer_id", None).await.unwrap();
let sigil_b_peer_id = sigil_b.rpc("my_peer_id", None).await.unwrap();

let connected_peers_a = sigil_a.rpc("connected_peers", None).await.unwrap();
println!("connected peers a: {}", connected_peers_a);

let gossipsub_peers_a = sigil_a.rpc("gossipsub_mesh_peers", None).await.unwrap();
println!("gossipsub mesh peers a: {}", gossipsub_peers_a);
sigil_a
.rpc_with_expected("connected_peers", None, &sigil_b_peer_id)
.await
.unwrap();

let kademlia_routing_table_peers = sigil_a
.rpc("kademlia_routing_table_peers", None)
sigil_a
.rpc_with_expected("gossipsub_mesh_peers", None, &sigil_b_peer_id)
.await
.unwrap();
println!("kademlia routing table peers a: {kademlia_routing_table_peers}\n");

let peer_id_b = sigil_b.rpc("my_peer_id", None).await.unwrap();
println!("peer b id: {}", peer_id_b);
sigil_a
.rpc_with_expected("kademlia_routing_table_peers", None, &sigil_b_peer_id)
.await
.unwrap();

let connected_peers_b = sigil_b.rpc("connected_peers", None).await.unwrap();
println!("connected peers b: {}", connected_peers_b);
sigil_b
.rpc_with_expected("connected_peers", None, &sigil_a_peer_id)
.await
.unwrap();

let gossipsub_peers_b = sigil_b.rpc("gossipsub_mesh_peers", None).await.unwrap();
println!("gossipsub mesh peers b: {}", gossipsub_peers_b);
sigil_b
.rpc_with_expected("gossipsub_mesh_peers", None, &sigil_a_peer_id)
.await
.unwrap();

let kademlia_routing_table_peers = sigil_b
.rpc("kademlia_routing_table_peers", None)
sigil_b
.rpc_with_expected("kademlia_routing_table_peers", None, &sigil_a_peer_id)
.await
.unwrap();
println!("kademlia routing table peers b: {kademlia_routing_table_peers}");
}

#[tokio::test]
#[serial]
async fn test_no_connections_default_config() {
let sigil = SigilTestInstance::new("default.toml").await;

Expand All @@ -70,6 +75,7 @@ async fn test_no_connections_default_config() {
}

#[tokio::test]
#[serial]
async fn test_hello_sigil() {
let sigil = SigilTestInstance::new("default.toml").await;

Expand Down
2 changes: 1 addition & 1 deletion sigil/tests/test_configs/a.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[priory]
secret_key_seed = 1
secret_key_seed = 3
1 change: 1 addition & 0 deletions sigil/tests/test_configs/default.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[priory]
secret_key_seed = 1
20 changes: 19 additions & 1 deletion sigil/tests/test_helper.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use anyhow::{anyhow, Context, Result};
use serde_json::Value;
use testcontainers::{
core::{ContainerAsync, IntoContainerPort, WaitFor},
runners::AsyncRunner,
GenericImage, ImageExt,
};
use tokio::time::Duration;

// TODO: there are a lot of constansts in here. They will either be params or real CONST vars.

Expand All @@ -29,6 +31,9 @@ impl SigilTestInstance {
.await
.expect("Failed to start sigil container");

// give it a chance to make connections or crash
tokio::time::sleep(Duration::from_millis(500)).await;

let host_port = container
.get_host_port_ipv4(port)
.await
Expand Down Expand Up @@ -99,7 +104,20 @@ impl SigilTestInstance {
method, params
))?;

response.text().await.context("Failed to get response body")
let body = response
.text()
.await
.context("Failed to get response body")?;

let json: Value = serde_json::from_str(&body)
.context(format!("parse rpc response from {method} as json"))?;

json["result"]
.as_str()
.context(format!(
"extract result field from json response to {method}"
))
.map(|s| s.into())
}

pub async fn get_container_logs(&self) -> String {
Expand Down