Skip to content

Commit 68060a4

Browse files
committed
Fix client state test cleanup
The test `test_process_client_handling_stream_request_latest_voters_snapshot` occasionally fails currently in an inconsistent manner. This tests doesn't match the cleanup steps of the other tests. As a result it makes this test susceptible to async task scheduling differences between runs. In general the tasks being tested are considered "critical" and so such failures need to result in a `panic!` if they occur. However, with async-std's tasks such panics cannot be easily intercepted / caught, especially with how they are spawned by the program with `InternalClientMessageProcessingTask::new`. So if the channels that supply the task with the information coming in get `drop`ed and then the task attempts to consume them, a panic will result. The solution to this is to cancel the task as part of the test before the channels are dropped. This will ensure that the task itself no longer gets scheduled, and the panic is avoided.
1 parent 06bf72f commit 68060a4

File tree

1 file changed

+5
-1
lines changed
  • node-metrics/src/service/client_state

1 file changed

+5
-1
lines changed

node-metrics/src/service/client_state/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ pub mod tests {
13081308
let (internal_client_message_sender, internal_client_message_receiver) = mpsc::channel(1);
13091309
let (server_message_sender_1, mut server_message_receiver_1) = mpsc::channel(1);
13101310
let (server_message_sender_2, mut server_message_receiver_2) = mpsc::channel(1);
1311-
let _process_internal_client_message_handle = InternalClientMessageProcessingTask::new(
1311+
let mut process_internal_client_message_handle = InternalClientMessageProcessingTask::new(
13121312
internal_client_message_receiver,
13131313
data_state,
13141314
client_thread_state,
@@ -1359,6 +1359,10 @@ pub mod tests {
13591359
voters_1, voters_2
13601360
]))),
13611361
);
1362+
1363+
if let Some(task_handle) = process_internal_client_message_handle.task_handle.take() {
1364+
assert_eq!(task_handle.cancel().await, None);
1365+
}
13621366
}
13631367

13641368
#[async_std::test]

0 commit comments

Comments
 (0)