Skip to content

Commit b7341d9

Browse files
TheSentinel454Elrondclaude
committed
test(buzz-acp): drive the closed gap-replay restore over both subscription kinds
closed_gap_replay_restores_its_loss_record_for_the_retry and its membership twin set up the same retained-live_until-plus-loss state by hand. Run the one test over LossArm::both() and both CLOSED reasons (error and rate-limited), which keeps the membership rate-limited arm covered, and drop the duplicate. Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Luke Tornquist <[email protected]>
1 parent c92c7c3 commit b7341d9

2 files changed

Lines changed: 26 additions & 41 deletions

File tree

‎crates/buzz-acp/src/relay/closed_retry_tests.rs‎

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -230,48 +230,25 @@ async fn closed_after_eose_does_not_stamp_live_until() {
230230
#[tokio::test]
231231
async fn closed_gap_replay_restores_its_loss_record_for_the_retry() {
232232
const LOST: u64 = 3_000;
233-
for message in [DB_ERROR, "rate-limited: retry in 30s"] {
234-
let channel = Uuid::new_v4();
235-
let mut state = LossArm::Channel(channel).progress_past_a_loss(LOST).await;
236-
let sub = channel_sub_id(channel);
237-
let (mut client, _server, first) = open_replay(&mut state, &sub).await;
238-
assert!(first <= LOST, "first replay since={first}");
239-
assert!(!state.channel_dropped_since.contains_key(&channel));
233+
for arm in LossArm::both() {
234+
for message in [DB_ERROR, "rate-limited: retry in 30s"] {
235+
let mut state = arm.progress_past_a_loss(LOST).await;
236+
let sub = arm.sub();
237+
let (mut client, _server, first) = open_replay(&mut state, &sub).await;
238+
assert!(first <= LOST, "{sub} {message}: first replay since={first}");
239+
assert_eq!(arm.dropped(&state), None, "{sub} {message}");
240240

241-
deliver_closed(&mut client, &mut state, &sub, message).await;
242-
assert_eq!(
243-
state.channel_dropped_since.get(&channel),
244-
Some(&LOST),
245-
"{message}"
246-
);
247-
let since = state.channel_since(&channel).unwrap();
248-
assert!(
249-
since <= LOST,
250-
"{message}: the retry must still cover {LOST}, got since={since}"
251-
);
241+
deliver_closed(&mut client, &mut state, &sub, message).await;
242+
assert_eq!(arm.dropped(&state), Some(LOST), "{sub} {message}");
243+
let since = arm.since(&state).unwrap();
244+
assert!(
245+
since <= LOST,
246+
"{sub} {message}: the retry must still cover {LOST}, got since={since}"
247+
);
248+
}
252249
}
253250
}
254251

255-
#[tokio::test]
256-
async fn closed_membership_gap_replay_restores_its_loss_record() {
257-
const LOST: u64 = 3_000;
258-
let mut state = BgState::new();
259-
state.membership_sub_active = true;
260-
state.startup_watermark = Some(1_000);
261-
state.membership_last_seen = Some(1_000);
262-
let (mut live, _live_server) = test_ws_pair().await;
263-
deliver_eose(&mut live, &mut state, MEMBERSHIP_NOTIF_SUB_ID).await;
264-
state.membership_dropped_since = Some(LOST);
265-
lose_connection(&mut state).await;
266-
267-
let (mut client, _server, first) = open_replay(&mut state, MEMBERSHIP_NOTIF_SUB_ID).await;
268-
assert!(first <= LOST);
269-
assert_eq!(state.membership_dropped_since, None);
270-
deliver_closed(&mut client, &mut state, MEMBERSHIP_NOTIF_SUB_ID, DB_ERROR).await;
271-
assert_eq!(state.membership_dropped_since, Some(LOST));
272-
assert!(state.membership_since().unwrap() <= LOST);
273-
}
274-
275252
/// Through the real socket-owner loop: a channel REQ answered with an error
276253
/// CLOSED is retried after the first backoff step (2s ±20%), not before, with
277254
/// the same `since`. The loop has no other traffic, so only the parked-retry

‎crates/buzz-acp/src/relay/resume_tests.rs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,11 +1114,11 @@ pub(super) enum LossArm {
11141114
}
11151115

11161116
impl LossArm {
1117-
fn both() -> [Self; 2] {
1117+
pub(super) fn both() -> [Self; 2] {
11181118
[Self::Channel(Uuid::new_v4()), Self::Membership]
11191119
}
11201120

1121-
fn sub(self) -> String {
1121+
pub(super) fn sub(self) -> String {
11221122
match self {
11231123
Self::Channel(channel) => channel_sub_id(channel),
11241124
Self::Membership => MEMBERSHIP_NOTIF_SUB_ID.to_owned(),
@@ -1132,13 +1132,21 @@ impl LossArm {
11321132
}
11331133
}
11341134

1135-
fn dropped(self, state: &BgState) -> Option<u64> {
1135+
pub(super) fn dropped(self, state: &BgState) -> Option<u64> {
11361136
match self {
11371137
Self::Channel(channel) => state.channel_dropped_since.get(&channel).copied(),
11381138
Self::Membership => state.membership_dropped_since,
11391139
}
11401140
}
11411141

1142+
/// The `since` this subscription's next REQ would carry.
1143+
pub(super) fn since(self, state: &BgState) -> Option<u64> {
1144+
match self {
1145+
Self::Channel(channel) => state.channel_since(&channel),
1146+
Self::Membership => state.membership_since(),
1147+
}
1148+
}
1149+
11421150
/// Delivered progress at 4_000 and a retained `live_until` past a
11431151
/// recorded loss at `lost`, the socket already closed.
11441152
pub(super) async fn progress_past_a_loss(self, lost: u64) -> BgState {

0 commit comments

Comments
 (0)