rt: fix basic_scheduler notification bug (#1861)

The "global executor" thread-local is to track where to spawn new tasks,
**not** which scheduler is active on the current thread. This fixes a
bug with scheduling tasks on the basic_scheduler by tracking the
currently active basic_scheduler with a dedicated thread-local variable.

Fixes: #1851
This commit is contained in:
Carl Lerche
2019-11-29 10:23:22 -08:00
committed by GitHub
parent ec7f2ae306
commit a2cfc877a7
5 changed files with 95 additions and 10 deletions
+29
View File
@@ -0,0 +1,29 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::task;
use tokio_test::assert_ok;
use std::thread;
use std::time::Duration;
#[tokio::test]
async fn basic_blocking() {
// Run a few times
for _ in 0..100 {
let out = assert_ok!(
tokio::spawn(async {
assert_ok!(
task::spawn_blocking(|| {
thread::sleep(Duration::from_millis(5));
"hello"
})
.await
)
})
.await
);
assert_eq!(out, "hello");
}
}