Skip to content

Commit

Permalink
chore(rust): used portpicker crate to avoid port clash in ockam examples
Browse files Browse the repository at this point in the history
  • Loading branch information
PsychoPunkSage committed Jul 16, 2024
1 parent 5290da6 commit fc60a2e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions 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 examples/rust/tcp_inlet_and_outlet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rust-version = "1.56.0"

[dependencies]
ockam = { path = "../../../implementations/rust/ockam/ockam" }
portpicker = "0.1.1"

[dev-dependencies]
example_test_helper = { path = "../../../tools/docs/example_test_helper" }
15 changes: 7 additions & 8 deletions examples/rust/tcp_inlet_and_outlet/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use example_test_helper::{CmdBuilder, Error};
use ockam::compat::rand;
use ockam::compat::rand::Rng;
use portpicker::pick_unused_port;

#[test]
fn run_01_inlet_outlet_one_process() -> Result<(), Error> {
let port = rand::thread_rng().gen_range(10000..65535);
let port = pick_unused_port().expect("No free ports available");
// Spawn example, wait for it to start up
let runner = CmdBuilder::new(&format!(
"cargo run --example 01-inlet-outlet 127.0.0.1:{port} ockam.io:80"
Expand All @@ -24,8 +23,8 @@ fn run_01_inlet_outlet_one_process() -> Result<(), Error> {

#[test]
fn run_02_inlet_outlet_separate_processes() -> Result<(), Error> {
let routing_port = rand::thread_rng().gen_range(10000..65535);
let inlet_port = rand::thread_rng().gen_range(10000..65535);
let routing_port = pick_unused_port().expect("No free ports available");
let inlet_port = pick_unused_port().expect("No free ports available");
// Spawn outlet, wait for it to start up
let outlet = CmdBuilder::new(&format!("cargo run --example 02-outlet ockam.io:80 {routing_port}")).spawn()?;
outlet.match_stdout(r"(?i)Waiting for incoming TCP connection")?;
Expand All @@ -52,8 +51,8 @@ fn run_02_inlet_outlet_separate_processes() -> Result<(), Error> {
#[test]
#[ignore]
fn run_03_inlet_outlet_separate_processes_secure_channel() -> Result<(), Error> {
let routing_port = rand::thread_rng().gen_range(10000..65535);
let inlet_port = rand::thread_rng().gen_range(10000..65535);
let routing_port = pick_unused_port().expect("No free ports available");
let inlet_port = pick_unused_port().expect("No free ports available");
// Spawn outlet, wait for it to start up
let outlet = CmdBuilder::new(&format!("cargo run --example 03-outlet ockam.io:80 {routing_port}")).spawn()?;
outlet.match_stdout(r"(?i)Waiting for incoming TCP connection")?;
Expand All @@ -80,7 +79,7 @@ fn run_03_inlet_outlet_separate_processes_secure_channel() -> Result<(), Error>
#[test]
#[ignore]
fn run_04_inlet_outlet_seperate_processes_secure_channel_via_ockam_hub() -> Result<(), Error> {
let port = rand::thread_rng().gen_range(10000..65535);
let port = pick_unused_port().expect("No free ports available");
// Spawn outlet, wait for it to start up, grab dynamic forwarding address
let outlet = CmdBuilder::new("cargo run --example 04-outlet ockam.io:80").spawn()?;
outlet.match_stdout(r"(?i)RemoteRelay was created on the node")?;
Expand Down

0 comments on commit fc60a2e

Please sign in to comment.