Skip to content

Commit 767ac37

Browse files
committed
test(index): pin the duration clock in the quiet-timeout watchdog test
index_supervisor_quiet_timeout_remains_hang_with_duration_enabled ran the duration watchdog on the real clock with a 60 s limit next to a 1 s quiet timeout. On a starved host the duration limit can be crossed before the quiet timeout fires, and the verdict then turns from HANG into a resource kill, so the test depended on how fast the machine was. The resource clock is now pinned at the request origin through the existing clock seam. The quiet timeout runs on the subprocess clock, so it is the only way the hung worker can end, however slowly the host runs. The limit is set equal to the quiet timeout on purpose: more real time than the limit always passes and it still cannot fire. A new assertion checks that the duration check read the pinned clock, so HANG wins against an armed watchdog. RED (real clock, limit crossed first): FAIL ASSERT(remained_hang) with index.supervisor.resource_limit resource=duration_ms. GREEN with the pin. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 1e4751d commit 767ac37

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎tests/test_index_supervisor.c‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,11 +1230,22 @@ TEST(index_supervisor_quiet_timeout_remains_hang_with_duration_enabled) {
12301230
const char *saved_timeout = getenv("CBM_INDEX_WORKER_TIMEOUT_S");
12311231
char *saved_timeout_copy = saved_timeout ? cbm_strdup(saved_timeout) : NULL;
12321232
(void)cbm_setenv("CBM_INDEX_WORKER_TIMEOUT_S", "1", 1);
1233-
cbm_index_supervisor_reset_resource_hooks_for_testing();
1234-
cbm_index_resource_policy_t policy = index_supervisor_test_worker_policy(0, 60000);
1233+
/* The duration watchdog stays armed, but its clock is pinned at the request
1234+
* origin, so the quiet timeout (the subprocess's own clock) is the only way
1235+
* this hung worker can end, however slowly the host runs. With the real
1236+
* clock a starved run could cross the duration limit first and turn the
1237+
* HANG into a resource kill. The limit equals the quiet timeout on purpose:
1238+
* more real time than the limit always passes, and it still cannot fire. */
1239+
index_supervisor_resource_fake_t fake = {
1240+
.now_ms = 100,
1241+
.rss_status = CBM_PROC_TREE_RSS_EMPTY,
1242+
};
1243+
cbm_index_supervisor_set_resource_hooks_for_testing(index_supervisor_fake_clock,
1244+
index_supervisor_fake_charged_rss, &fake);
1245+
cbm_index_resource_policy_t policy = index_supervisor_test_worker_policy(0, 1000);
12351246
cbm_index_worker_handle_t *handle = NULL;
12361247
int start_rc = cbm_index_worker_start_with_policy("{\"__cbm_test_worker\":\"hang-tree\"}", 0,
1237-
&policy, false, NULL, NULL, 0, &handle);
1248+
&policy, false, NULL, NULL, 100, &handle);
12381249
const cbm_index_worker_result_t *result = NULL;
12391250
bool terminal = handle && index_supervisor_test_poll_terminal(
12401251
handle, INDEX_SUPERVISOR_TEST_TERMINAL_MS, &result);
@@ -1246,11 +1257,15 @@ TEST(index_supervisor_quiet_timeout_remains_hang_with_duration_enabled) {
12461257
} else {
12471258
index_supervisor_test_cleanup_handle(handle);
12481259
}
1260+
cbm_index_supervisor_reset_resource_hooks_for_testing();
12491261
index_supervisor_test_restore_env("CBM_INDEX_WORKER_TIMEOUT_S", saved_timeout_copy);
12501262

12511263
ASSERT_EQ(start_rc, 0);
12521264
ASSERT_TRUE(terminal);
12531265
ASSERT_TRUE(remained_hang);
1266+
/* The duration check really ran while polling (it read the pinned clock),
1267+
* so HANG won against a live watchdog, not against a disabled one. */
1268+
ASSERT_TRUE(fake.clock_calls > 0);
12541269
PASS();
12551270
}
12561271

0 commit comments

Comments
 (0)