Skip to content

Commit

Permalink
Assure tests don't race
Browse files Browse the repository at this point in the history
They create files in the same directory and even though they are unique,
my linux VM races nonetheless.

Let's not risk it and serialize them.
  • Loading branch information
Byron committed May 6, 2022
1 parent 220a216 commit d9778ba
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ coinit_speed_over_memory = []
log = "0.4"

[dev-dependencies]
serial_test = "0.6.0"
chrono = "0.4.9"
rand = "0.8.3"
once_cell = "1.7.2"
Expand Down
2 changes: 2 additions & 0 deletions src/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ fn get_mount_points() -> Result<Vec<MountPoint>, Error> {

#[cfg(test)]
mod tests {
use serial_test::serial;
use std::{
collections::{hash_map::Entry, HashMap},
env,
Expand All @@ -763,6 +764,7 @@ mod tests {
};

#[test]
#[serial]
fn test_list() {
crate::tests::init_logging();

Expand Down
2 changes: 2 additions & 0 deletions src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ mod tests {
tests::{get_unique_name, init_logging},
TrashContext,
};
use serial_test::serial;
use std::fs::File;

#[test]
#[serial]
fn test_delete_with_ns_file_manager() {
init_logging();
let mut trash_ctx = TrashContext::default();
Expand Down
7 changes: 7 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ pub use utils::{get_unique_name, init_logging};
))]
mod os_limited {
use super::{get_unique_name, init_logging};
use serial_test::serial;
use std::collections::{hash_map::Entry, HashMap};
use std::fs::File;

use crate as trash;

#[test]
#[serial]
fn list() {
const MAX_SECONDS_DIFFERENCE: i64 = 10;
init_logging();
Expand Down Expand Up @@ -103,6 +105,7 @@ mod os_limited {
}

#[test]
#[serial]
fn purge() {
init_logging();
let file_name_prefix = get_unique_name();
Expand Down Expand Up @@ -134,6 +137,7 @@ mod os_limited {
}

#[test]
#[serial]
fn restore() {
init_logging();
let file_name_prefix = get_unique_name();
Expand All @@ -151,6 +155,7 @@ mod os_limited {
.into_iter()
.filter(|x| x.name.starts_with(&file_name_prefix))
.collect();
dbg!(&targets, &names);
assert_eq!(targets.len(), file_count);
trash::os_limited::restore_all(targets).unwrap();
let remaining = trash::os_limited::list()
Expand All @@ -172,6 +177,7 @@ mod os_limited {
}

#[test]
#[serial]
fn restore_collision() {
init_logging();
let file_name_prefix = get_unique_name();
Expand Down Expand Up @@ -228,6 +234,7 @@ mod os_limited {
}

#[test]
#[serial]
fn restore_twins() {
init_logging();
let file_name_prefix = get_unique_name();
Expand Down

0 comments on commit d9778ba

Please sign in to comment.