From fe7b78f8710c03fcd51537f187dc24f753cdb2c4 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 3 Nov 2026 07:39:31 -0600 Subject: [PATCH 1/3] fix(id): name the hanging group in nixos-integration VM test (#1372) The whole cli_integration binary ran in one server.succeed() with --format=terse, so a hang produced only "timeout reached; test terminating..." with no test name or wait target. Run the suite as four named groups (fast_unit, serve, tag, harness_unit), each under its own timeout deadline and with the pretty libtest format. A hang now names the group and filters before the per-group deadline fires, and libtest names the individual tests still running after 60 s. A coverage check proves the filters partition every test in the binary before anything runs, so no test is dropped. A 3400 s suite budget keeps every failure below the 3600 s globalTimeout backstop. Coverage and the deadline failure path were verified against the locally built test binary; the full VM run is the remaining validation. --- pkgs/id/nix/tests/integration-test.nix | 152 +++++++++++++++++++++++-- 1 file changed, 145 insertions(+), 7 deletions(-) diff --git a/pkgs/id/nix/tests/integration-test.nix b/pkgs/id/nix/tests/integration-test.nix index 5e031dbc1e..f888cba0f3 100644 --- a/pkgs/id/nix/tests/integration-test.nix +++ b/pkgs/id/nix/tests/integration-test.nix @@ -10,6 +10,15 @@ # This is the ONLY way to run serve_tests in nix — they spawn `id serve` as a # subprocess and need to bind/listen on ports, which the nix build sandbox blocks. # +# Legibility: the suite used to run as one server.succeed() with --format=terse, +# so a hang produced only "timeout reached; test terminating..." with no test +# name or wait target (see #1372). It now runs as named groups, each under its +# own `timeout` deadline and with the pretty libtest format, so a hang names the +# group, the filters it was running, and (after 60 s) the individual tests that +# are still running, well inside globalTimeout. Group filters are verified to +# partition every test in the binary before any test runs, so coverage cannot +# silently shrink. +# # Usage: # pkgs.testers.runNixOSTest (import ./integration-test.nix { # inherit idPackage integrationTestRunner; @@ -30,14 +39,62 @@ # serially behind the two-worker harness (see #190), so 20 minutes still # terminated the suite before it completed in CI. Keep enough headroom for # the full suite while preserving per-process deadlines in the test binary. + # The testScript's own suite budget (3400 s) keeps every failure below this + # backstop, so a hang is always reported by a named group instead of the + # driver's global "timeout reached; test terminating...". globalTimeout = 3600; # 60 minutes for the full integration suite testScript = '' + import shlex + import time + ID_BIN = "${idPackage}/bin/id" TEST_BIN = "${integrationTestRunner}/bin/cli_integration_test" EXAMPLES_DIR = "${integrationTestRunner}/share/id-test/examples" APPS_DIR = "${integrationTestRunner}/share/id-test/apps" + # Named groups: (group name, libtest filter arguments, per-group deadline). + # Filters are substring matches, but the coverage check below proves that + # every test in the binary matches exactly one group. When a test module is + # added, update this table (the check fails with the missing names). + GROUPS = [ + ( + "fast_unit", + [ + "cli_tests::", + "put_get_tests::", + "list_tests::", + "find_search_tests::", + "id_tests::", + "peers_tests::", + "error_handling_tests::", + "show_view_tests::", + "peek_tests::", + "filter_flag_tests::", + "show_peek_subcommand_help::", + ], + 900, + ), + ("serve", ["serve_tests::"], 2200), + ("tag", ["tag_tests::"], 400), + ( + "harness_unit", + [ + "test_output_within_kills_a_hung_process", + "test_output_within_ends_when_a_grandchild_keeps_the_pipes", + "test_unix_stop_keeps_its_gate_and_its_allow", + "test_every_unsafe_block_is_allowed_on_its_function", + "test_streaming_child_dies_with_its_guard_even_when_the_test_panics", + ], + 300, + ), + ] + + # Total wall-clock budget for the groups, below globalTimeout (3600 s) so a + # hang always fails here (with the group name) rather than at globalTimeout. + # Leaves room for VM boot and the setup assertions above. + SUITE_BUDGET_SECONDS = 3400 + start_all() # Verify both binaries are accessible @@ -46,15 +103,96 @@ server.succeed(f"test -d {EXAMPLES_DIR}") server.succeed(f"test -d {APPS_DIR}") - # Run the full integration test suite (including serve_tests). - # ID_BINARY overrides the compile-time CARGO_BIN_EXE_id path so the - # test binary finds the nix-built id binary. - server.succeed( + # The per-group deadline and the legibility of a killed child depend on + # GNU timeout being present in the VM. + server.succeed("command -v timeout") + + # Prove the group filters partition the suite before running anything. + listed = server.succeed(f"{TEST_BIN} --list") + all_tests = sorted( + line.rsplit(": ", 1)[0] + for line in listed.splitlines() + if line.endswith(": test") + ) + if not all_tests: + raise AssertionError( + "[id-integration] --list returned no tests; cannot verify group coverage" + ) + + covered = [] + for name, filters, _deadline in GROUPS: + hits = [test for test in all_tests if any(f in test for f in filters)] + if not hits: + raise AssertionError( + f"[id-integration] group '{name}' matches no tests; update GROUPS" + ) + covered.append((name, hits)) + + overlap = sorted({t for _name, hits in covered for t in hits if hits.count(t) > 1}) + missing = sorted(set(all_tests) - {t for _name, hits in covered for t in hits}) + if overlap or missing: + raise AssertionError( + "[id-integration] group filters must partition the suite exactly; " + f"duplicated={overlap} uncovered={missing}" + ) + + print( + "[id-integration] " + f"{len(all_tests)} tests in {len(GROUPS)} named groups: " + + ", ".join(f"{name}={len(hits)}" for name, hits in covered), + flush=True, + ) + + env = ( f"ID_BINARY={ID_BIN} " f"ID_TEST_EXAMPLES_DIR={EXAMPLES_DIR} " - f"ID_TEST_APPS_DIR={APPS_DIR} " - f"{TEST_BIN} " - f"--test-threads=2 --nocapture --format=terse 2>&1" + f"ID_TEST_APPS_DIR={APPS_DIR}" ) + + suite_started = time.monotonic() + for name, filters, cap in GROUPS: + elapsed = int(time.monotonic() - suite_started) + remaining = SUITE_BUDGET_SECONDS - elapsed + if remaining < 60: + raise AssertionError( + f"[id-integration] suite budget of {SUITE_BUDGET_SECONDS}s " + f"exhausted after {elapsed}s, before group '{name}' " + f"(filters: {' '.join(filters)})" + ) + + deadline = min(cap, remaining) + filter_args = " ".join(shlex.quote(f) for f in filters) + print( + f"[id-integration] waiting on group '{name}' " + f"(filters: {filter_args}); per-group deadline {deadline}s, " + f"{remaining}s of suite budget left", + flush=True, + ) + + group_started = time.monotonic() + rc, output = server.execute( + f"{env} timeout --signal=TERM --kill-after=15 {deadline} " + f"{TEST_BIN} {filter_args} " + f"--test-threads=2 --nocapture --format=pretty 2>&1", + check_return=False, + ) + if rc != 0: + # The driver logs captured output for failed commands, but print the + # tail explicitly so the last started test and the deadline that + # fired survive in the test log even if the driver output is cut. + print( + "\n".join(output.splitlines()[-150:]), + flush=True, + ) + raise AssertionError( + f"[id-integration] group '{name}' failed or exceeded its " + f"{deadline}s deadline (rc={rc}); filters: {filter_args}" + ) + + print( + f"[id-integration] group '{name}' finished in " + f"{time.monotonic() - group_started:.1f}s", + flush=True, + ) ''; } From 3e64b8299c9858ee5cb831df220680f0b9cc3658 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 3 Nov 2026 08:26:07 -0600 Subject: [PATCH 2/3] fix(id): use succeed for group runs (execute(check_return=False) hides rc) --- pkgs/id/nix/tests/integration-test.nix | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/pkgs/id/nix/tests/integration-test.nix b/pkgs/id/nix/tests/integration-test.nix index f888cba0f3..2668733e7d 100644 --- a/pkgs/id/nix/tests/integration-test.nix +++ b/pkgs/id/nix/tests/integration-test.nix @@ -170,24 +170,20 @@ ) group_started = time.monotonic() - rc, output = server.execute( - f"{env} timeout --signal=TERM --kill-after=15 {deadline} " - f"{TEST_BIN} {filter_args} " - f"--test-threads=2 --nocapture --format=pretty 2>&1", - check_return=False, - ) - if rc != 0: - # The driver logs captured output for failed commands, but print the - # tail explicitly so the last started test and the deadline that - # fired survive in the test log even if the driver output is cut. - print( - "\n".join(output.splitlines()[-150:]), - flush=True, + try: + server.succeed( + f"{env} timeout --signal=TERM --kill-after=15 {deadline} " + f"{TEST_BIN} {filter_args} " + f"--test-threads=2 --nocapture --format=pretty 2>&1" ) + except Exception as exc: + # The driver logs the captured output (including the last started + # test and libtest's "has been running" warnings) before raising; + # re-raise with the group and its deadline so the failure is named. raise AssertionError( f"[id-integration] group '{name}' failed or exceeded its " - f"{deadline}s deadline (rc={rc}); filters: {filter_args}" - ) + f"{deadline}s deadline; filters: {filter_args}" + ) from exc print( f"[id-integration] group '{name}' finished in " From cc96cc4893bc7a2e6b0068367b0f2a57bf1761e0 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 3 Nov 2026 08:38:15 -0600 Subject: [PATCH 3/3] fix(id): run every group before failing, then name all failed groups --- pkgs/id/nix/tests/integration-test.nix | 28 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pkgs/id/nix/tests/integration-test.nix b/pkgs/id/nix/tests/integration-test.nix index 2668733e7d..2f421d7906 100644 --- a/pkgs/id/nix/tests/integration-test.nix +++ b/pkgs/id/nix/tests/integration-test.nix @@ -150,6 +150,7 @@ ) suite_started = time.monotonic() + failed_groups = [] for name, filters, cap in GROUPS: elapsed = int(time.monotonic() - suite_started) remaining = SUITE_BUDGET_SECONDS - elapsed @@ -176,15 +177,28 @@ f"{TEST_BIN} {filter_args} " f"--test-threads=2 --nocapture --format=pretty 2>&1" ) - except Exception as exc: - # The driver logs the captured output (including the last started - # test and libtest's "has been running" warnings) before raising; - # re-raise with the group and its deadline so the failure is named. - raise AssertionError( + except Exception: + # The driver has already logged the captured output, including the + # last started test and libtest's "has been running" warnings. + # Record the group, keep going so every group still runs, and fail + # with a summary naming all failed groups at the end. + failed_groups.append(name) + print( f"[id-integration] group '{name}' failed or exceeded its " - f"{deadline}s deadline; filters: {filter_args}" - ) from exc + f"{deadline}s deadline; filters: {filter_args}; continuing", + flush=True, + ) + else: + print( + f"[id-integration] group '{name}' finished in " + f"{time.monotonic() - group_started:.1f}s", + flush=True, + ) + if failed_groups: + raise AssertionError( + "[id-integration] failed groups: " + ", ".join(failed_groups) + ) print( f"[id-integration] group '{name}' finished in " f"{time.monotonic() - group_started:.1f}s",