Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Move some tests to scoped instead of spawn #20704

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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|| {
Copy link
Member

Choose a reason for hiding this comment

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

Note: this means the threads don't actually run concurrently.

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|| {
Copy link
Member

Choose a reason for hiding this comment

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

These threads will all execute their bodies in sequence, not concurrently.

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());
}