Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
ec7f2ae
commit a2cfc87
Showing
5 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(feature = "full")] | ||
|
||
use tokio::fs; | ||
use tokio_test::assert_ok; | ||
|
||
#[tokio::test] | ||
async fn path_read_write() { | ||
let temp = tempdir(); | ||
let dir = temp.path(); | ||
|
||
assert_ok!(fs::write(dir.join("bar"), b"bytes").await); | ||
let out = assert_ok!(fs::read(dir.join("bar")).await); | ||
|
||
assert_eq!(out, b"bytes"); | ||
} | ||
|
||
fn tempdir() -> tempfile::TempDir { | ||
tempfile::tempdir().unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |