Skip to content

Commit

Permalink
test: Move some tests to scoped instead of spawn
Browse files Browse the repository at this point in the history
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 rust-lang#19120
  • Loading branch information
alexcrichton committed Jan 7, 2015
1 parent 9e4e524 commit 99b39cc
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/test/run-pass/drop-trait-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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);
assert_eq!(receiver.recv().ok(), None);

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());
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/extern-stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_>>();
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/extern-yield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-9396.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions src/test/run-pass/tcp-accept-stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions src/test/run-pass/unique-send-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _t = range(0u, n).map(|i| {
expected += i;
let tx = tx.clone();
Thread::spawn(move|| {
Thread::scoped(move|| {
child(&tx, i)
});
expected += i;
}
})
}).collect::<Vec<_>>();

let mut actual = 0u;
for _ in range(0u, n) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/unwind-resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

1 comment on commit 99b39cc

@sfackler
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

:(

Please sign in to comment.