Hardswap Invariants in tests + Quota fixes

This commit is contained in:
Alexey
2026-09-20 00:28:52 +03:00
parent 89dacbd17e
commit d706b3f3ba
66 changed files with 1821 additions and 505 deletions
+29
View File
@@ -90,6 +90,35 @@ async fn stop_runtime(
generation.stop_background_tasks().await;
}
#[tokio::test]
async fn user_revocation_interrupts_live_session_before_periodic_cleanup() {
let (runtime, generation, listener) = live_runtime().await;
let bootstrap = issue_bootstrap(&runtime);
let (_, token) = create_session(&listener, &runtime, &bootstrap).await;
let session_hash = token_hash(&token);
let session = runtime
.get_session(session_hash, "proxy.example.com")
.unwrap();
let polling = Arc::clone(&session);
let poll = tokio::spawn(async move { polling.poll_down(0).await });
tokio::task::yield_now().await;
let mutation = generation.proxy_shared.delete_user("alice");
assert!(mutation.cancelled >= 1);
assert!(matches!(
tokio::time::timeout(Duration::from_millis(250), poll)
.await
.unwrap()
.unwrap(),
Err(ManagerError::Closed)
));
assert!(runtime
.get_session(session_hash, "proxy.example.com")
.is_err());
stop_runtime(runtime, generation).await;
}
#[tokio::test]
async fn pause_preserves_decoy_retry_and_exact_session_replay() {
let (runtime, generation, listener) = live_runtime().await;
+2
View File
@@ -45,6 +45,7 @@ pub(super) async fn run_upgraded(
UpgradeDeadlineLease::deadline,
);
let upgraded = tokio::select! {
biased;
_ = cancellation.cancelled() => return,
result = tokio::time::timeout_at(deadline, on_upgrade) => result,
};
@@ -137,6 +138,7 @@ async fn run_multiplex(
let down = session.poll_down_websocket(cursor);
tokio::pin!(down);
let event = tokio::select! {
biased;
_ = cancellation.cancelled() => return Err(()),
_ = tokio::time::sleep_until(open_deadline.into()), if !active => return Err(()),
_ = tokio::time::sleep_until(next_ping.into()) => DriverEvent::Liveness,
+7
View File
@@ -20,6 +20,7 @@ pub(super) async fn read_message(
backpressure_timeout: Duration,
) -> Result<(Message, Option<WebSocketBudgetLease>), ()> {
tokio::select! {
biased;
_ = cancellation.cancelled() => return Err(()),
ready = socket.get_ref().readable() => ready.map_err(|_| ())?,
}
@@ -28,6 +29,7 @@ pub(super) async fn read_message(
Some(reserve_data(runtime, owner, maximum, cancellation, backpressure_timeout).await?);
}
let message = tokio::select! {
biased;
_ = cancellation.cancelled() => return Err(()),
message = socket.next() => message.ok_or(())?.map_err(|_| ())?,
};
@@ -59,6 +61,7 @@ pub(super) async fn reserve_data(
return Ok(budget);
}
tokio::select! {
biased;
_ = cancellation.cancelled() => return Err(()),
_ = notified => {}
}
@@ -114,6 +117,7 @@ pub(super) async fn process_lane(
Err(_) => return Err(()),
}
tokio::select! {
biased;
_ = cancellation.cancelled() => return Err(()),
_ = notified => {}
}
@@ -147,6 +151,7 @@ where
Err(_) => return Err(()),
}
tokio::select! {
biased;
_ = cancellation.cancelled() => return Err(()),
_ = notified => {}
}
@@ -163,6 +168,7 @@ pub(super) async fn send(
timeout: Duration,
) -> Result<(), ()> {
tokio::select! {
biased;
_ = cancellation.cancelled() => Err(()),
result = tokio::time::timeout(timeout, socket.send(message)) => {
result.map_err(|_| ())?.map_err(|_| ())
@@ -176,6 +182,7 @@ pub(super) async fn flush(
timeout: Duration,
) -> Result<(), ()> {
tokio::select! {
biased;
_ = cancellation.cancelled() => Err(()),
result = tokio::time::timeout(timeout, socket.flush()) => {
result.map_err(|_| ())?.map_err(|_| ())
+1
View File
@@ -39,6 +39,7 @@ pub(super) async fn run_lane(
let down = session.poll_down_websocket_lane(reservation.lane_identity(), cursor);
tokio::pin!(down);
let event = tokio::select! {
biased;
_ = cancellation.cancelled() => return Err(()),
_ = tokio::time::sleep_until(open_deadline.into()), if !active => return Err(()),
_ = tokio::time::sleep_until(next_ping.into()) => DriverEvent::Liveness,