Replace some println spam in a test with an assertion (#439)

This commit is contained in:
Philip Degarmo 2020-09-05 21:46:23 -07:00 committed by GitHub
parent 972897690b
commit 8677e36681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -257,6 +257,7 @@ impl<'scope, T: Send + 'static> Scope<'scope, T> {
#[cfg(test)]
mod tests {
use super::*;
use std::sync::atomic::{AtomicI32, Ordering};
#[test]
pub fn test_spawn() {
@ -265,21 +266,27 @@ mod tests {
let foo = Box::new(42);
let foo = &*foo;
let count = Arc::new(AtomicI32::new(0));
let outputs = pool.scope(|scope| {
for i in 0..100 {
for _ in 0..100 {
let count_clone = count.clone();
scope.spawn(async move {
println!("task {}", i);
if *foo != 42 {
panic!("not 42!?!?")
} else {
count_clone.fetch_add(1, Ordering::Relaxed);
*foo
}
});
}
});
for output in outputs {
assert_eq!(output, 42);
for output in &outputs {
assert_eq!(*output, 42);
}
assert_eq!(outputs.len(), 100);
assert_eq!(count.load(Ordering::Relaxed), 100);
}
}