Skip to content

Commit

Permalink
test: use random_port in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexD10S committed Dec 3, 2024
1 parent 568f1ce commit 4bc05b1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions crates/pop-cli/tests/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use anyhow::Result;
use assert_cmd::{cargo::cargo_bin, Command};
use pop_common::templates::Template;
use pop_contracts::find_free_port;
use pop_parachains::Parachain;
use std::{fs, path::Path, process::Command as Cmd};
use strum::VariantArray;
Expand Down Expand Up @@ -90,14 +91,17 @@ async fn parachain_lifecycle() -> Result<()> {
// Overwrite the config file to manually set the port to test pop call parachain.
let network_toml_path = temp_parachain_dir.join("network.toml");
fs::create_dir_all(&temp_parachain_dir)?;
let random_port = find_free_port();
let localhost_url = format!("ws://127.0.0.1:{}", random_port);
fs::write(
&network_toml_path,
r#"[relaychain]
format!(
r#"[relaychain]
chain = "paseo-local"
[[relaychain.nodes]]
name = "alice"
rpc_port = 8833
rpc_port = {}
validator = true
[[relaychain.nodes]]
Expand All @@ -111,6 +115,8 @@ default_command = "./target/release/parachain-template-node"
[[parachains.collators]]
name = "collator-01"
"#,
random_port
),
)?;

// pop up parachain -p "./test_parachain"
Expand All @@ -120,8 +126,13 @@ name = "collator-01"
.spawn()
.unwrap();

// If after 20 secs is still running probably execution is ok, or waiting for user response
sleep(Duration::from_secs(20)).await;

assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running");

// pop call parachain --pallet System --extrinsic remark --args "0x11" --url
// ws://127.0.0.1:8833/ --suri //Alice --skip-confirm
// ws://127.0.0.1:8833 --suri //Alice --skip-confirm
Command::cargo_bin("pop")
.unwrap()
.args(&[
Expand All @@ -134,18 +145,14 @@ name = "collator-01"
"--args",
"0x11",
"--url",
"ws://127.0.0.1:8833/",
&localhost_url,
"--suri",
"//Alice",
"--skip-confirm",
])
.assert()
.success();

// If after 20 secs is still running probably execution is ok, or waiting for user response
sleep(Duration::from_secs(20)).await;

assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running");
// Stop the process
Cmd::new("kill").args(["-s", "TERM", &cmd.id().to_string()]).spawn()?;

Expand Down

0 comments on commit 4bc05b1

Please sign in to comment.