Skip to content

Commit c0cab71

Browse files
khanayan123claude
andcommitted
fix(test): use interval-based task identification in FakeEventScheduler
The FakeEventScheduler used positional indexing to identify callbacks, which broke when the extended heartbeat task was added. Use interval duration to distinguish metrics (<=60s) from extended heartbeat (>60s) callbacks instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f42f6d8 commit c0cab71

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

test/telemetry/test_telemetry.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,27 @@ struct FakeEventScheduler : public EventScheduler {
4646
size_t count_tasks = 0;
4747
std::function<void()> heartbeat_callback = nullptr;
4848
std::function<void()> metrics_callback = nullptr;
49+
std::function<void()> extended_heartbeat_callback = nullptr;
4950
Optional<std::chrono::steady_clock::duration> heartbeat_interval;
5051
Optional<std::chrono::steady_clock::duration> metrics_interval;
52+
Optional<std::chrono::steady_clock::duration> extended_heartbeat_interval;
5153
bool cancelled = false;
5254

5355
// NOTE: White box testing. This is a limitation of the event scheduler API.
56+
// Tasks are registered in order: heartbeat (0), metrics (1, if enabled),
57+
// extended heartbeat (last).
5458
Cancel schedule_recurring_event(std::chrono::steady_clock::duration interval,
5559
std::function<void()> callback) override {
5660
if (count_tasks == 0) {
5761
heartbeat_callback = callback;
5862
heartbeat_interval = interval;
59-
} else if (count_tasks == 1) {
63+
} else if (interval <= std::chrono::minutes(1)) {
64+
// Metrics interval is <= 60s; extended heartbeat is much larger.
6065
metrics_callback = callback;
6166
metrics_interval = interval;
67+
} else {
68+
extended_heartbeat_callback = callback;
69+
extended_heartbeat_interval = interval;
6270
}
6371
count_tasks++;
6472
return [this]() { cancelled = true; };

0 commit comments

Comments
 (0)