Skip to content

Commit 99b39cc

Browse files
committed
test: Move some tests to scoped instead of spawn
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
1 parent 9e4e524 commit 99b39cc

8 files changed

+20
-20
lines changed

src/test/run-pass/drop-trait-enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ pub fn main() {
6666
assert_eq!(receiver.recv().ok(), None);
6767

6868
let (sender, receiver) = channel();
69-
let _t = Thread::spawn(move|| {
69+
let _t = Thread::scoped(move|| {
7070
let v = Foo::FailingVariant { on_drop: SendOnDrop { sender: sender } };
7171
});
7272
assert_eq!(receiver.recv().unwrap(), Message::Dropped);
7373
assert_eq!(receiver.recv().ok(), None);
7474

7575
let (sender, receiver) = channel();
7676
let _t = {
77-
Thread::spawn(move|| {
77+
Thread::scoped(move|| {
7878
let mut v = Foo::NestedVariant(box 42u, SendOnDrop {
7979
sender: sender.clone()
8080
}, sender.clone());

src/test/run-pass/extern-stress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t {
4242

4343
pub fn main() {
4444
range(0u, 100).map(|_| {
45-
Thread::spawn(move|| {
45+
Thread::scoped(move|| {
4646
assert_eq!(count(5), 16);
4747
})
4848
}).collect::<Vec<_>>();

src/test/run-pass/extern-yield.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t {
3939

4040
pub fn main() {
4141
range(0, 10u).map(|i| {
42-
Thread::spawn(move|| {
42+
Thread::scoped(move|| {
4343
let result = count(5);
4444
println!("result = {}", result);
4545
assert_eq!(result, 16);

src/test/run-pass/issue-9396.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::time::Duration;
1515

1616
pub fn main() {
1717
let (tx, rx) = channel();
18-
let _t = Thread::spawn(move||{
18+
let _t = Thread::scoped(move||{
1919
let mut timer = Timer::new().unwrap();
2020
timer.sleep(Duration::milliseconds(10));
2121
tx.send(()).unwrap();

src/test/run-pass/tcp-accept-stress.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ fn test() {
3434

3535
let (srv_tx, srv_rx) = channel();
3636
let (cli_tx, cli_rx) = channel();
37-
for _ in range(0, N) {
37+
let _t = range(0, N).map(|_| {
3838
let a = a.clone();
3939
let cnt = cnt.clone();
4040
let srv_tx = srv_tx.clone();
41-
Thread::spawn(move|| {
41+
Thread::scoped(move|| {
4242
let mut a = a;
4343
loop {
4444
match a.accept() {
@@ -52,18 +52,18 @@ fn test() {
5252
}
5353
}
5454
srv_tx.send(());
55-
});
56-
}
55+
})
56+
}).collect::<Vec<_>>();
5757

58-
for _ in range(0, N) {
58+
let _t = range(0, N).map(|_| {
5959
let cli_tx = cli_tx.clone();
60-
Thread::spawn(move|| {
60+
Thread::scoped(move|| {
6161
for _ in range(0, M) {
6262
let _s = TcpStream::connect(addr).unwrap();
6363
}
6464
cli_tx.send(());
65-
});
66-
}
65+
})
66+
}).collect::<Vec<_>>();
6767
drop((cli_tx, srv_tx));
6868

6969
// wait for senders

src/test/run-pass/threads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::thread::Thread;
1313
pub fn main() {
1414
let mut i = 10;
1515
while i > 0 {
16-
Thread::spawn({let i = i; move|| child(i)});
16+
Thread::scoped({let i = i; move|| child(i)});
1717
i = i - 1;
1818
}
1919
println!("main thread exiting");

src/test/run-pass/unique-send-2.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ pub fn main() {
1919
let (tx, rx) = channel();
2020
let n = 100u;
2121
let mut expected = 0u;
22-
for i in range(0u, n) {
22+
let _t = range(0u, n).map(|i| {
23+
expected += i;
2324
let tx = tx.clone();
24-
Thread::spawn(move|| {
25+
Thread::scoped(move|| {
2526
child(&tx, i)
26-
});
27-
expected += i;
28-
}
27+
})
28+
}).collect::<Vec<_>>();
2929

3030
let mut actual = 0u;
3131
for _ in range(0u, n) {

src/test/run-pass/unwind-resource.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn f(tx: Sender<bool>) {
3737

3838
pub fn main() {
3939
let (tx, rx) = channel();
40-
let _t = Thread::spawn(move|| f(tx.clone()));
40+
let _t = Thread::scoped(move|| f(tx.clone()));
4141
println!("hiiiiiiiii");
4242
assert!(rx.recv().unwrap());
4343
}

0 commit comments

Comments
 (0)