Skip to content

test+ci: gate parallel ctest with serial retry, harden test framework - #1267

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1260
Oct 20, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1260

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1260

Summary

  • Gate wrapper (scripts/ctest-gate.ps1): runs ctest -j <procs> and, on failure, re-runs only the failed tests (ctest --rerun-failed -j1) serially once. A serial green emits a ::warning:: annotation listing the recovered tests and passes the gate; a test that also fails serially stays red, so real regressions still block. The x64 CI test step now invokes the gate (parallel + serial retry) instead of a bare serial ctest.
  • TempDir race (tests/framework/temp_dir.h): the old GetTempFileNameW + DeleteFileW + create_directory sequence left a window where a parallel worker could claim the same path — two tests shared/deleted each other's files, and a leftover file at that name made create_directory throw out of the before-hook → terminate → 0xc0000409. Replaced with atomic CreateDirectoryW on a wct-<pid>-<tick>-<counter> name, retrying on collision.
  • run_command (tests/framework/process_win32.cpp): stdout/stderr/stdin are now pumped on separate threads. Draining stdout fully before stderr let a child that filled the stderr pipe block forever → INFINITE wait → ctest timeout kill under parallel load. Also checks CreatePipe/CreateProcessW: a transient spawn failure previously left pi.hProcess = NULL, so WaitForSingleObject returned immediately and an uninitialized code was returned as a garbage exit status.
  • Pipeline::run (tests/framework/pipeline.cpp): stdin WriteFile moved to a thread — a child that never reads stdin used to block the write before the output-reader threads started, same deadlock class.
  • TEST runner (tests/framework/wctest.h): exceptions thrown by before/after hooks are now recorded as test failures instead of escaping to terminate() (the 0xc0000409 class). The per-test failure reset moved above the before-hooks so a hook-reported failure is no longer cleared; the test body is skipped when before-hooks failed (TempDir may be unset).

Test plan

  • Gate mechanics verified with a synthetic ctest project: transient failure recovered on serial retry → exit 0 + annotation; persistent failure → exit 1 ("real regression").
  • Parallel (-j 16) targeted runs against Debug build in this worktree, all green on first pass: ticket-named flake groups ls|mktemp|timeout|wc|which|cut|find|head|join|realpath (477 tests), wpm|integration|winuxcmd (131), pipe-heavy tput|cat|tee|sed|yes|tr incl. probe_stdin_leftover coverage (249).
  • CI: x64 workflow runs the gate; watch for ::warning:: annotations instead of fake reds.

I18N impact

None — no user-visible strings in src/ changed; test framework, CI, and script output are not part of the catalog.

Generated with Devin

…#1260)

Parallel ctest runs flake with 0xc0000409 fail-fast and
environment-sensitive assertion failures that all pass serially.

Gate wrapper (scripts/ctest-gate.ps1): run ctest in parallel, and on
failure re-run only the failed tests (ctest --rerun-failed) serially
once. A serial green is annotated and passes the gate; a test that also
fails serially stays red, so real regressions still block. The x64 CI
test step now runs through the gate in parallel.

Root-cause fixes in the test framework:

- TempDir: replace the GetTempFileNameW + DeleteFile + create_directory
  sequence with atomic CreateDirectoryW on a pid/tick/counter name. The
  old code left a window where a parallel worker could claim the same
  path, and a leftover file at that name made create_directory throw out
  of the before-hook, terminating the test process (0xc0000409).
- run_command: drain stdout/stderr and feed stdin on separate threads
  instead of serially - a child filling the stderr pipe blocked forever
  while the parent drained stdout first, hanging until the ctest
  timeout. Also check CreatePipe/CreateProcessW so a transient spawn
  failure returns exit -1 instead of waiting on a NULL handle and
  reporting an uninitialized exit code.
- Pipeline::run: feed stdin on a thread for the same reason - a blocked
  WriteFile used to prevent the reader threads from ever starting.
- TEST runner: catch exceptions thrown by before/after hooks and record
  them as test failures instead of letting them escape to terminate();
  move the per-test failure reset above the hooks so hook-reported
  failures are not cleared.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit c946ec6 into main Oct 20, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1260 branch October 21, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

并行 ctest 假红族:0xc0000409 fail-fast + 环境敏感断言,串行全绿——多轮构建实录,gate 包装或根因修

1 participant