-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(subscriber): add tests for excessive poll counts
A defect in the way polls are counted was fixed in #440. The defect caused the polls of a "child" task to also be counted on the "parent" task. Where in this case, the "parent" is a task that spawns the "child" task. This change adds a regression test for that fix. To do so, functionality to record and validate poll counts is added to the `console-subscriber` integration test framework. The new functionality is also used to add some basic tests for poll counts.
- Loading branch information
Showing
6 changed files
with
155 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::time::Duration; | ||
|
||
use tokio::time::sleep; | ||
|
||
mod support; | ||
use support::{assert_task, ExpectedTask}; | ||
|
||
#[test] | ||
fn single_poll() { | ||
let expected_task = ExpectedTask::default().match_default_name().expect_polls(1); | ||
|
||
let future = futures::future::ready(()); | ||
|
||
assert_task(expected_task, future); | ||
} | ||
|
||
#[test] | ||
fn two_polls() { | ||
let expected_task = ExpectedTask::default().match_default_name().expect_polls(2); | ||
|
||
let future = async { | ||
sleep(Duration::ZERO).await; | ||
}; | ||
|
||
assert_task(expected_task, future); | ||
} | ||
|
||
#[test] | ||
fn many_polls() { | ||
let expected_task = ExpectedTask::default() | ||
.match_default_name() | ||
.expect_polls(11); | ||
|
||
let future = async { | ||
for _ in 0..10 { | ||
sleep(Duration::ZERO).await; | ||
} | ||
}; | ||
|
||
assert_task(expected_task, future); | ||
} |
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,36 @@ | ||
use std::time::Duration; | ||
|
||
use tokio::time::sleep; | ||
|
||
mod support; | ||
use support::{assert_tasks, spawn_named, ExpectedTask}; | ||
|
||
/// This test asserts the behavior that was fixed in #440. Before that fix, | ||
/// the polls of a child were also counted towards the parent (the task which | ||
/// spawned the child task). In this scenario, that would result in the parent | ||
/// having 3 polls counted, when it should really be 1. | ||
#[test] | ||
fn child_polls_dont_count_towards_parent_polls() { | ||
let expected_tasks = vec![ | ||
ExpectedTask::default() | ||
.match_name("parent".into()) | ||
.expect_polls(1), | ||
ExpectedTask::default() | ||
.match_name("child".into()) | ||
.expect_polls(2), | ||
]; | ||
|
||
let future = async { | ||
let child_join_handle = spawn_named("parent", async { | ||
spawn_named("child", async { | ||
sleep(Duration::ZERO).await; | ||
}) | ||
}) | ||
.await | ||
.expect("joining parent failed"); | ||
|
||
child_join_handle.await.expect("joining child failed"); | ||
}; | ||
|
||
assert_tasks(expected_tasks, future); | ||
} |
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