Skip to content

Commit

Permalink
test: test with tracing (#3906)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Jun 30, 2021
1 parent b877629 commit 90e1935
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -122,7 +122,7 @@ jobs:

# Run `tokio` with "unstable" cfg flag.
- name: test tokio full --cfg unstable
run: cargo test --features full
run: cargo test --all-features
working-directory: tokio
env:
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
Expand Down
14 changes: 7 additions & 7 deletions tokio/src/runtime/tests/loom_queue.rs
Expand Up @@ -30,7 +30,7 @@ fn basic() {

for _ in 0..2 {
for _ in 0..2 {
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local.push_back(task, &inject);
}

Expand All @@ -39,7 +39,7 @@ fn basic() {
}

// Push another task
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local.push_back(task, &inject);

while local.pop().is_some() {
Expand Down Expand Up @@ -81,15 +81,15 @@ fn steal_overflow() {
let mut n = 0;

// push a task, pop a task
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local.push_back(task, &inject);

if local.pop().is_some() {
n += 1;
}

for _ in 0..6 {
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local.push_back(task, &inject);
}

Expand Down Expand Up @@ -133,7 +133,7 @@ fn multi_stealer() {

// Push work
for _ in 0..NUM_TASKS {
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local.push_back(task, &inject);
}

Expand Down Expand Up @@ -170,10 +170,10 @@ fn chained_steal() {

// Load up some tasks
for _ in 0..4 {
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
l1.push_back(task, &inject);

let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
l2.push_back(task, &inject);
}

Expand Down
21 changes: 21 additions & 0 deletions tokio/src/runtime/tests/mod.rs
@@ -1,3 +1,24 @@
#[cfg(not(all(tokio_unstable, feature = "tracing")))]
use crate::runtime::task::joinable;

#[cfg(all(tokio_unstable, feature = "tracing"))]
use self::joinable_wrapper::joinable;

#[cfg(all(tokio_unstable, feature = "tracing"))]
mod joinable_wrapper {
use crate::runtime::task::{JoinHandle, Notified, Schedule};
use tracing::Instrument;

pub(crate) fn joinable<T, S>(task: T) -> (Notified<S>, JoinHandle<T::Output>)
where
T: std::future::Future + Send + 'static,
S: Schedule,
{
let span = tracing::trace_span!("test_span");
crate::runtime::task::joinable(task.instrument(span))
}
}

cfg_loom! {
mod loom_basic_scheduler;
mod loom_blocking;
Expand Down
10 changes: 5 additions & 5 deletions tokio/src/runtime/tests/queue.rs
Expand Up @@ -10,7 +10,7 @@ fn fits_256() {
let inject = queue::Inject::new();

for _ in 0..256 {
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local.push_back(task, &inject);
}

Expand All @@ -25,7 +25,7 @@ fn overflow() {
let inject = queue::Inject::new();

for _ in 0..257 {
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local.push_back(task, &inject);
}

Expand All @@ -49,7 +49,7 @@ fn steal_batch() {
let inject = queue::Inject::new();

for _ in 0..4 {
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local1.push_back(task, &inject);
}

Expand Down Expand Up @@ -103,7 +103,7 @@ fn stress1() {

for _ in 0..NUM_LOCAL {
for _ in 0..NUM_PUSH {
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local.push_back(task, &inject);
}

Expand Down Expand Up @@ -158,7 +158,7 @@ fn stress2() {
let mut num_pop = 0;

for i in 0..NUM_TASKS {
let (task, _) = task::joinable::<_, Runtime>(async {});
let (task, _) = super::joinable::<_, Runtime>(async {});
local.push_back(task, &inject);

if i % 128 == 0 && local.pop().is_some() {
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/runtime/tests/task.rs
Expand Up @@ -7,13 +7,13 @@ use std::sync::Arc;

#[test]
fn create_drop() {
let _ = task::joinable::<_, Runtime>(async { unreachable!() });
let _ = super::joinable::<_, Runtime>(async { unreachable!() });
}

#[test]
fn schedule() {
with(|rt| {
let (task, _) = task::joinable(async {
let (task, _) = super::joinable(async {
crate::task::yield_now().await;
});

Expand All @@ -26,7 +26,7 @@ fn schedule() {
#[test]
fn shutdown() {
with(|rt| {
let (task, _) = task::joinable(async {
let (task, _) = super::joinable(async {
loop {
crate::task::yield_now().await;
}
Expand Down

0 comments on commit 90e1935

Please sign in to comment.