Skip to content

Commit 9b91cbf

Browse files
TheSentinel454Elrondclaude
committed
fix(loadgen): start no hot-thread request once the run stops
An overdue reply or fetch and the stop signal can be ready together, and select! picks either, so an author could start new work during the shutdown grace and fail the run if that request outlived it. Return once the run is stopping, so only work already in flight settles. 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 da8f81b commit 9b91cbf

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

  • crates/buzz-test-client/src/loadgen

‎crates/buzz-test-client/src/loadgen/run.rs‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,11 @@ async fn hot_author(shared: Arc<Shared>, index: usize) {
10521052
_ = tokio::time::sleep_until(due.into()) => {}
10531053
_ = stopping(&shared) => return,
10541054
}
1055+
// An overdue arrival and the stop can be ready together, and `select!`
1056+
// picks either; start nothing new once the run is stopping.
1057+
if stopped(&shared) {
1058+
return;
1059+
}
10551060
if next_reply == Some(due) {
10561061
next_reply = rng.after(profile.replies_per_hour);
10571062
let event = EventBuilder::new(
@@ -1765,10 +1770,11 @@ hold_secs = 2
17651770
channel: String,
17661771
}
17671772

1768-
/// Runs two hot-thread authors for a second against a relay whose root
1769-
/// lookup returns a newer reply-shaped decoy by the root's author, plus
1770-
/// the hot root itself when `seeded`.
1771-
async fn hot_thread_run(seeded: bool) -> HotRun {
1773+
/// Runs `[hot_thread]` section `hot` for a second against a relay whose
1774+
/// root lookup returns a newer reply-shaped decoy by the root's author,
1775+
/// plus the hot root itself when `seeded`, and which takes `delay` to
1776+
/// accept each event.
1777+
async fn hot_thread_run(seeded: bool, hot: &str, delay: Duration) -> HotRun {
17721778
let author = hot_root_keys("t");
17731779
let channel = identity::channel_id("t", 0, 0);
17741780
let root = EventBuilder::new(kind(KIND_STREAM_MESSAGE), HOT_ROOT_PREFIX)
@@ -1792,6 +1798,9 @@ hold_secs = 2
17921798
if target == "/events" {
17931799
let event: Event = serde_json::from_slice(body).unwrap();
17941800
post_log.lock().unwrap().push(event);
1801+
if !delay.is_zero() {
1802+
tokio::task::block_in_place(|| std::thread::sleep(delay));
1803+
}
17951804
return (200, json!({"accepted": true, "message": ""}).to_string());
17961805
}
17971806
let filter: Value = serde_json::from_slice(body).unwrap();
@@ -1819,9 +1828,7 @@ humans = 0
18191828
agents = 0
18201829
channels_per_member = 1
18211830
[hot_thread]
1822-
authors = 2
1823-
replies_per_hour = 36000.0
1824-
fetches_per_hour = 36000.0
1831+
{hot}
18251832
[[ramp]]
18261833
users = 1.0
18271834
hold_secs = 1
@@ -1842,9 +1849,11 @@ hold_secs = 1
18421849
}
18431850
}
18441851

1852+
const TWO_AUTHORS: &str = "authors = 2\nreplies_per_hour = 36000.0\nfetches_per_hour = 36000.0";
1853+
18451854
#[tokio::test]
18461855
async fn hot_thread_authors_reply_to_the_hot_root_and_fail_without_it() {
1847-
let run = hot_thread_run(true).await;
1856+
let run = hot_thread_run(true, TWO_AUTHORS, Duration::ZERO).await;
18481857
let report = run.outcome.expect("hot-thread run passes");
18491858
assert_eq!(report["steps"][0]["hot_authors"], 2, "{report}");
18501859
assert!(!run.posted.is_empty(), "{report}");
@@ -1881,12 +1890,24 @@ hold_secs = 1
18811890
assert!(ops["hot_reply"]["count"].as_u64() > Some(0), "{report}");
18821891

18831892
// Without a seeded hot root the authors post nothing and the step aborts.
1884-
let run = hot_thread_run(false).await;
1893+
let run = hot_thread_run(false, TWO_AUTHORS, Duration::ZERO).await;
18851894
let report = run.outcome.expect_err("a missing hot root fails the run");
18861895
assert!(run.posted.is_empty());
18871896
let reason = report["steps"][0]["abort_reason"]
18881897
.as_str()
18891898
.unwrap_or_default();
18901899
assert!(reason.starts_with("thread_fetch"), "{report}");
18911900
}
1901+
1902+
/// Every author is mid-reply at the stop, with its next reply already
1903+
/// due when that one settles. Each may finish the reply it started, but
1904+
/// must start no other: one reply per author settles during shutdown.
1905+
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
1906+
async fn hot_thread_authors_start_nothing_once_the_run_stops() {
1907+
let busy = "authors = 8\nreplies_per_hour = 36000000.0";
1908+
let run = hot_thread_run(true, busy, Duration::from_millis(300)).await;
1909+
let report = run.outcome.expect("in-flight replies settle in the grace");
1910+
let settled = &report["shutdown"]["ops"]["hot_reply"]["count"];
1911+
assert_eq!(settled.as_u64(), Some(8), "{report}");
1912+
}
18921913
}

0 commit comments

Comments
 (0)