Skip to content

Commit a1b7c05

Browse files
committed
test(spill): make spill test verdicts independent of host free disk
extraction::extract_spill_round_trip_keeps_every_field and parallel::parallel_spill_mode_builds_the_same_graph failed on any machine with less than 10 GB free: cbm_result_spill_open refuses to spill onto a nearly full disk (mem.spill.refused reason=low_disk), so the store never opened. Three pipeline tests took the same refused-store path there and passed without spilling at all (backpressure_futile_nap_disengages, over_budget_after_futility_fails_whole_and_preserves_db, spill_resolves_namespace_imports_like_memory). A verdict must be a pure function of code, test, platform and seed, not of how full the disk is. Add a free-space pin to result_spill that exists only in test-seam builds (CBM_ENABLE_TEST_SEAMS). Production still asks the disk, and its 10 GB floor and half-of-free cap are unchanged. The test runner pins 64 GiB at the top of main, before worker re-exec dispatch, so every suite and re-exec'd index worker sees the same disk. A new test, extraction::extract_spill_refuses_below_the_free_disk_floor, pins the guard itself: one byte under the floor refuses, the floor opens. Verified with cbm_fs_free_bytes temporarily forced to 9 GB: both tests RED 3/3 before, green 3/3 after, RED again with the runner pin removed; the refusal test goes RED with the production guard disabled. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 9d65f4c commit a1b7c05

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

