rollup merge of #20704: alexcrichton/hopefully-make-tests-less-spurious

These tests have all been failing spuroiusly on Windows from time to time, and
one suspicion is that the shilc thread outliving the main thread somehow causes
the problem. Switch all the tests over to using Thread::scoped instead of
Thread::spawn to see if it helps the issue.

cc #19120
This commit is contained in:
Alex Crichton 2015-01-07 17:17:34 -08:00
commit b21a0cee19
8 changed files with 21 additions and 21 deletions

View File

@ -66,7 +66,7 @@ pub fn main() {
assert_eq!(receiver.recv().ok(), None);
let (sender, receiver) = channel();
let _t = Thread::spawn(move|| {
let _t = Thread::scoped(move|| {
let v = Foo::FailingVariant { on_drop: SendOnDrop { sender: sender } };
});
assert_eq!(receiver.recv().unwrap(), Message::Dropped);
@ -74,7 +74,7 @@ pub fn main() {
let (sender, receiver) = channel();
let _t = {
Thread::spawn(move|| {
Thread::scoped(move|| {
let mut v = Foo::NestedVariant(box 42u, SendOnDrop {
sender: sender.clone()
}, sender.clone());

View File

@ -42,7 +42,7 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t {
pub fn main() {
range(0u, 100).map(|_| {
Thread::spawn(move|| {
Thread::scoped(move|| {
assert_eq!(count(5), 16);
})
}).collect::<Vec<_>>();

View File

@ -39,7 +39,7 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t {
pub fn main() {
range(0, 10u).map(|i| {
Thread::spawn(move|| {
Thread::scoped(move|| {
let result = count(5);
println!("result = {}", result);
assert_eq!(result, 16);

View File

@ -15,7 +15,7 @@ use std::time::Duration;
pub fn main() {
let (tx, rx) = channel();
let _t = Thread::spawn(move||{
let _t = Thread::scoped(move||{
let mut timer = Timer::new().unwrap();
timer.sleep(Duration::milliseconds(10));
tx.send(()).unwrap();

View File

@ -34,11 +34,11 @@ fn test() {
let (srv_tx, srv_rx) = channel();
let (cli_tx, cli_rx) = channel();
for _ in range(0, N) {
let _t = range(0, N).map(|_| {
let a = a.clone();
let cnt = cnt.clone();
let srv_tx = srv_tx.clone();
Thread::spawn(move|| {
Thread::scoped(move|| {
let mut a = a;
loop {
match a.accept() {
@ -52,18 +52,18 @@ fn test() {
}
}
srv_tx.send(());
});
}
})
}).collect::<Vec<_>>();
for _ in range(0, N) {
let _t = range(0, N).map(|_| {
let cli_tx = cli_tx.clone();
Thread::spawn(move|| {
Thread::scoped(move|| {
for _ in range(0, M) {
let _s = TcpStream::connect(addr).unwrap();
}
cli_tx.send(());
});
}
})
}).collect::<Vec<_>>();
drop((cli_tx, srv_tx));
// wait for senders

View File

@ -13,7 +13,7 @@ use std::thread::Thread;
pub fn main() {
let mut i = 10;
while i > 0 {
Thread::spawn({let i = i; move|| child(i)});
Thread::scoped({let i = i; move|| child(i)});
i = i - 1;
}
println!("main thread exiting");

View File

@ -19,13 +19,13 @@ pub fn main() {
let (tx, rx) = channel();
let n = 100u;
let mut expected = 0u;
for i in range(0u, n) {
let tx = tx.clone();
Thread::spawn(move|| {
child(&tx, i)
});
let _t = range(0u, n).map(|i| {
expected += i;
}
let tx = tx.clone();
Thread::scoped(move|| {
child(&tx, i)
})
}).collect::<Vec<_>>();
let mut actual = 0u;
for _ in range(0u, n) {

View File

@ -37,7 +37,7 @@ fn f(tx: Sender<bool>) {
pub fn main() {
let (tx, rx) = channel();
let _t = Thread::spawn(move|| f(tx.clone()));
let _t = Thread::scoped(move|| f(tx.clone()));
println!("hiiiiiiiii");
assert!(rx.recv().unwrap());
}