v0.2.8-pre.007-fix.002

This commit is contained in:
2026-08-23 16:16:39 +02:00
parent 3b64d1e0ec
commit 9cc140fb84
5 changed files with 261 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/unit_tests/ws_session.rs
// version: 9
// version: 10
use futures_util::SinkExt; // rust-rules: trait-import
use futures_util::StreamExt; // rust-rules: trait-import
@@ -189,6 +189,18 @@ async fn yield_runtime_steps() {
return;
}
async fn wait_for_observed_ping(ping_rx: &mut tokio::sync::mpsc::UnboundedReceiver<()>) {
for _ in 0..256 {
match ping_rx.try_recv() {
std::result::Result::Ok(()) => return,
std::result::Result::Err(tokio::sync::mpsc::error::TryRecvError::Empty) => tokio::task::yield_now().await,
std::result::Result::Err(tokio::sync::mpsc::error::TryRecvError::Disconnected) => panic!("heartbeat observation channel disconnected before Ping"),
}
}
assert!(matches!(ping_rx.try_recv(), std::result::Result::Ok(())), "heartbeat Ping was not observed after bounded scheduler progress");
return;
}
#[tokio::test(flavor = "current_thread")]
async fn websocket_session_connects_and_round_trips_internal_json_rpc() {
let (listener, url) = bind_local_listener().await;
@@ -457,14 +469,12 @@ async fn helius_heartbeat_sends_ping_at_sixty_seconds_and_rearms() {
yield_runtime_steps().await;
assert!(matches!(ping_rx.try_recv(), std::result::Result::Err(tokio::sync::mpsc::error::TryRecvError::Empty)));
tokio::time::advance(std::time::Duration::from_secs(1)).await;
yield_runtime_steps().await;
assert!(matches!(ping_rx.try_recv(), std::result::Result::Ok(())));
wait_for_observed_ping(&mut ping_rx).await;
tokio::time::advance(std::time::Duration::from_secs(59)).await;
yield_runtime_steps().await;
assert!(matches!(ping_rx.try_recv(), std::result::Result::Err(tokio::sync::mpsc::error::TryRecvError::Empty)));
tokio::time::advance(std::time::Duration::from_secs(1)).await;
yield_runtime_steps().await;
assert!(matches!(ping_rx.try_recv(), std::result::Result::Ok(())));
wait_for_observed_ping(&mut ping_rx).await;
session.close().await.expect("Helius heartbeat fixture session must close");
tokio::time::resume();
server.await.expect("Helius heartbeat fixture server must complete");