Merge pull request #120 from Byron/some-tests-for-tasks

Tests to prevent against recent regression of Task::blocking(…).detach()
This commit is contained in:
Stjepan Glavina 2020-05-19 14:02:25 -07:00 committed by GitHub
commit 1487fa52bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

23
tests/task.rs Normal file
View File

@ -0,0 +1,23 @@
#[test]
fn spawn() {
assert_eq!(42, smol::run(smol::Task::spawn(async { 42 })));
}
#[test]
fn spawn_detach() {
let (s, r) = piper::chan(1);
smol::Task::spawn(async move { s.send(()).await }).detach();
assert_eq!(Some(()), smol::run(r.recv()));
}
#[test]
fn blocking() {
assert_eq!(42, smol::run(smol::Task::blocking(async { 42 })));
}
#[test]
fn blocking_detach() {
let (s, r) = piper::chan(1);
smol::Task::blocking(async move { s.send(()).await }).detach();
assert_eq!(Some(()), smol::run(r.recv()));
}