Skip to content

Commit 76c9bff

Browse files
committed
serial_test
1 parent 12cc902 commit 76c9bff

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Install Rust ${{ matrix.rust_version }}
3838
run: rustup default ${{ matrix.rust_version }}
3939
- name: Run Tests
40-
run: cargo test --no-default-features --features=prost -- --test-threads=1
40+
run: cargo test --no-default-features --features=prost
4141
cross-test:
4242
name: Test ${{ matrix.target }}
4343
runs-on: ubuntu-latest
@@ -55,7 +55,7 @@ jobs:
5555
- name: Install Cross
5656
run: cargo install cross --git https://github.com/cross-rs/cross
5757
- name: Run Tests
58-
run: cross test --target ${{ matrix.target }} --no-default-features --features=prost -- --test-threads=1
58+
run: cross test --target ${{ matrix.target }} --no-default-features --features=prost
5959
cross-test-mips-mipssel:
6060
name: Test ${{ matrix.target }}
6161
runs-on: ubuntu-latest
@@ -71,7 +71,7 @@ jobs:
7171
- name: Install Cross
7272
run: cargo install cross --git https://github.com/cross-rs/cross
7373
- name: Run Tests
74-
run: cross +nightly test --target ${{ matrix.target }} --no-default-features --features=prost -- --test-threads=1
74+
run: cross +nightly test --target ${{ matrix.target }} --no-default-features --features=prost
7575
env:
7676
RUSTFLAGS: "-C opt-level=1"
7777
test-wasm-browser:

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ wasi = "0.11"
6161
[dev-dependencies]
6262
average = "0.14"
6363
criterion = "=0.3.3"
64+
serial_test = "3.2"
6465

6566
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
6667
wasm-bindgen-test = "0.3"

src/instant.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,18 @@ impl Into<prost_types::Timestamp> for Instant {
279279

280280
#[cfg(test)]
281281
mod tests {
282-
use once_cell::sync::Lazy;
283-
284282
use super::Instant;
285283
use crate::{with_clock, Clock};
284+
use serial_test::serial;
285+
use std::thread;
286286
use std::time::Duration;
287-
use std::{sync::Mutex, thread};
288-
289-
static RECENT_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
290287

291288
#[test]
292289
#[cfg_attr(
293290
all(target_arch = "wasm32", target_os = "unknown"),
294291
ignore = "WASM thread cannot sleep"
295292
)]
293+
#[serial]
296294
fn test_now() {
297295
let t0 = Instant::now();
298296
thread::sleep(Duration::from_millis(15));
@@ -311,9 +309,8 @@ mod tests {
311309
all(target_arch = "wasm32", target_os = "unknown"),
312310
ignore = "WASM thread cannot sleep"
313311
)]
312+
#[serial]
314313
fn test_recent() {
315-
let _guard = RECENT_LOCK.lock().unwrap();
316-
317314
// Ensures that the recent global value is zero so that the fallback logic can kick in.
318315
crate::set_recent(Instant(0));
319316

@@ -346,9 +343,8 @@ mod tests {
346343
all(target_arch = "wasm32", target_os = "unknown"),
347344
wasm_bindgen_test::wasm_bindgen_test
348345
)]
346+
#[serial]
349347
fn test_mocking() {
350-
let _guard = RECENT_LOCK.lock().unwrap();
351-
352348
// Ensures that the recent global value is zero so that the fallback logic can kick in.
353349
crate::set_recent(Instant(0));
354350

@@ -380,6 +376,7 @@ mod tests {
380376
all(target_arch = "wasm32", target_os = "unknown"),
381377
wasm_bindgen_test::wasm_bindgen_test
382378
)]
379+
#[serial]
383380
fn checked_arithmetic_u64_overflow() {
384381
fn nanos_to_dur(total_nanos: u128) -> Duration {
385382
let nanos_per_sec = Duration::from_secs(1).as_nanos();

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ fn mul_div_po2_u64(value: u64, numer: u64, denom: u32) -> u64 {
542542
#[cfg(test)]
543543
mod tests {
544544
use super::Clock;
545+
use serial_test::serial;
545546

546547
#[cfg(not(target_arch = "wasm32"))]
547548
use super::{Counter, Monotonic};
@@ -557,6 +558,7 @@ mod tests {
557558
all(target_arch = "wasm32", target_os = "unknown"),
558559
wasm_bindgen_test::wasm_bindgen_test
559560
)]
561+
#[serial]
560562
fn test_mock() {
561563
let (clock, mock) = Clock::mock();
562564
assert_eq!(clock.now().0, 0);
@@ -565,6 +567,7 @@ mod tests {
565567
}
566568

567569
#[test]
570+
#[serial]
568571
#[cfg_attr(
569572
all(target_arch = "wasm32", target_os = "unknown"),
570573
wasm_bindgen_test::wasm_bindgen_test
@@ -575,6 +578,7 @@ mod tests {
575578
}
576579

577580
#[test]
581+
#[serial]
578582
#[cfg_attr(
579583
all(target_arch = "wasm32", target_os = "unknown"),
580584
wasm_bindgen_test::wasm_bindgen_test
@@ -585,6 +589,7 @@ mod tests {
585589
}
586590

587591
#[test]
592+
#[serial]
588593
#[cfg_attr(
589594
all(target_arch = "wasm32", target_os = "unknown"),
590595
wasm_bindgen_test::wasm_bindgen_test
@@ -598,6 +603,7 @@ mod tests {
598603

599604
#[cfg(not(target_arch = "wasm32"))]
600605
#[test]
606+
#[serial]
601607
#[cfg_attr(not(feature = "flaky_tests"), ignore)]
602608
fn test_reference_source_calibration() {
603609
let mut clock = Clock::new();
@@ -681,6 +687,7 @@ mod tests {
681687

682688
#[cfg(not(target_arch = "wasm32"))]
683689
#[test]
690+
#[serial]
684691
#[cfg_attr(not(feature = "flaky_tests"), ignore)]
685692
fn measure_source_reference_self_timing() {
686693
let source = Counter::default();

src/stats.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ impl Variance {
6161
#[cfg(test)]
6262
mod tests {
6363
use super::Variance;
64+
use serial_test::serial;
6465

6566
#[test]
67+
#[serial]
6668
fn basic() {
6769
let inputs = &[5.0, 10.0, 12.0, 15.0, 20.0];
6870
let mut variance = Variance::default();

src/upkeep.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,12 @@ impl Drop for Handle {
170170
#[cfg(test)]
171171
mod tests {
172172
use super::Upkeep;
173+
use serial_test::serial;
173174
use std::time::Duration;
174175

175176
#[test]
176177
#[cfg_attr(target_arch = "wasm32", ignore)] // WASM is single threaded
178+
#[serial]
177179
fn test_spawning_second_upkeep() {
178180
let first = Upkeep::new(Duration::from_millis(250)).start();
179181
let second = Upkeep::new(Duration::from_millis(250))

0 commit comments

Comments
 (0)