Skip to content

Commit 2df3504

Browse files
cknittclaude
andauthored
Fix flaky retained-parse watch test on Windows (#8902)
Windows can report one write as several change events, each rebuilding and re-reporting A. Wait for those rebuilds before counting, then poll for A's re-parse after the edit of B. Claude-Session: https://claude.ai/code/session_0193XhTJFgkaaGZTNw9Uqd5v Signed-off-by: Christoph Knittel <ck@cca.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b53635a commit 2df3504

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎rewatch-ocaml/tests/check_command_validation.sh‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,14 @@ for implementation in rust ocaml; do
15171517
fi
15181518
normalize_project_path "$work/quiet-watch-$implementation.err" \
15191519
"$work/quiet-watch-$implementation.err.norm" "$quiet_watch_project"
1520+
# macOS and Windows can report one write as several change events, and each
1521+
# rebuild reports the parse error again. Compare the distinct reports only.
1522+
node -e '
1523+
const fs = require("fs");
1524+
const blocks = fs.readFileSync(process.argv[1], "utf8").split(/^(?=Error in )/m);
1525+
const distinct = blocks.filter((block, i) => block !== blocks[i - 1]);
1526+
fs.writeFileSync(process.argv[1], distinct.join(""));
1527+
' "$work/quiet-watch-$implementation.err.norm"
15201528
done
15211529
if ! cmp -s "$work/quiet-watch-rust.err.norm" \
15221530
"$work/quiet-watch-ocaml.err.norm"; then

‎rewatch-ocaml/tests/run.sh‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,10 +1923,25 @@ background_pids="$background_pids $retained_parse_pid"
19231923
wait_for_initial_build "$retained_parse/watch.log"
19241924
printf 'let value =\n' >"$retained_parse/src/A.res"
19251925
wait_for_text "$retained_parse/watch.log" 'This let-binding misses an expression'
1926+
# Windows can report one write as several change events, and each one starts
1927+
# a rebuild that parses A and reports its error again. Wait until those
1928+
# rebuilds are over, so that the counts only grow from the edit of B.
19261929
failed_parses=$(grep -c '^parse.*A\.res' "$retained_parse/calls.log")
1930+
quiet_polls=0
1931+
while [ "$quiet_polls" -lt 10 ]; do
1932+
sleep 0.1
1933+
parses=$(grep -c '^parse.*A\.res' "$retained_parse/calls.log")
1934+
if [ "$parses" = "$failed_parses" ]; then
1935+
quiet_polls=$((quiet_polls + 1))
1936+
else
1937+
failed_parses=$parses
1938+
quiet_polls=0
1939+
fi
1940+
done
1941+
reported_errors=$(grep -c 'This let-binding misses an expression' "$retained_parse/watch.log")
19271942
printf 'let other = 2\n' >"$retained_parse/src/B.res"
1928-
wait_for_text "$retained_parse/watch.log" 'This let-binding misses an expression' 2
1929-
test "$(grep -c '^parse.*A\.res' "$retained_parse/calls.log")" -gt "$failed_parses"
1943+
wait_for_count "$retained_parse/calls.log" '^parse.*A\.res' $((failed_parses + 1))
1944+
wait_for_text "$retained_parse/watch.log" 'This let-binding misses an expression' $((reported_errors + 1))
19301945
grep 'value = 1' "$retained_parse/src/A.js" >/dev/null
19311946
printf 'let value = 2\n' >"$retained_parse/src/A.res"
19321947
wait_for_text "$retained_parse/src/A.js" 'value = 2'

0 commit comments

Comments
 (0)