Skip to content

Commit

Permalink
move to async #4
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Jan 6, 2024
1 parent e629c82 commit 23dc25d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
41 changes: 31 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ jobs:
strategy:
matrix:
build:
- linux-stable
- macos-stable
# - linux-stable
# - macos-stable
- windows-stable
include:
- build: linux-stable
os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
rust: stable
- build: macos-stable
os: macos-latest
target: x86_64-apple-darwin
rust: stable
# - build: linux-stable
# os: ubuntu-20.04
# target: x86_64-unknown-linux-gnu
# rust: stable
# - build: macos-stable
# os: macos-latest
# target: x86_64-apple-darwin
# rust: stable
- build: windows-stable
os: windows-latest
target: x86_64-pc-windows-msvc
Expand All @@ -94,8 +94,29 @@ jobs:
if: ${{ ! startsWith(matrix.build, 'windows') }}
run: sudo -E env "PATH=$PATH" cargo test --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture

fmt:
runs-on: ubuntu-22.04
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test-case = "3.3.1"
tun = { version = "0.6.1", features = [ "async" ] }
serde_yaml = "0.9.30"
tokio = { version = "1.35.1", features = [ "full" ] }
tokio-util = "0.7.10"
tokio-util = { version = "0.7.10" }

[features]
# Enable simulation integration tests
Expand Down
21 changes: 14 additions & 7 deletions tests/sim/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,24 @@ async fn run_simulation(simulation: Simulation) -> anyhow::Result<()> {
let handle = tokio::spawn(network::run(tun, sim.clone(), token.clone()));

// spawn the tracer as a blocking task and wait for it to finish or fail.
tokio::task::spawn_blocking(move || tracer::Tracer::new(sim).trace()).await??;
let handle2 = tokio::task::spawn_blocking(move || tracer::Tracer::new(sim, token).trace());

println!("tracing complete");
// println!("tracing complete");

// notify the network simulator to stop.
token.cancel();

println!("cancel signalled");
// // notify the network simulator to stop.
// token.cancel();
//
// println!("cancel signalled");

// join the network simulator task once it has shutdown.
handle.await??;
// handle.await??;

// handle.await??;

let (a, b) = tokio::try_join!(handle, handle2)?;

a?;
b?;

println!("joined sim");

Expand Down
7 changes: 5 additions & 2 deletions tests/sim/tracer.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
use crate::simulation::{Response, Simulation, SingleHost};
use std::num::NonZeroUsize;
use std::sync::Arc;
use tokio_util::sync::CancellationToken;
use trippy::tracing::{
Builder, CompletionReason, MaxRounds, ProbeStatus, TimeToLive, TraceId, TracerRound,
};

pub struct Tracer {
sim: Arc<Simulation>,
pub token: CancellationToken,
}

impl Tracer {
pub fn new(sim: Arc<Simulation>) -> Self {
Self { sim }
pub fn new(sim: Arc<Simulation>, token: CancellationToken) -> Self {
Self { sim, token }
}

pub fn trace(&self) -> anyhow::Result<()> {
Builder::new(self.sim.target, |round| self.validate_round(round))
.trace_identifier(TraceId(self.sim.icmp_identifier))
.max_rounds(MaxRounds(NonZeroUsize::MIN))
.start()?;
self.token.cancel();
Ok(())
}

Expand Down

0 comments on commit 23dc25d

Please sign in to comment.