Skip to content

Commit f5d5746

Browse files
authored
Merge pull request #2951 from DeusData/distill/2215-idle-cadence-guard
test(daemon): pin the idle maintenance-probe cadence
2 parents 0640103 + fb23905 commit f5d5746

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎src/daemon/frontend.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ static atomic_uint_fast64_t frontend_test_worker_observation_count = ATOMIC_VAR_
121121
static atomic_uint_fast64_t frontend_test_worker_idle_count = ATOMIC_VAR_INIT(0);
122122
static atomic_uint_fast64_t frontend_test_routed_cancellation_count = ATOMIC_VAR_INIT(0);
123123
static atomic_uint_fast32_t frontend_test_replay_budget_ms = ATOMIC_VAR_INIT(0);
124+
static atomic_uint_fast32_t frontend_test_monitor_idle_sleep = ATOMIC_VAR_INIT(0);
124125

125126
void cbm_daemon_frontend_test_observer_reset(bool hold_monitor) {
126127
atomic_store_explicit(&frontend_test_monitor_observation_count, 0, memory_order_release);
128+
atomic_store_explicit(&frontend_test_monitor_idle_sleep, 0, memory_order_release);
127129
atomic_store_explicit(&frontend_test_worker_observation_count, 0, memory_order_release);
128130
atomic_store_explicit(&frontend_test_worker_idle_count, 0, memory_order_release);
129131
atomic_store_explicit(&frontend_test_monitor_is_waiting, false, memory_order_release);
@@ -157,6 +159,10 @@ uint64_t cbm_daemon_frontend_test_routed_cancellations(void) {
157159
uint32_t cbm_daemon_frontend_test_replay_timeout_ms(void) {
158160
return (uint32_t)atomic_load_explicit(&frontend_test_replay_budget_ms, memory_order_acquire);
159161
}
162+
163+
uint32_t cbm_daemon_frontend_test_monitor_idle_sleep_ms(void) {
164+
return (uint32_t)atomic_load_explicit(&frontend_test_monitor_idle_sleep, memory_order_acquire);
165+
}
160166
#endif
161167

162168
static cbm_version_cohort_maintenance_presence_t frontend_observe_maintenance(
@@ -187,7 +193,11 @@ static void *frontend_maintenance_monitor_worker(void *opaque) {
187193
cbm_version_cohort_maintenance_presence_t presence =
188194
frontend_observe_maintenance(monitor->manager, true);
189195
if (presence == CBM_VERSION_COHORT_MAINTENANCE_ABSENT) {
190-
cbm_usleep(FRONTEND_MAINTENANCE_IDLE_POLL_MS * 1000U);
196+
uint32_t idle_ms = FRONTEND_MAINTENANCE_IDLE_POLL_MS;
197+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
198+
atomic_store_explicit(&frontend_test_monitor_idle_sleep, idle_ms, memory_order_release);
199+
#endif
200+
cbm_usleep(idle_ms * 1000U);
191201
continue;
192202
}
193203

‎src/daemon/frontend.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ uint64_t cbm_daemon_frontend_test_routed_cancellations(void);
8383
* settings requests. Recovery tests use distinct connect and startup budgets
8484
* and compare. */
8585
uint32_t cbm_daemon_frontend_test_replay_timeout_ms(void);
86+
/* Milliseconds the maintenance monitor last slept in its no-maintenance
87+
* (ABSENT) branch, recorded from the exact value passed to the sleep; zero
88+
* until the first idle cycle after reset. Pins the idle probe cadence. */
89+
uint32_t cbm_daemon_frontend_test_monitor_idle_sleep_ms(void);
8690
#endif
8791

8892
/* Takes ownership of client and borrows cohort_manager for the complete call.

‎tests/test_daemon_frontend.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,32 @@ TEST(daemon_frontend_idle_uses_one_maintenance_observer) {
16411641
ASSERT_TRUE(fixture_closed);
16421642
PASS();
16431643
}
1644+
1645+
/* An idle monitor must not repeatedly perform the expensive presence probe
1646+
* while no maintenance request exists (#2093). The monitor records the exact
1647+
* value it sleeps on in its no-maintenance branch; once recorded that value is
1648+
* stable, so the verdict depends on neither elapsed time nor scheduler cadence.
1649+
* The deadline below is only a hang guard. */
1650+
TEST(daemon_frontend_idle_maintenance_probe_is_bounded) {
1651+
frontend_maintenance_fixture_t fixture;
1652+
ASSERT_TRUE(frontend_maintenance_fixture_start(&fixture, "idle-cadence"));
1653+
1654+
cbm_daemon_frontend_test_observer_reset(false);
1655+
cbm_daemon_maintenance_monitor_t *monitor = cbm_daemon_maintenance_monitor_start(
1656+
fixture.manager, NULL, NULL, EXIT_SUCCESS, "idle cadence test");
1657+
ASSERT_TRUE(monitor != NULL);
1658+
uint64_t deadline = cbm_now_ms() + 10000U;
1659+
while (cbm_now_ms() < deadline && cbm_daemon_frontend_test_monitor_idle_sleep_ms() == 0) {
1660+
cbm_usleep(1000);
1661+
}
1662+
uint32_t idle_sleep_ms = cbm_daemon_frontend_test_monitor_idle_sleep_ms();
1663+
ASSERT_TRUE(cbm_daemon_maintenance_monitor_stop(&monitor));
1664+
frontend_maintenance_fixture_finish(&fixture);
1665+
1666+
ASSERT_TRUE(idle_sleep_ms != 0);
1667+
ASSERT_GTE(idle_sleep_ms, 250);
1668+
PASS();
1669+
}
16441670
#endif
16451671

16461672
#ifndef _WIN32
@@ -1982,6 +2008,7 @@ SUITE(daemon_frontend) {
19822008
RUN_TEST(daemon_frontend_rejects_non_notification_cancellation_shapes);
19832009
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
19842010
RUN_TEST(daemon_frontend_idle_uses_one_maintenance_observer);
2011+
RUN_TEST(daemon_frontend_idle_maintenance_probe_is_bounded);
19852012
#endif
19862013
#ifndef _WIN32
19872014
RUN_TEST(daemon_frontend_maintenance_exits_while_stdio_reader_is_blocked);

0 commit comments

Comments
 (0)