diff --git a/packages/cultcache-rs/tests/unique_index.rs b/packages/cultcache-rs/tests/unique_index.rs index f6c67404..b4aa01fa 100644 --- a/packages/cultcache-rs/tests/unique_index.rs +++ b/packages/cultcache-rs/tests/unique_index.rs @@ -1086,21 +1086,20 @@ fn two_caches_racing_one_value_through_the_gate_leave_one_holder() { let value = format!("V{round}"); let gate = std::sync::Barrier::new(2); let (won_left, won_right) = std::thread::scope(|scope| { - let run = |cache: &mut CultCache, key: String| { - let (gate, value) = (&gate, &value); - scope.spawn(move || { - gate.wait(); - match cache.put(&key, &unique(value)) { - Ok(_) => true, - Err(error) => { - conflict_of(&error); - false - } + let (gate, value) = (&gate, &value); + let attempt = move |cache: &mut CultCache, key: String| { + gate.wait(); + match cache.put(&key, &unique(value)) { + Ok(_) => true, + Err(error) => { + conflict_of(&error); + false } - }) + } }; - let l = run(&mut left, format!("l{round}")); - let r = run(&mut right, format!("r{round}")); + let (left, right) = (&mut left, &mut right); + let l = scope.spawn(move || attempt(left, format!("l{round}"))); + let r = scope.spawn(move || attempt(right, format!("r{round}"))); (l.join().unwrap(), r.join().unwrap()) }); assert!(won_left ^ won_right, "{round}: exactly one writer lands (left {won_left}, right {won_right})");