From e8a83d1edd9395af857e2cdd897d68c1bd29b0c4 Mon Sep 17 00:00:00 2001 From: thomasschafer Date: Sat, 7 Dec 2024 17:21:07 +0000 Subject: [PATCH] Fix tests failing when running in parallel --- .github/workflows/test.yml | 7 +------ Cargo.lock | 41 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + tests/app.rs | 15 ++++++++------ 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a082c95..3a2dc6f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,10 +32,5 @@ jobs: - name: Lint run: cargo clippy - - name: Run tests (Windows) - if: matrix.os == 'windows-latest' - run: cargo test --verbose -- --test-threads=1 - - - name: Run tests (Unix) - if: matrix.os != 'windows-latest' + - name: Run tests run: cargo test --verbose diff --git a/Cargo.lock b/Cargo.lock index a77ab44..15c1d86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1058,6 +1058,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scc" +version = "2.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66b202022bb57c049555430e11fc22fea12909276a80a4c3d368da36ac1d88ed" +dependencies = [ + "sdd", +] + [[package]] name = "scooter" version = "0.2.1" @@ -1079,6 +1088,7 @@ dependencies = [ "regex", "serde", "serde_json", + "serial_test", "similar", "simple-log", "tempfile", @@ -1091,6 +1101,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sdd" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49c1eeaf4b6a87c7479688c6d52b9f1153cedd3c489300564f932b065c6eab95" + [[package]] name = "serde" version = "1.0.215" @@ -1146,6 +1162,31 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "serial_test" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b258109f244e1d6891bf1053a55d63a5cd4f8f4c30cf9a1280989f80e7a1fa9" +dependencies = [ + "futures", + "log", + "once_cell", + "parking_lot", + "scc", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d69265a08751de7844521fd15003ae0a888e035773ba05695c5c759a6f89eef" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "shlex" version = "1.3.0" diff --git a/Cargo.toml b/Cargo.toml index 8ef4afa..2a29674 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ ratatui = "0.27.0" regex = "1.11.1" serde = { version = "1.0.215", features = ["derive"] } serde_json = "1.0.133" +serial_test = "3.2.0" similar = "2.6.0" simple-log = "2.1.1" tokio = { version = "1.41.1", features = ["full"] } diff --git a/tests/app.rs b/tests/app.rs index ddc557d..a342d09 100644 --- a/tests/app.rs +++ b/tests/app.rs @@ -2,14 +2,16 @@ use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifi use scooter::{ App, EventHandler, ReplaceResult, ReplaceState, Screen, SearchFields, SearchResult, SearchState, }; +use serial_test::serial; use std::cmp::max; -use std::fs::{self, create_dir_all, File}; -use std::io::Write; +use std::fs::{self, create_dir_all}; use std::mem; use std::path::{Path, PathBuf}; use std::thread::sleep; use std::time::{Duration, Instant}; use tempfile::TempDir; +use tokio::fs::File; +use tokio::io::AsyncWriteExt; #[tokio::test] async fn test_search_state() { @@ -167,15 +169,14 @@ macro_rules! create_test_files { let path = Path::new(&path); create_dir_all(path.parent().unwrap()).unwrap(); { - let mut file = File::create(path).unwrap(); - file.write_all(contents.as_bytes()).unwrap(); - file.sync_all().unwrap(); + let mut file = File::create(path).await.unwrap(); + file.write_all(contents.as_bytes()).await.unwrap(); + file.sync_all().await.unwrap(); } )+ #[cfg(windows)] sleep(Duration::from_millis(100)); - temp_dir } }; @@ -355,11 +356,13 @@ macro_rules! test_with_both_regex_modes { use super::*; #[tokio::test] + #[serial] async fn with_advanced_regex() { ($test_fn)(true).await; } #[tokio::test] + #[serial] async fn without_advanced_regex() { ($test_fn)(false).await; }