Skip to content

Commit 7ddf878

Browse files
authored
test: cover interrupted watch build trace events (#14802)
Add a standalone cram test for a watch build that is interrupted by a file change. The test checks the trace event ordering and run-id relationship: the build-restart event is emitted before the interrupted build-finish event, and the restarted build completes successfully. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
1 parent 8076d30 commit 7ddf878

2 files changed

Lines changed: 83 additions & 1 deletion

File tree

test/blackbox-tests/test-cases/trace/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(cram
2-
(applies_to watch-build-events debug-event)
2+
(applies_to watch-build-events debug-event interrupted-watch-build-events)
33
(enabled_if
44
(= %{system} linux)))
55

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Interrupted watch builds emit a restart event before the interrupted iteration's
2+
build-finish event.
3+
4+
$ make_dune_project 3.22
5+
6+
$ cat > x <<EOF
7+
> original
8+
> EOF
9+
10+
$ cat > build.sh <<'EOF'
11+
> if [ "$(cat "$1")" = unstable ]; then
12+
> touch "$3"
13+
> sleep 1000
14+
> exit 1
15+
> else
16+
> cat "$1" > "$2"
17+
> fi
18+
> EOF
19+
20+
Keep the synchronization marker outside the workspace so it does not enqueue its
21+
own source invalidation.
22+
23+
$ marker="$TMPDIR/go-ahead"
24+
$ cat > dune <<EOF
25+
> (rule
26+
> (target y)
27+
> (deps x build.sh)
28+
> (action (run bash %{dep:build.sh} %{dep:x} y "$marker")))
29+
> EOF
30+
31+
$ rm -f "$marker"
32+
$ start_dune @idle
33+
34+
$ build y
35+
Success
36+
$ cat _build/default/y
37+
original
38+
39+
$ echo unstable > x
40+
$ (dune_cmd wait-for-file-to-appear "$marker"; echo updated > x) & build y
41+
Success
42+
$ cat _build/default/y
43+
updated
44+
45+
$ stop_dune > /dev/null
46+
47+
$ dune trace cat | jq -s '
48+
> include "dune";
49+
> [ .[] | buildEvents | del(.args.rusage) ] | .[-4:]'
50+
[
51+
{
52+
"args": {
53+
"run_id": 2,
54+
"restart": true
55+
},
56+
"name": "build-start"
57+
},
58+
{
59+
"args": {
60+
"run_id": 3,
61+
"reasons": [
62+
"x changed"
63+
]
64+
},
65+
"name": "build-restart"
66+
},
67+
{
68+
"args": {
69+
"run_id": 3,
70+
"restart": true
71+
},
72+
"name": "build-start"
73+
},
74+
{
75+
"args": {
76+
"run_id": 3,
77+
"outcome": "success",
78+
"restart_duration": "number"
79+
},
80+
"name": "build-finish"
81+
}
82+
]

0 commit comments

Comments
 (0)