Skip to content

Commit 99a03a5

Browse files
authored
runtime: add thread_park_ok test (#7402)
1 parent 933fa49 commit 99a03a5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tokio/tests/rt_handle_block_on.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,24 @@ rt_test! {
220220
assert_eq!(answer, 42);
221221
}
222222

223+
#[test]
224+
fn thread_park_ok() {
225+
use core::task::Poll;
226+
let rt = rt();
227+
let mut exit = false;
228+
rt.handle().block_on(core::future::poll_fn(move |cx| {
229+
if exit {
230+
return Poll::Ready(());
231+
}
232+
cx.waker().wake_by_ref();
233+
// Verify that consuming the park token does not result in a hang.
234+
std::thread::current().unpark();
235+
std::thread::park();
236+
exit = true;
237+
Poll::Pending
238+
}));
239+
}
240+
223241
// ==== net ======
224242

225243
#[test]

0 commit comments

Comments
 (0)