From 6ffe521421d645d507618f8befc4da6f3c0d0374 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 1 Jun 2023 14:42:49 -0700 Subject: [PATCH] ci: fix spurious CI failure PR #5720 introduced runtime self-tuning. It included a test that attempts to verify self-tuning logic. The test is heavily reliant on timing details. This patch attempts to make the test a bit more reliable by not assuming tuning will converge within a set amount of time. --- .github/workflows/ci.yml | 2 +- tokio/tests/rt_threaded.rs | 25 +++++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7aa75b7855d..f8fd34ce487 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -294,7 +294,7 @@ jobs: toolchain: ${{ env.rust_nightly }} - uses: Swatinem/rust-cache@v2 - name: asan - run: cargo test --workspace --all-features --target x86_64-unknown-linux-gnu --tests -- --test-threads 1 + run: cargo test --workspace --all-features --target x86_64-unknown-linux-gnu --tests -- --test-threads 1 --nocapture env: RUSTFLAGS: -Z sanitizer=address # Ignore `trybuild` errors as they are irrelevant and flaky on nightly diff --git a/tokio/tests/rt_threaded.rs b/tokio/tests/rt_threaded.rs index 85ecdf4271d..fcfec74a32a 100644 --- a/tokio/tests/rt_threaded.rs +++ b/tokio/tests/rt_threaded.rs @@ -627,7 +627,6 @@ fn test_tuning() { } // Now, hammer the injection queue until the interval drops. - let mut i = 0; let mut n = 0; loop { let curr = interval.load(Relaxed); @@ -645,18 +644,16 @@ fn test_tuning() { break; } - let counter = counter.clone(); - let interval = interval.clone(); + if Arc::strong_count(&interval) < 5_000 { + let counter = counter.clone(); + let interval = interval.clone(); - if i <= 5_000 { - i += 1; rt.spawn(async move { let prev = counter.swap(0, Relaxed); interval.store(prev, Relaxed); }); + std::thread::yield_now(); - } else { - std::thread::sleep(Duration::from_micros(500)); } } @@ -682,7 +679,6 @@ fn test_tuning() { } // Now, hammer the injection queue until the interval reaches the expected range. - let mut i = 0; let mut n = 0; loop { let curr = interval.load(Relaxed); @@ -697,20 +693,17 @@ fn test_tuning() { break; } - let counter = counter.clone(); - let interval = interval.clone(); + if Arc::strong_count(&interval) <= 5_000 { + let counter = counter.clone(); + let interval = interval.clone(); - if i <= 5_000 { - i += 1; rt.spawn(async move { let prev = counter.swap(0, Relaxed); interval.store(prev, Relaxed); }); - - std::thread::yield_now(); - } else { - std::thread::sleep(Duration::from_micros(500)); } + + std::thread::yield_now(); } flag.store(false, Relaxed);