Skip to content

Commit 23d4833

Browse files
committed
test(watcher): poll-only-watched-projects waits for the watched reindex, not one poll
watcher_poll_only_watched_projects failed on the macOS LSan job of PR DeusData#2295, whose diff was Java-only, with `FAIL tests/test_watcher.c:2971: index_call_count == 0, expected 1` (8211 passed, 1 failed). The LSan report that followed points into the aborted test body (watcher and store never freed after the early FAIL): a consequence, not a separate leak. The assert expected ONE touch+poll after a dirty change to reindex exactly once. That needs every git probe of the poll to succeed. A poll whose git spawn is refused under runner load is a fail-closed no-op by design (DeusData#937: the baseline stays uncommitted and the next poll retries), and that path returns without a log line. This is the same test race that DeusData#2376 fixed in watcher_unwatch_drains_pending_free and watcher_sustained_failure_logs_once_issue2015, not a production defect. Holding one exhausted spawn with cbm_subprocess_force_spawn_eagain_for_testing at that poll reproduces the CI output exactly: watch, baseline, then `FAIL tests/test_watcher.c:2971: index_call_count == 0, expected 1 == 1`, with no watcher.changed and no watcher.git.failed. The old test was also partly inert. The Go original (TestPollAllOnlyWatched, from the DeusData#49 fix that replaced scan-all with an explicit watch list) registered BOTH projects in the store and asserted that the unwatched one gets no watcher state. The C port dropped the store registration, so nothing let the watcher learn about B, and the B half could not fail. The test now: - registers A and B in the store, and watches only A; - asserts that the baseline poll indexes nothing and does not adopt B; - makes both worktrees dirty (a dirty change, not a commit, so a late baseline still sees it); - polls until A's reindex has happened, asserting after EVERY poll that B has no watcher state (cbm_watcher_index_failure_count == -1), was never reindexed, and that the watch count is still 1; - asserts that A was reindexed exactly once. No timer or deadline decides the verdict. A watcher that never reindexes A hangs, which the runner reports as a failure, never a pass. Evidence (macOS arm64, ASan/UBSan test-runner, CBM_SANITIZED, so one exhausted spawn = 10 injected refusals), with temporary injection that has since been removed: - CI-shaped (baseline OK, first change poll refused): consumed=10 at loop poll 1, watcher.changed at loop poll 2, PASS. - Heavy (baseline poll plus loop polls 1-3 refused): loop poll 4 takes the baseline, poll 5 reindexes A; loop polls=5 watched=1 other=0, PASS. - Mutation, the pre-DeusData#49 scan-all (poll_once adopts every stored project): `FAIL tests/test_watcher.c:3001: cbm_watcher_index_failure_count(w, "projB-ow") == 0, expected -1 == -1`, both unforced and with the heavy refusals (A's and B's baseline spawns both refused). The other 82 watcher tests stay green under that mutation, so this is the only test guarding DeusData#49. Final tree: build/c/test-runner watcher, 5/5 runs, 83 passed each. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 1f9b4db commit 23d4833

1 file changed

Lines changed: 65 additions & 13 deletions

File tree

‎tests/test_watcher.c‎

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,10 +2905,41 @@ TEST(watcher_fallback_still_detects) {
29052905
PASS();
29062906
}
29072907

