Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run CI stress tests serially #15

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
# https://github.com/rust-lang/cargo/issues/6669
- name: cargo test --doc
run: cargo test --locked --all-features --doc
# run stress tests serially, as they individually spawn many threads to provoke contention
- name: stress tests
run: cargo test -- --ignored --test-threads 1
os-check:
# run cargo test on mac and windows
runs-on: ${{ matrix.os }}
Expand All @@ -68,3 +71,6 @@ jobs:
run: cargo generate-lockfile
- name: cargo test
run: cargo test --locked --all-features --all-targets
# run stress tests serially, as they individually spawn many threads to provoke contention
- name: stress tests
run: cargo test -- --ignored --test-threads 1
3 changes: 3 additions & 0 deletions tests/cuckoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ fn stress_find_thread(env: Arc<Environment>) {
}

#[test]
#[ignore]
fn stress_test_blocking() {
let mut root = Environment::new();
root.table1 = HashMap::builder().resize_mode(ResizeMode::Blocking).build();
Expand All @@ -187,6 +188,7 @@ fn stress_test_blocking() {
}

#[test]
#[ignore]
fn stress_test_incremental() {
let mut root = Environment::new();
root.table1 = HashMap::builder()
Expand All @@ -199,6 +201,7 @@ fn stress_test_incremental() {
}

#[test]
#[ignore]
fn stress_test_incremental_slow() {
let mut root = Environment::new();
root.table1 = HashMap::builder()
Expand Down
128 changes: 103 additions & 25 deletions tests/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ use common::{threads, with_map};

// Call `contains_key` in parallel for a shared set of keys.
#[test]
#[ignore]
fn contains_key_stress() {
const ENTRIES: usize = match () {
_ if cfg!(miri) => 64,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 12,
_ => 1 << 14,
_ => 1 << 19,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 32 };

with_map(|map| {
for _ in (0..ITERATIONS).inspect(|e| debug!("{e}/{ITERATIONS}")) {
let map = map();
let mut content = [0; ENTRIES];
let mut content = vec![0; ENTRIES];

{
let guard = map.guard();
Expand Down Expand Up @@ -54,13 +55,14 @@ fn contains_key_stress() {

// Call `insert` in parallel with each thread inserting a distinct set of keys.
#[test]
#[ignore]
fn insert_stress() {
const ENTRIES: usize = match () {
_ if cfg!(miri) => 64,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 11,
_ => 1 << 14,
_ => 1 << 17,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 32 };

#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)]
struct Random(usize);
Expand Down Expand Up @@ -93,14 +95,15 @@ fn insert_stress() {

// Call `insert` in parallel on a small shared set of keys.
#[test]
#[ignore]
fn insert_overwrite_stress() {
const ENTRIES: usize = if cfg!(miri) { 64 } else { 256 };
const OPERATIONS: usize = match () {
_ if cfg!(miri) => 1,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 9,
_ => 1 << 10,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 32 };

let entries = || {
let mut entries = (0..(OPERATIONS))
Expand Down Expand Up @@ -173,14 +176,15 @@ fn insert_overwrite_stress() {

// Call `update` in parallel for a small shared set of keys.
#[test]
#[ignore]
fn update_stress() {
const ENTRIES: usize = if cfg!(miri) { 64 } else { 256 };
const OPERATIONS: usize = match () {
_ if cfg!(miri) => 1,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 10,
_ => 1 << 11,
_ => 1 << 10,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 48 };

let entries = || {
let mut entries = (0..(OPERATIONS))
Expand Down Expand Up @@ -230,13 +234,14 @@ fn update_stress() {
// Call `update` in parallel for a shared set of keys, with a single thread dedicated
// to inserting unrelated keys. This is likely to cause interference with incremental resizing.
#[test]
#[ignore]
fn update_insert_stress() {
const ENTRIES: usize = match () {
_ if cfg!(miri) => 64,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 12,
_ => 1 << 14,
_ => 1 << 18,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 48 };

with_map(|map| {
let map = map();
Expand Down Expand Up @@ -289,14 +294,15 @@ fn update_insert_stress() {
// Call `update_or_insert` in parallel for a small shared set of keys.
// Stresses the `insert` -> `update` transition in `compute`.
#[test]
#[ignore]
fn update_or_insert_stress() {
const ENTRIES: usize = if cfg!(miri) { 64 } else { 256 };
const OPERATIONS: usize = match () {
_ if cfg!(miri) => 1,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 10,
_ => 1 << 11,
_ => 1 << 10,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 48 };

let threads = threads();

Expand Down Expand Up @@ -344,14 +350,15 @@ fn update_or_insert_stress() {
//
// Stresses the `update` <-> `insert` transition in `compute`.
#[test]
#[ignore]
fn remove_update_or_insert_stress() {
const ENTRIES: usize = if cfg!(miri) { 64 } else { 256 };
const OPERATIONS: usize = match () {
_ if cfg!(miri) => 1,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 4,
_ => 1 << 7,
_ => 1 << 9,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 32 };

let threads = threads();

Expand Down Expand Up @@ -424,14 +431,15 @@ fn remove_update_or_insert_stress() {
//
// Stresses the `remove` <-> `update` transition in `compute`.
#[test]
#[ignore]
fn conditional_remove_update_or_insert_stress() {
const ENTRIES: usize = if cfg!(miri) { 64 } else { 256 };
const OPERATIONS: usize = match () {
_ if cfg!(miri) => 1,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 4,
_ => 1 << 7,
_ => 1 << 9,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 32 };

let threads = threads();

Expand Down Expand Up @@ -506,14 +514,15 @@ fn conditional_remove_update_or_insert_stress() {

// Call `remove` and `insert` in parallel for a shared set of keys.
#[test]
#[ignore]
fn insert_remove_stress() {
const ENTRIES: usize = if cfg!(miri) { 64 } else { 256 };
const OPERATIONS: usize = match () {
_ if cfg!(miri) => 1,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 7,
_ => 1 << 7,
_ => 1 << 9,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 48 };

let entries = || {
let mut entries = (0..(OPERATIONS))
Expand Down Expand Up @@ -573,11 +582,12 @@ fn insert_remove_stress() {
// and a dedicated thread for inserting unrelated keys. This is likely to cause interference
// with incremental resizing.
#[test]
#[ignore]
fn remove_mixed_stress() {
const ENTRIES: usize = match () {
_ if cfg!(miri) => 64,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 12,
_ => 1 << 14,
_ => 1 << 17,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 64 };

Expand Down Expand Up @@ -654,15 +664,81 @@ fn remove_mixed_stress() {
});
}

// Performs insert and remove operations with each thread operating on a distinct set of keys.
#[test]
#[ignore]
fn insert_remove_chunk_stress() {
const ENTRIES: usize = match () {
_ if cfg!(miri) => 48,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 10,
_ => 1 << 17,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 48 };

let run =
|barrier: &Barrier, chunk: Range<usize>, map: &HashMap<usize, usize>, threads: usize| {
barrier.wait();

for i in chunk.clone() {
assert_eq!(map.pin().insert(i, i), None);
}

for i in chunk.clone() {
assert_eq!(map.pin().get(&i), Some(&i));
}

for i in chunk.clone() {
assert_eq!(map.pin().remove(&i), Some(&i));
}

for i in chunk.clone() {
assert_eq!(map.pin().get(&i), None);
}

if !cfg!(papaya_stress) {
for (&k, &v) in map.pin().iter() {
assert!(k < ENTRIES * threads);
assert!(v == k);
}
}
};

with_map(|map| {
for _ in (0..ITERATIONS).inspect(|e| debug!("{e}/{ITERATIONS}")) {
let map = map();
let threads = threads();
let barrier = Barrier::new(threads);

thread::scope(|s| {
for i in 0..threads {
let map = &map;
let barrier = &barrier;

let chunk = (ENTRIES * i)..(ENTRIES * (i + 1));
s.spawn(move || run(barrier, chunk, map, threads));
}
});

if !cfg!(papaya_stress) {
let got: Vec<_> = map.pin().into_iter().map(|(&k, &v)| (k, v)).collect();
assert_eq!(got, []);
}

assert_eq!(map.len(), 0);
}
});
}

// Performs a mix of operations with each thread operating on a distinct set of keys.
#[test]
#[ignore]
fn mixed_chunk_stress() {
const ENTRIES: usize = match () {
_ if cfg!(miri) => 48,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 10,
_ => 1 << 14,
_ => 1 << 16,
};
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 48 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 32 };

let run =
|barrier: &Barrier, chunk: Range<usize>, map: &HashMap<usize, usize>, threads: usize| {
Expand Down Expand Up @@ -735,14 +811,15 @@ fn mixed_chunk_stress() {
// Performs a mix of operations with each thread operating on a specific entry within
// a distinct set of keys. This is more likely to cause interference with incremental resizing.
#[test]
#[ignore]
fn mixed_entry_stress() {
const ENTRIES: usize = match () {
_ if cfg!(miri) => 100,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 10,
_ => 1 << 10,
_ => 1 << 11,
};
const OPERATIONS: usize = if cfg!(miri) { 1 } else { 72 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 48 };
const ITERATIONS: usize = if cfg!(miri) { 1 } else { 32 };

let run =
|barrier: &Barrier, chunk: Range<usize>, map: &HashMap<usize, usize>, threads: usize| {
Expand Down Expand Up @@ -798,14 +875,15 @@ fn mixed_entry_stress() {

// Adapted from: https://github.com/jonhoo/flurry/tree/main/tests/jdk
#[test]
#[ignore]
fn everything() {
const SIZE: usize = match () {
_ if cfg!(miri) => 1 << 5,
_ if cfg!(papaya_stress) || cfg!(papaya_asan) => 1 << 8,
_ => 1 << 16,
_ => 1 << 20,
};
// there must be more things absent than present!
const ABSENT_SIZE: usize = if cfg!(miri) { 1 << 5 } else { 1 << 17 };
const ABSENT_SIZE: usize = if cfg!(miri) { 1 << 6 } else { 1 << 22 };
const ABSENT_MASK: usize = ABSENT_SIZE - 1;

let mut rng = rand::thread_rng();
Expand Down
Loading