‎internal/cbm/result_spill.c‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,31 @@ struct cbm_result_spill {
106106
* target to race against, and a failed write stays handled underneath. */
107107
enum { SPILL_FREE_FLOOR_GB = 10, SPILL_FREE_SHARE_DIV = 2 };
108108

109+
#ifdef CBM_ENABLE_TEST_SEAMS
110+
/* Set by the test's main thread before any worker exists; atomic so a reading
111+
* worker and a restoring test can never race under TSan. */
112+
static _Atomic size_t g_free_bytes_pin;
113+
114+
size_t cbm_result_spill_pin_free_bytes_for_tests(size_t bytes) {
115+
return atomic_exchange_explicit(&g_free_bytes_pin, bytes, memory_order_relaxed);
116+
}
117+
118+
size_t cbm_result_spill_free_floor_bytes_for_tests(void) {
119+
return (size_t)SPILL_FREE_FLOOR_GB * 1024 * 1024 * 1024;
120+
}
121+
#endif
122+
123+
/* Free space under the spill directory. Production always asks the disk. */
124+
static size_t spill_free_bytes(const char *spill_dir) {
125+
#ifdef CBM_ENABLE_TEST_SEAMS
126+
size_t pinned = atomic_load_explicit(&g_free_bytes_pin, memory_order_relaxed);
127+
if (pinned > 0) {
128+
return pinned;
129+
}
130+
#endif
131+
return cbm_fs_free_bytes(spill_dir);
132+
}
133+
109134
/* Remove spill files left by runs that are no longer here. Only files this
110135
* module names (spill-<pid>-<writer>.bin) are touched, and on Windows an open
111136
* file refuses deletion, which is exactly the liveness check we want: a running
@@ -164,7 +189,7 @@ cbm_result_spill_t *cbm_result_spill_open(const char *dir, int writers, int slot
164189
* caller in the memory path it was already in (back-pressure, then its own
165190
* budget decision) — the same outcome as a disk that fills mid-run, minus
166191
* the filled disk. */
167-
size_t free_bytes = cbm_fs_free_bytes(spill_dir);
192+
size_t free_bytes = spill_free_bytes(spill_dir);
168193
int64_t byte_cap = 0;
169194
if (free_bytes > 0) {
170195
size_t floor_bytes = (size_t)SPILL_FREE_FLOOR_GB * 1024 * 1024 * 1024;

‎internal/cbm/result_spill.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,15 @@ void cbm_result_spill_close(cbm_result_spill_t *sp);
7070
* `new_base`. Exposed for tests. */
7171
void cbm_result_relocate(CBMFileResult *result, const char *old_base, size_t len, char *new_base);
7272

73+
#ifdef CBM_ENABLE_TEST_SEAMS
74+
/* Test builds only: open's free-space reading (and so its low-disk refusal and
75+
* its disk-share cap) answers `bytes` instead of asking the disk; 0 asks the
76+
* disk again. Returns the previous pin. A test's verdict must not depend on how
77+
* full the machine's disk happens to be, so the test runner pins ample space
78+
* for the whole process and the refusal test pins a low value on purpose. */
79+
size_t cbm_result_spill_pin_free_bytes_for_tests(size_t bytes);
80+
/* The production floor: below this much free space, open refuses. */
81+
size_t cbm_result_spill_free_floor_bytes_for_tests(void);
82+
#endif
83+
7384
#endif /* CBM_RESULT_SPILL_H */

‎tests/test_extraction.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8329,6 +8329,37 @@ TEST(extract_spill_round_trip_keeps_every_field) {
83298329
PASS();
83308330
}
83318331

8332+
/* The low-disk guard, pinned through the free-space seam rather than the host
8333+
* disk: one byte under the floor refuses (spilling onto a nearly full disk is
8334+
* a worse failure than the memory pressure it relieves), the floor itself
8335+
* opens. The runner pins ample space everywhere else; restored before asserts. */
8336+
TEST(extract_spill_refuses_below_the_free_disk_floor) {
8337+
char dir[512];
8338+
snprintf(dir, sizeof(dir), "%s/cbm_spill_XXXXXX", cbm_tmpdir());
8339+
ASSERT_NOT_NULL(cbm_mkdtemp(dir));
8340+
8341+
size_t floor_bytes = cbm_result_spill_free_floor_bytes_for_tests();
8342+
size_t saved = cbm_result_spill_pin_free_bytes_for_tests(floor_bytes - 1);
8343+
cbm_result_spill_t *below = cbm_result_spill_open(dir, 1, 1);
8344+
(void)cbm_result_spill_pin_free_bytes_for_tests(floor_bytes);
8345+
cbm_result_spill_t *at = cbm_result_spill_open(dir, 1, 1);
8346+
(void)cbm_result_spill_pin_free_bytes_for_tests(saved);
8347+
8348+
bool refused = below == NULL;
8349+
bool opened = at != NULL;
8350+
cbm_result_spill_close(below);
8351+
cbm_result_spill_close(at);
8352+
char spill_sub[600];
8353+
snprintf(spill_sub, sizeof(spill_sub), "%s/spill", dir);
8354+
cbm_rmdir(spill_sub);
8355+
cbm_rmdir(dir);
8356+
8357+
ASSERT_EQ(floor_bytes, (size_t)10 * 1024 * 1024 * 1024);
8358+
ASSERT_TRUE(refused);
8359+
ASSERT_TRUE(opened);
8360+
PASS();
8361+
}
8362+
83328363
/* ── A skipped file gets no LSP walk, per-file or cross-file ── */
83338364

83348365
/* CBM_TEST_LSP_SKIP_ON names the file: the result carries lsp_skipped, the
@@ -8388,6 +8419,7 @@ SUITE(extraction) {
83888419
RUN_TEST(extract_compact_keeps_every_field_and_shrinks_the_arena);
83898420
RUN_TEST(extract_compact_is_idempotent_and_survives_empty_results);
83908421
RUN_TEST(extract_spill_round_trip_keeps_every_field);
8422+
RUN_TEST(extract_spill_refuses_below_the_free_disk_floor);
83918423
RUN_TEST(extract_lsp_skipped_file_gets_no_walk);
83928424
RUN_TEST(extract_walk_truncated_when_a_node_budget_is_set);
83938425
/* Initialize extraction library */

‎tests/test_main.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ int tf_skip_count = 0;
2424
#include "mcp/index_supervisor.h" /* cbm_index_set_worker_role */
2525
#include "mcp/mcp.h" /* cbm_mcp_handle_tool — act as a real worker */
2626
#include "ui/http_server.h" /* deleted-self executable probe */
27+
#include "result_spill.h" /* pinned free disk: spill verdicts ignore the host disk */
2728
#include <sqlite3.h>
2829
#include <errno.h>
2930
#include <stdbool.h>
@@ -957,6 +958,14 @@ int main(int argc, char **argv) {
957958
(void)printf("sanitized=%d test_seams=%d\n", sanitized, test_seams);
958959
return 0;
959960
}
961+
/* A test's verdict is a pure function of code, test, platform and seed --
962+
* never of how full this machine's disk is. The spill store refuses to open
963+
* below 10 GB free, so without this pin every spill test failed, and every
964+
* budget-driven pipeline test silently took the no-store path, on a host
965+
* with less free space. Pin ample space for this process and every worker
966+
* it re-execs; the refusal itself is pinned on purpose by
967+
* extraction::extract_spill_refuses_below_the_free_disk_floor. */
968+
(void)cbm_result_spill_pin_free_bytes_for_tests((size_t)64 * 1024 * 1024 * 1024);
960969
/* Skip the multi-hundred-MB executable-image hash that computes the exact
961970
* build fingerprint: it is tens of seconds per spawned worker/daemon under
962971
* ASan on constrained CI runners and the sole cause of the daemon-family

0 commit comments

Comments
 (0)