2908+
/* Reindex counts for watcher_poll_only_watched_projects, split by project:
2909+
* the watched one, and anything else. */
2910+
static int ow_watched_calls = 0;
2911+
static int ow_other_calls = 0;
2912+
static int ow_index_callback(const char *name, const char *path, void *ud) {
2913+
(void)path;
2914+
(void)ud;
2915+
if (name && strcmp(name, "projA-ow") == 0) {
2916+
ow_watched_calls++;
2917+
} else {
2918+
ow_other_calls++;
2919+
}
2920+
return 0;
2921+
}
2922+
29082923
TEST(watcher_poll_only_watched_projects) {
2909-
/* Port of TestPollAllOnlyWatched:
2910-
* Two repos exist, only one is watched → only the watched one
2911-
* gets polled and can trigger reindex. */
2924+
/* Port of TestPollAllOnlyWatched (#49: the watcher polls its explicit
2925+
* watch list, never every project the store knows). Two repos exist and
2926+
* BOTH are registered in the store, as in the Go original; only A is
2927+
* watched. Contract: B never gets watcher state and is never reindexed,
2928+
* and A's change is reindexed.
2929+
*
2930+
* No verdict depends on one git probe succeeding. The earlier version
2931+
* asserted that ONE poll after the change reindexed exactly once, and it
2932+
* never registered B anywhere the watcher could see, so its B half could
2933+
* not fail. A poll whose git probe fails transiently (spawn refused under
2934+
* runner load) is a fail-closed no-op by design (#937: the baseline stays
2935+
* uncommitted and the next poll retries), so that assert read
2936+
* `index_call_count == 0, expected 1` on a loaded macOS runner. Holding
2937+
* one exhausted spawn with cbm_subprocess_force_spawn_eagain_for_testing
2938+
* at that poll reproduces the CI line exactly. The test now polls until
2939+
* A's reindex has happened, and after every poll asserts the states that
2940+
* hold whatever git answers: B has no watcher state and no reindex. A
2941+
* watcher that never reindexes A hangs here, which the runner reports as
2942+
* a failure, never a pass. */
29122943
char tmpdirA[256];
29132944
snprintf(tmpdirA, sizeof(tmpdirA), "/tmp/cbm_watcher_owA_XXXXXX");
29142945
char tmpdirB[256];
@@ -2941,19 +2972,32 @@ TEST(watcher_poll_only_watched_projects) {
29412972
wt_git(tmpdirB, "add b.txt");
29422973
wt_git(tmpdirB, "commit -q -m init");
29432974

2975+
/* Both projects are known to the store. A watcher that polled stored
2976+
* projects instead of its watch list (the pre-#49 scan-all) adopts B. */
29442977
cbm_store_t *store = cbm_store_open_memory();
2945-
cbm_watcher_t *w = cbm_watcher_new(store, index_callback, NULL);
2978+
ASSERT_EQ(cbm_store_upsert_project(store, "projA-ow", tmpdirA), CBM_STORE_OK);
2979+
ASSERT_EQ(cbm_store_upsert_project(store, "projB-ow", tmpdirB), CBM_STORE_OK);
2980+
cbm_watcher_t *w = cbm_watcher_new(store, ow_index_callback, NULL);
29462981

29472982
/* Only watch A — B is NOT watched */
29482983
cbm_watcher_watch(w, "projA-ow", tmpdirA);
29492984
ASSERT_EQ(cbm_watcher_watch_count(w), 1);
2950-
index_call_count = 0;
2985+
ow_watched_calls = 0;
2986+
ow_other_calls = 0;
29512987

2952-
/* Baseline */
2953-
cbm_watcher_poll_once(w);
2954-
ASSERT_EQ(index_call_count, 0);
2988+
/* Baseline poll. Its git outcome is not asserted: if a probe fails here,
2989+
* a later poll takes the baseline instead. A baseline poll never indexes,
2990+
* whatever git answers, and it must not adopt B. */
2991+
ASSERT_EQ(cbm_watcher_poll_once(w), 0);
2992+
ASSERT_EQ(ow_watched_calls + ow_other_calls, 0);
2993+
ASSERT_EQ(cbm_watcher_index_failure_count(w, "projB-ow"), -1);
2994+
ASSERT_EQ(cbm_watcher_watch_count(w), 1);
29552995

2956-
/* Make BOTH repos dirty */
2996+
/* Make BOTH repos dirty. A dirty worktree, not a commit: the baseline
2997+
* keeps the dirty signature at "clean known", so A's change is seen
2998+
* whenever the baseline lands, even if the baseline poll above failed. A
2999+
* commit made before a late baseline would be adopted as the baseline
3000+
* HEAD and never reindexed. */
29573001
{
29583002
char _p[1024];
29593003
snprintf(_p, sizeof(_p), "%s/a.txt", tmpdirA);
@@ -2965,10 +3009,18 @@ TEST(watcher_poll_only_watched_projects) {
29653009
th_append_file(_p, "dirty\n");
29663010
}
29673011

2968-
/* Poll — only A should trigger (B is not watched) */
2969-
cbm_watcher_touch(w, "projA-ow");
2970-
cbm_watcher_poll_once(w);
2971-
ASSERT_EQ(index_call_count, 1);
3012+
/* Poll until A's reindex. touch clears the adaptive interval so every
3013+
* poll checks A; each poll runs at most one attempt for A, so the loop
3014+
* stops at exactly one. After EVERY poll, B has no watcher state and no
3015+
* reindex, whether or not that poll's git probes succeeded. */
3016+
while (ow_watched_calls == 0) {
3017+
cbm_watcher_touch(w, "projA-ow");
3018+
cbm_watcher_poll_once(w);
3019+
ASSERT_EQ(ow_other_calls, 0);
3020+
ASSERT_EQ(cbm_watcher_index_failure_count(w, "projB-ow"), -1);
3021+
ASSERT_EQ(cbm_watcher_watch_count(w), 1);
3022+
}
3023+
ASSERT_EQ(ow_watched_calls, 1);
29723024

29733025
cbm_watcher_free(w);
29743026
cbm_store_close(store);

0 commit comments

Comments
 (0)