From 2c3e503258dd444f77a3eb6f722cab8c40ed473b Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Sun, 27 Sep 2026 14:09:48 -0700 Subject: [PATCH] test: Improve tracking of slow tests (#10429) Co-authored-by: Connor Fitzgerald --- .config/nextest.toml | 16 +++++++- .../actions/sample-host-metrics/action.yml | 20 ++++++++++ .../actions/sample-host-metrics/sample.ps1 | 37 +++++++++++++++++++ .github/workflows/ci.yml | 22 +++++++++++ Cargo.lock | 1 + Cargo.toml | 4 +- benches/Cargo.toml | 1 + benches/src/lib.rs | 5 +++ examples/features/src/framework.rs | 3 ++ player/tests/player/main.rs | 3 +- tests/src/init.rs | 6 ++- tests/src/lib.rs | 2 +- tests/tests/wgpu-validation/api/instance.rs | 2 +- xtask/src/test.rs | 7 ++++ 14 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 .github/actions/sample-host-metrics/action.yml create mode 100644 .github/actions/sample-host-metrics/sample.ps1 diff --git a/.config/nextest.toml b/.config/nextest.toml index cb871a800..ee500c143 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -1,11 +1,23 @@ # None of our tests should take longer than 45s, and if they've gone 2x that, # terminate them to prevent infinite run-on. +# +# The period is 15s rather than 45s only so that the log gets a liveness +# heartbeat every 15s; nextest prints a `SLOW` line once per period, and CI +# hosts that stall are hard to distinguish from slow tests without one. +# See . [profile.default] default-filter = "!test(~oom_test)" -slow-timeout = { period = "45s", terminate-after = 2 } +slow-timeout = { period = "15s", terminate-after = 6 } fail-fast = false retries = 0 +# Per-test start times and durations, kept as a CI artifact so that +# intermittent timeouts can be analyzed after the run logs expire (#9248). +[profile.default.junit] +path = "junit.xml" +store-success-output = false +store-failure-output = false + # Use two threads for tests with "2 threads" in their name [[profile.default.overrides]] filter = 'test(~2_threads) | test(~2 threads)' @@ -50,7 +62,7 @@ filter = 'test(clear_texture) | test(clear_buffer_range_respected) | test(compil [profile.wasm] default-filter = "test([wasm])" -slow-timeout = { period = "45s", terminate-after = 2 } +slow-timeout = { period = "15s", terminate-after = 6 } fail-fast = false retries = 0 diff --git a/.github/actions/sample-host-metrics/action.yml b/.github/actions/sample-host-metrics/action.yml new file mode 100644 index 000000000..21039e005 --- /dev/null +++ b/.github/actions/sample-host-metrics/action.yml @@ -0,0 +1,20 @@ +name: "Sample host metrics" +description: "Start a background sampler that records host performance counters to a CSV." +inputs: + output: + description: "Path of the CSV file to write." + required: true +runs: + using: "composite" + steps: + - shell: pwsh + env: + INPUTS_OUTPUT: ${{ inputs.output }} + run: | + Start-Process pwsh -WindowStyle Hidden -ArgumentList @( + "-NoProfile" + "-File" + "${{ github.action_path }}/sample.ps1" + "-Output" + $env:INPUTS_OUTPUT + ) diff --git a/.github/actions/sample-host-metrics/sample.ps1 b/.github/actions/sample-host-metrics/sample.ps1 new file mode 100644 index 000000000..e86f0a82b --- /dev/null +++ b/.github/actions/sample-host-metrics/sample.ps1 @@ -0,0 +1,37 @@ +# Appends one line of host performance counters to a CSV every few seconds +# until the sample budget runs out or the job ends and the runner kills us. +# +# Windows CI intermittently stops making progress for a minute or more at a +# time, which kills whichever tests happen to be running. These samples let a +# timeout be correlated with CPU, memory or disk pressure on the host. +# https://github.com/gfx-rs/wgpu/issues/9248 +param( + [Parameter(Mandatory = $true)] [string] $Output, + [int] $IntervalSeconds = 5, + [int] $Samples = 400 +) + +$ErrorActionPreference = "Continue" + +$counters = @( + "\Processor(_Total)\% Processor Time" + "\Memory\Available MBytes" + "\Memory\Pages/sec" + "\PhysicalDisk(_Total)\Current Disk Queue Length" + "\System\Processes" +) + +Set-Content -Path $Output -Encoding ascii ` + -Value "time,cpu_pct,avail_mb,pages_per_sec,disk_queue,processes" + +for ($i = 0; $i -lt $Samples; $i++) { + $now = (Get-Date).ToUniversalTime().ToString("o") + try { + $values = (Get-Counter -Counter $counters -ErrorAction Stop).CounterSamples | + ForEach-Object { [math]::Round($_.CookedValue, 1) } + Add-Content -Path $Output -Value "$now,$($values -join ',')" + } catch { + Add-Content -Path $Output -Value "$now,,,,," + } + Start-Sleep -Seconds $IntervalSeconds +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd5ac737a..f8149958a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -746,6 +746,16 @@ jobs: # Delete snapshots so we can ensure there aren't any excess output files. rm -r naga/tests/out + # Windows CI intermittently stops making progress for a minute or more at + # a time, which kills whichever tests happen to be running. Sample the + # host counters so that a timeout can be correlated with CPU, memory or + # disk pressure. https://github.com/gfx-rs/wgpu/issues/9248 + - name: (Windows) Start host metrics sampler + if: matrix.os == 'windows-2022' + uses: $/.github/actions/sample-host-metrics + with: + output: host-metrics.csv + - name: Run tests shell: bash run: | @@ -766,6 +776,18 @@ jobs: **/*-actual.png **/*-difference.png + # Per-test timings and the host counter samples outlive the run logs, + # which is what we need to chase intermittent timeouts (#9248). + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + name: Upload test timings + if: always() # We want timings even if the tests fail. + with: + name: test-timings-${{ matrix.os }} + path: | + **/nextest/*/junit.xml + host-metrics.csv + if-no-files-found: warn + # Print GPU configuration so we can see what features were available during the test. - name: Print GPU configurations if: always() # We want this information even if the tests fail. diff --git a/Cargo.lock b/Cargo.lock index afab820cc..c122d9fe2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4816,6 +4816,7 @@ dependencies = [ "anyhow", "bincode 2.0.1", "bytemuck", + "env_logger", "naga", "naga-test", "nanorand", diff --git a/Cargo.toml b/Cargo.toml index 059c549c8..0f4c8adad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -135,7 +135,9 @@ codespan-reporting = { version = "0.13", default-features = false } diff = "0.1" document-features = "0.2.10" encase = "0.13" -env_logger = { version = "0.11", default-features = false } +env_logger = { version = "0.11", default-features = false, features = [ + "humantime", +] } exhaust = "0.2" fern = "0.7" flume = "0.12" diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 7ef5e9d21..27735c5ee 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -26,6 +26,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [ anyhow.workspace = true bincode = { workspace = true, features = ["serde"] } bytemuck.workspace = true +env_logger.workspace = true naga = { workspace = true, features = [ "deserialize", "serialize", diff --git a/benches/src/lib.rs b/benches/src/lib.rs index 9452037f6..a34b21e7c 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -115,6 +115,11 @@ Other: "; pub fn main(benchmarks: Vec) { + // The benchmarks run as tests in CI, where they occasionally time out with + // no output at all to say where the time went. See + // . + let _ = env_logger::builder().format_timestamp_millis().try_init(); + let mut args = Arguments::from_env(); let help = args.contains(["-h", "--help"]); diff --git a/examples/features/src/framework.rs b/examples/features/src/framework.rs index a181f8a0d..7e16b189d 100644 --- a/examples/features/src/framework.rs +++ b/examples/features/src/framework.rs @@ -76,6 +76,9 @@ fn init_logger() { // of these default filters. env_logger::builder() .filter_level(log::LevelFilter::Info) + // Millisecond timestamps; see + // . + .format_timestamp_millis() .parse_default_env() .init(); } diff --git a/player/tests/player/main.rs b/player/tests/player/main.rs index 38a200409..01feac469 100644 --- a/player/tests/player/main.rs +++ b/player/tests/player/main.rs @@ -212,7 +212,8 @@ impl Corpus { #[cfg_attr(miri, ignore)] #[test] fn test_api() { - env_logger::init(); + // Millisecond timestamps; see . + env_logger::builder().format_timestamp_millis().init(); Corpus::run_from(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/player/data/all.ron")) } diff --git a/tests/src/init.rs b/tests/src/init.rs index 01b2bebfd..605d796bf 100644 --- a/tests/src/init.rs +++ b/tests/src/init.rs @@ -16,9 +16,13 @@ fn default_device_lost_callback(reason: wgpu::DeviceLostReason, message: String) /// Initialize the logger for the test runner. pub fn init_logger() { + // Millisecond timestamps, because second resolution is not enough to tell + // where the time goes when CI stalls. See + // . + // // We don't actually care if it fails #[cfg(not(target_arch = "wasm32"))] - let _ = env_logger::try_init(); + let _ = env_logger::builder().format_timestamp_millis().try_init(); #[cfg(target_arch = "wasm32")] let _ = console_log::init_with_level(log::Level::Info); } diff --git a/tests/src/lib.rs b/tests/src/lib.rs index ba5621148..c819a1dad 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -21,7 +21,7 @@ pub use init::initialize_html_canvas; pub use self::image::ComparisonType; pub use config::{GpuTestConfiguration, GpuTestInitializer}; pub use expectations::{FailureApplicationReasons, FailureBehavior, FailureCase, FailureReason}; -pub use init::{initialize_adapter, initialize_device, initialize_instance}; +pub use init::{init_logger, initialize_adapter, initialize_device, initialize_instance}; pub use macro_rules_attribute::apply; pub use params::TestParameters; pub use run::{execute_test, TestingContext}; diff --git a/tests/tests/wgpu-validation/api/instance.rs b/tests/tests/wgpu-validation/api/instance.rs index 2f57c6184..0c358df35 100644 --- a/tests/tests/wgpu-validation/api/instance.rs +++ b/tests/tests/wgpu-validation/api/instance.rs @@ -21,7 +21,7 @@ mod multi_instance { #[test] pub fn multi_instance() { { - env_logger::init(); + wgpu_test::init_logger(); // Sequential instances. for _ in 0..3 { diff --git a/xtask/src/test.rs b/xtask/src/test.rs index 9dde0453a..055bb4ca7 100644 --- a/xtask/src/test.rs +++ b/xtask/src/test.rs @@ -87,6 +87,13 @@ pub fn run_tests( &["nextest", "run"] }; + // Test concurrency, and therefore how much contention the tests see, follows + // the CPU count. See . + match std::thread::available_parallelism() { + Ok(n) => log::info!("Host reports {n} logical CPUs"), + Err(e) => log::info!("Could not determine the host CPU count: {e}"), + } + log::info!("Generating .gpuconfig file based on gpus on the system"); // We use a test to generate the .gpuconfig file instead of using the cli directly