Skip to content

Commit 8b1ecf2

Browse files
committed
test(subscriber): prefer sleep over yield_now in tests
A flakiness problem has been discovered with the `console-subscriber` integration tests introduced in #452. Issue #473 is tracking the issue. It has been observed that we only "miss" the wake operation event when it comes from `yield_now()`, but not when it comes from a task that yielded due to `sleep`, even when the duration is zero. it is likely that this is due to nature of the underlying race condition. This change removes all the calls to `yield_now()` from the `framework` tests, except those where we wish to actually test self wakes.
1 parent 6dd661d commit 8b1ecf2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

console-subscriber/tests/framework.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn test_spawned_task() {
100100
let future = async {
101101
task::Builder::new()
102102
.name("another-name")
103-
.spawn(async { task::yield_now().await })
103+
.spawn(async { sleep(Duration::ZERO).await })
104104
};
105105

106106
assert_task(expected_task, future);
@@ -113,7 +113,7 @@ fn test_spawned_task() {
113113
fn fail_wrong_task_name() {
114114
let expected_task = ExpectedTask::default().match_name("wrong-name".into());
115115

116-
let future = async { task::yield_now().await };
116+
let future = async { sleep(Duration::ZERO).await };
117117

118118
assert_task(expected_task, future);
119119
}
@@ -132,11 +132,11 @@ fn multiple_tasks() {
132132
let future = async {
133133
let task1 = task::Builder::new()
134134
.name("task-1")
135-
.spawn(async { task::yield_now().await })
135+
.spawn(async { sleep(Duration::ZERO).await })
136136
.unwrap();
137137
let task2 = task::Builder::new()
138138
.name("task-2")
139-
.spawn(async { task::yield_now().await })
139+
.spawn(async { sleep(Duration::ZERO).await })
140140
.unwrap();
141141

142142
tokio::try_join! {
@@ -166,11 +166,11 @@ fn fail_1_of_2_expected_tasks() {
166166
let future = async {
167167
let task1 = task::Builder::new()
168168
.name("task-1")
169-
.spawn(async { task::yield_now().await })
169+
.spawn(async { sleep(Duration::ZERO).await })
170170
.unwrap();
171171
let task2 = task::Builder::new()
172172
.name("task-2")
173-
.spawn(async { task::yield_now().await })
173+
.spawn(async { sleep(Duration::ZERO).await })
174174
.unwrap();
175175

176176
tokio::try_join! {

0 commit comments

Comments
 (0)