mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
yesterday 400fb2694641b05e53217d3c742a6e49e3a254c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#!/usr/bin/env bash
#
# The contents of this file are subject to the terms of the Common Development and
# Distribution License (the License). You may not use this file except in compliance with the
# License.
#
# You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
# specific language governing permission and limitations under the License.
#
# When distributing Covered Software, include this CDDL Header Notice in each file and include
# the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
# Header, with the fields enclosed by brackets [] replaced by your own identifying
# information: "Portions copyright [year] [name of copyright owner]".
#
# Copyright 2026 3A Systems, LLC.
 
set -e -o pipefail
HERE=$(cd "$(dirname "$0")" && pwd)
OUT=$(mktemp -d)
trap 'rm -rf "$OUT"' EXIT
mkdir -p "$OUT/load"
if [ ! -f "$HERE/rolling-load.sh" ]; then
  echo 'rolling load support is missing' >&2
  exit 1
fi
. "$HERE/rolling-load.sh"
 
# Only a segment started after scale-out and checked successfully proves that the
# corresponding replica continued to take writes after the topology changed.
for scenario in before after failed; do
  (
    OUT="$OUT/post-$scenario"; mkdir -p "$OUT/load"
    unset ROLLING_END ROLLING_END_MS
    [ "$scenario" != after ] || touch "$OUT/load/post-start"
    [ "$scenario" != failed ] || touch "$OUT/load/post-start"
    start_clients() { [ "$scenario" != before ] || touch "$OUT/load/post-start"; touch "$OUT/load/stop"; }
    docker() { case $1 in wait|rm) : ;; logs) echo csv ;; inspect) echo '0 false' ;; exec) : ;; *) return 1 ;; esac; }
    check_client() { [ "$scenario" != failed ]; }
    if rolling_worker d0; then [ "$scenario" != failed ]; else [ "$scenario" = failed ]; fi
    if [ "$scenario" = after ]; then
      [ -e "$OUT/load/d0.post-verified" ] || { echo 'post-scale segment was not recorded' >&2; exit 1; }
    else
      [ ! -e "$OUT/load/d0.post-verified" ] || { echo 'pre-scale or failed segment counted as post-scale' >&2; exit 1; }
    fi
  )
done
(
  OUT="$OUT/post-completion"; mkdir -p "$OUT/load"; DS_NODES='d0 d1'
  touch "$OUT/load/d0.post-verified"
  if rolling_post_segments_complete; then echo 'missing post-scale writer accepted' >&2; exit 1; fi
  touch "$OUT/load/d1.post-verified"
  rolling_post_segments_complete || { echo 'verified post-scale writers rejected' >&2; exit 1; }
  touch "$OUT/load/deadline"
  if rolling_post_segments_complete; then echo 'post-scale completion after deadline accepted' >&2; exit 1; fi
  rm "$OUT/load/deadline"
  touch "$OUT/load/d0.done"
  if rolling_post_segments_complete; then echo 'stopped post-scale worker accepted' >&2; exit 1; fi
)
# The load ends after every post-scale segment, without waiting for the hard limit.
(
  OUT="$OUT/post-lifecycle"; mkdir -p "$OUT/load"; DS_NODES='d0 d1'
  DURATION=60 DISTURB_AT=0 STAT_INTERVAL=0
  fail() { echo "$*" >&2; return 1; }
  wait_until() { local end=$((SECONDS + $1)); shift 2; until "$@"; do [ "$SECONDS" -lt "$end" ] || return 1; command sleep 0.01; done; }
  rolling_worker() {
    while [ ! -e "$OUT/load/post-start" ]; do command sleep 0.01; done
    touch "$OUT/load/$1.post-verified"
    while [ ! -e "$OUT/load/stop" ]; do command sleep 0.01; done
  }
  disturb() { :; }
  rolling_run_load
  [ ! -e "$OUT/load/deadline" ] || { echo 'successful load waited for its deadline' >&2; exit 1; }
  [ -e "$OUT/load/d0.post-verified" ] && [ -e "$OUT/load/d1.post-verified" ] || exit 1
)
# A worker which exits before its post-scale segment aborts the run.
if (
  OUT="$OUT/post-stopped"; mkdir -p "$OUT/load"; DS_NODES=d0
  DURATION=60 DISTURB_AT=0 STAT_INTERVAL=0
  fail() { return 1; }
  wait_until() { local end=$((SECONDS + $1)); shift 2; until "$@"; do [ "$SECONDS" -lt "$end" ] || return 1; command sleep 0.01; done; }
  rolling_worker() { :; }
  disturb() { command sleep 0.1; }
  rolling_run_load
) >/dev/null 2>&1; then
  echo 'a stopped worker passed the post-scale check' >&2; exit 1
fi
 
# The scale deadline must fit the per-DS index budget with the default segment size.
(
  DURATION=2700; unset ROLLING_SEGMENT
  . "$HERE/rolling-load.sh"
  [ "$ROLLING_SEGMENT" -eq 50 ] && rolling_index_budget || { echo '2700-second load exceeds the index budget' >&2; exit 1; }
)
 
# Three shards permit 50-second segments for a one-hour load.
(
  DURATION=3600; unset ROLLING_SEGMENT
  . "$HERE/rolling-load.sh"
  [ "$ROLLING_SEGMENT" -eq 50 ] && rolling_index_budget || { echo 'one-hour load exceeds the index budget' >&2; exit 1; }
  ROLLING_SEGMENT=20; . "$HERE/rolling-load.sh"
  [ "$ROLLING_SEGMENT" -eq 20 ] || { echo 'explicit segment override changed' >&2; exit 1; }
  if rolling_index_budget; then echo 'unsafe one-hour index budget accepted' >&2; exit 1; fi
)
 
# The sampler runs in a subshell: it must inherit the deadline before it is started.
(
  DURATION=60; unset ROLLING_END ROLLING_END_MS SCALE_DEADLINE_ACTIVE
  prepare_rolling_deadline
  ( [ "$SCALE_DEADLINE_ACTIVE" = 1 ] && [ "$ROLLING_END_MS" -gt 0 ] ) || { echo 'sampler cannot inherit deadline' >&2; exit 1; }
)
 
# Docker reports the process exit in nanoseconds: a client ending beyond the wall-clock
# deadline is an error even when its own --maxDuration was within it.
finished_before_deadline '1970-01-01T00:00:10.000000000Z' 10000 || exit 1
if finished_before_deadline '1970-01-01T00:00:10.000000001Z' 10000; then
  echo 'late client was accepted' >&2; exit 1
fi
if finished_before_deadline invalid 10000; then
  echo 'invalid client finish time was accepted' >&2; exit 1
fi
 
# A segment has two clients; a pause may stop the node only once both have ended. The
# other node must continue to write while this node is paused.
start_clients() { printf 'start %s %s\n' "$1" "$2" >>"$OUT/events"; }
docker() {
  case $1 in
    wait) sleep 0.1 ;;
    logs) echo 'csv' ;;
    inspect) echo '0 false' ;;
    rm) : ;;
    *) return 1 ;;
  esac
}
check_client() { printf 'checked %s\n' "$1" >>"$OUT/events"; }
fail() { echo "$*" >&2; return 1; }
wait_until() {
  local deadline=$((SECONDS + $1)); shift 2
  until "$@"; do [ "$SECONDS" -lt "$deadline" ] || return 1; sleep 0.1; done
}
ROLLING_SEGMENT=1 STAT_INTERVAL=0
rolling_worker d0 & a=$!
rolling_worker d1 & b=$!
sleep 0.2
rolling_pause d0
before=$(grep -c '^start d1 ' "$OUT/events")
sleep 0.4
after=$(grep -c '^start d1 ' "$OUT/events")
[ "$after" -gt "$before" ] || { echo 'other node stopped writing' >&2; exit 1; }
count=$(grep -c '^start d0 ' "$OUT/events")
sleep 0.3
[ "$(grep -c '^start d0 ' "$OUT/events")" -eq "$count" ] || { echo 'paused node started another segment' >&2; exit 1; }
rolling_resume d0
resumed() { [ "$(grep -c '^start d0 ' "$OUT/events")" -gt "$count" ]; }
wait_until 3 'node resumes' resumed || { echo 'node did not resume' >&2; exit 1; }
touch "$OUT/load/stop"
wait "$a"
wait "$b"
[ "$(grep -c '^checked ' "$OUT/events")" -eq "$((2 * $(grep -c '^start ' "$OUT/events")))" ] || { echo 'not all clients checked' >&2; exit 1; }
# A failed worker must wake a pause immediately instead of consuming the disturbance timeout.
(
  mkdir -p "$OUT/failed-pause/load"; OUT="$OUT/failed-pause"; DISTURB_TIMEOUT=1; unset ROLLING_END
  touch "$OUT/load/d0.failed"
  start=$SECONDS
  if rolling_pause d0 2>"$OUT/error"; then echo 'failed worker accepted as parked' >&2; exit 1; fi
  grep -F "worker d0 failed" "$OUT/error" >/dev/null || { echo 'pause did not report the worker failure' >&2; exit 1; }
)
# Even if the first client failed, collect and check the second before exiting.
(
  mkdir -p "$OUT/failed-pair/load"; OUT="$OUT/failed-pair"; unset ROLLING_END ROLLING_END_MS
  start_clients() { :; }
  docker() { case $1 in wait|rm) : ;; logs) echo csv ;; inspect) echo '0 false' ;; exec) echo 'LDAP result=53 fixture' ;; *) return 1 ;; esac; }
  check_client() {
    echo "$1" >>"$OUT/checked"
    if [ "$1" = load-add-d0 ]; then
      [ -e "$OUT/load/d0.failed" ] || { echo 'worker failure not signalled before collecting pair' >&2; return 1; }
      return 0
    fi
    return 1
  }
  if rolling_worker d0; then echo 'client failure was accepted' >&2; exit 1; fi
  grep -Fx load-add-d0 "$OUT/checked" >/dev/null || { echo 'paired client was not checked' >&2; exit 1; }
  [ -f "$OUT/load/load-add-d0.csv" ] || { echo 'paired client output was not collected' >&2; exit 1; }
  [ -e "$OUT/load/d0.failed" ] || { echo 'worker failure was not signalled' >&2; exit 1; }
  grep -F 'LDAP result=53 fixture' "$OUT/load/d0.recent-errors.log" >/dev/null || { echo 'directory server errors were not collected' >&2; exit 1; }
)
# A checkpoint writer must have two running load clients, not just a stale marker.
(
  mkdir -p "$OUT/active/load"; OUT="$OUT/active"
  docker() { [ "$1" = inspect ] || return 1; [ "$4" != "${STOPPED_CLIENT:-}" ] && echo true || echo false; }
  if rolling_clients_running d0; then echo 'missing load clients were accepted' >&2; exit 1; fi
  printf 'load-mod-d0 load-add-d0\n' >"$OUT/load/d0.active"
  rolling_clients_running d0 || { echo 'running load clients rejected' >&2; exit 1; }
  STOPPED_CLIENT=load-add-d0
  if rolling_clients_running d0; then echo 'stopped load client was accepted' >&2; exit 1; fi
)
# Scale load must produce a meaningful fraction of both requested rates.
(
  . "$HERE/load.sh"
  mkdir -p "$OUT/min-rate/load"; OUT="$OUT/min-rate"
  DISTURBANCE=scale-kept LOAD_MOD_RATE=100 LOAD_ADD_RATE=20 STAT_INTERVAL=10
  echo '0 false' >"$OUT/load/load-mod-d0.exit"; echo 30 >"$OUT/load/load-mod-d0.seconds"
  printf 'Time (seconds),Recent throughput (ops/second),Errors/second\n10,1,0\n20,1,0\n30,1,0\n' >"$OUT/load/load-mod-d0.csv"
  if check_client load-mod-d0 >/dev/null 2>&1; then echo 'almost idle scale writer accepted' >&2; exit 1; fi
  sed 's/,1,0$/,10,0/' "$OUT/load/load-mod-d0.csv" >"$OUT/rate.csv"
  cp "$OUT/rate.csv" "$OUT/load/load-mod-d0.csv"
  check_client load-mod-d0 >/dev/null || { echo 'minimum scale rate rejected' >&2; exit 1; }
)
# A final 18 ms statistics row has its real duration, not the weight of a 10 s interval.
(
  . "$HERE/load.sh"
  mkdir -p "$OUT/weighted-rate/load"; OUT="$OUT/weighted-rate"
  DISTURBANCE=scale-rs-empty LOAD_MOD_RATE=100 LOAD_ADD_RATE=20 STAT_INTERVAL=10
  echo '0 false' >"$OUT/load/load-add-d3.exit"; echo 50 >"$OUT/load/load-add-d3.seconds"
  cat >"$OUT/load/load-add-d3.csv" <<'CSV'
Time (seconds),Recent throughput (ops/second),Errors/second
10.002,1.1,0
20.001,2.2,0
30.001,2.7,0
40.001,2.4,0
50.001,2.6,0
50.019,0.0,0
CSV
  check_client load-add-d3 >/dev/null || { echo 'short final interval reduced the true average' >&2; exit 1; }
  sed 's/50.019,0.0,0/50.019,0.0,1/' "$OUT/load/load-add-d3.csv" >"$OUT/with-error.csv"
  cp "$OUT/with-error.csv" "$OUT/load/load-add-d3.csv"
  if check_client load-add-d3 >/dev/null 2>&1; then echo 'an error in the short interval was ignored' >&2; exit 1; fi
  sed 's/50.019,0.0,1/50.001,0.0,0/' "$OUT/with-error.csv" >"$OUT/load/load-add-d3.csv"
  check_client load-add-d3 >/dev/null || { echo 'zero-length final interval was rejected' >&2; exit 1; }
  sed 's/50.019,0.0,1/49.999,0.0,0/' "$OUT/with-error.csv" >"$OUT/load/load-add-d3.csv"
  if check_client load-add-d3 >/dev/null 2>&1; then echo 'a decreasing interval time was accepted' >&2; exit 1; fi
  cat >"$OUT/load/load-add-d3.csv" <<'CSV'
Time (seconds),Recent throughput (ops/second),Errors/second
10,1.0,0
20,1.0,0
30,1.0,0
40,1.0,0
50,1.0,0
50.018,100.0,0
CSV
  if check_client load-add-d3 >/dev/null 2>&1; then echo 'short final spike hid a low average' >&2; exit 1; fi
)
# The last client must leave time for JVM startup and teardown before the deadline.
(
  mkdir -p "$OUT/final/load"; OUT="$OUT/final"; ROLLING_END=$((SECONDS + 80)); unset ROLLING_END_MS
  ROLLING_SEGMENT=120; STAT_INTERVAL=10
  start_clients() { echo "$3" >"$OUT/length"; touch "$OUT/load/stop"; }
  rolling_worker d0
  [ "$(cat "$OUT/length")" -le 40 ] || { echo 'last segment left less than 40 seconds for startup and teardown' >&2; exit 1; }
)
# Pausing a node cannot wait beyond the overall load deadline.
(
  ROLLING_END=$((SECONDS + 3)); DISTURB_TIMEOUT=900
  wait_until() { [ "$1" -le 3 ] && [ "$1" -gt 0 ]; }
  rolling_pause deadline-node || { echo 'pause exceeded the load deadline' >&2; exit 1; }
)
# Forty-second segments must preserve indexed searches for every per-DS AddRate shard.
(
  . "$HERE/load.sh"
  OUT="$OUT/shards"; mkdir -p "$OUT/load"
  BASE_DN=dc=example,dc=com SAMPLE_DATA=100 LOAD_MOD_RATE=10 LOAD_ADD_RATE=1 ROOT_PASSWORD=x
  DISTURBANCE=scale-rs-kept
  start_client() { printf '%s\n' "$*" >>"$OUT/commands"; }
  start_clients d0 1 40
  start_clients d0 2 40
  start_clients d0 3 40
  start_clients d0 4 40
  start_clients d1 2 40
  grep -E '^load-add-d0 addrate .* --noPurge ' "$OUT/commands" >/dev/null || { echo 'scale addrate still purges at the end of each segment' >&2; exit 1; }
  grep -Fx 'sn: AddRate-d0-1' "$OUT/load/addrate-d0.template" >/dev/null || exit 1
  grep -Fx 'sn: AddRate-d0-2' "$OUT/load/addrate-d0-2.template" >/dev/null || exit 1
  grep -Fx 'sn: AddRate-d0-3' "$OUT/load/addrate-d0-3.template" >/dev/null || exit 1
  grep -Fx 'sn: AddRate-d0-1' "$OUT/load/addrate-d0-4.template" >/dev/null || exit 1
  grep -Fx 'sn: AddRate-d1-2' "$OUT/load/addrate-d1-2.template" >/dev/null || exit 1
  DS_NODES='d0 d1 d2 d3'; . "$HERE/assert-converged.sh"
  for n in $DS_NODES; do for shard in 1 2 3; do case " $INDEXED_FILTERS " in *" (sn=AddRate-$n-$shard) "*) : ;; *) echo "index shard $n-$shard is not checked" >&2; exit 1 ;; esac; done; done
  ROLLING_SEGMENT=40 DURATION=900
  rolling_index_budget || { echo 'safe per-DS segment budget rejected' >&2; exit 1; }
  ROLLING_SEGMENT=20 DURATION=3600
  if rolling_index_budget; then echo 'unsafe per-DS index budget accepted' >&2; exit 1; fi
  DISTURBANCE=restart-ds
  start_clients d2 1 40
  grep -Fx 'sn: AddRate' "$OUT/load/addrate-d2.template" >/dev/null || { echo 'ordinary AddRate surname changed' >&2; exit 1; }
  if grep -E '^load-add-d2 addrate .* --noPurge ' "$OUT/commands" >/dev/null; then echo 'ordinary AddRate purge changed' >&2; exit 1; fi
  . "$HERE/assert-converged.sh"
  [ "$INDEXED_FILTERS" = '(sn=AddRate) (sn=Diverged)' ] || { echo 'ordinary index filters changed' >&2; exit 1; }
)
# Too many segments leave enough AddRate entries to exceed the sn index limit.
if (mkdir -p "$OUT/index-limit/load"; OUT="$OUT/index-limit"; DS_NODES='d0 d1 d2 d3'
    ROLLING_SEGMENT=20; DURATION=3600; DISTURB_AT=1; STAT_INTERVAL=0
    rolling_worker() { :; }; disturb() { :; }; sleep() { :; }
    rolling_run_load) >/dev/null 2>&1; then
  echo 'rolling load accepted enough retained entries to exceed the sn index limit' >&2; exit 1
fi
# A worker cannot launch new clients after the watchdog has set the deadline marker.
(
  . "$HERE/load.sh"
  OUT="$OUT/deadline"; mkdir -p "$OUT/load"; touch "$OUT/load/deadline"
  BASE_DN=dc=example,dc=com SAMPLE_DATA=100 LOAD_MOD_RATE=10 LOAD_ADD_RATE=1 ROOT_PASSWORD=x
  start_client() { echo launched >>"$OUT/launched"; }
  if start_clients d0 1 60; then echo 'clients launched after deadline' >&2; exit 1; fi
  [ ! -e "$OUT/launched" ] || { echo 'deadline allowed a client launch' >&2; exit 1; }
)
# A late Docker launch must not start work after the cutoff even if the host watchdog
# scanned before the container was created: the container enforces the deadline itself.
(
  . "$HERE/load.sh"
  OUT="$OUT/client-wrapper"; mkdir -p "$OUT/load"
  NETWORK=fixture IMAGE=fixture CLIENT_JAVA_ARGS=-Xmx128m ROLLING_END_MS=10000
  docker() { printf '%s\n' "$*" >"$OUT/command"; }
  start_client load-test modrate --hostname example
  grep -F -- '--entrypoint /bin/sh' "$OUT/command" >/dev/null || { echo 'missing in-container deadline guard' >&2; exit 1; }
  grep -F '/usr/bin/timeout' "$OUT/command" >/dev/null || { echo 'missing in-container cutoff' >&2; exit 1; }
)
# Drive the real watchdog with events instead of racing a one-second wall clock.
# It may fire only once the worker has published both active clients and the
# disturbance has released it. A separate bound prevents a broken test hanging.
test_deadline_sleep() {
  local limit=$((SECONDS + 10))
  [ "$1" -gt 0 ] && [ "$1" -le 60 ] || return 1
  while [ ! -s "$OUT/load/d0.active" ] || [ ! -e "$OUT/release-watchdog" ]; do
    [ "$SECONDS" -lt "$limit" ] || return 1
    command sleep 0.01
  done
}
# A disturbance that outlasts the load must fail and both clients must be killed.
if (mkdir -p "$OUT/slow/load"; OUT="$OUT/slow"; DS_NODES=d0; DURATION=60; DISTURB_AT=0
    sleep() { test_deadline_sleep "$@"; }
    rolling_worker() {
      echo 'load-mod-d0 load-add-d0' >"$OUT/load/d0.active"
      while [ ! -e "$OUT/load/stop" ]; do command sleep 0.01; done
    }
    docker() {
      case $1 in inspect) echo true ;; kill) echo "$2" >>"$OUT/killed" ;; *) return 1 ;; esac
    }
    disturb() {
      local limit=$((SECONDS + 10))
      touch "$OUT/release-watchdog"
      while [ ! -f "$OUT/killed" ] || [ "$(wc -l <"$OUT/killed")" -lt 2 ]; do
        [ "$SECONDS" -lt "$limit" ] || return 1
        command sleep 0.01
      done
      SECONDS=$ROLLING_END
    }
    rolling_run_load) 2>"$OUT/slow-error"; then
  echo 'disturbance outlasted the load but passed' >&2; exit 1
fi
[ -e "$OUT/slow/load/stop" ] || { echo 'workers were not stopped after a slow disturbance' >&2; exit 1; }
[ "$(wc -l <"$OUT/slow/killed")" -eq 2 ] || { echo 'active clients were not stopped at deadline' >&2; exit 1; }
# An early scenario failure must keep the watchdog alive until a blocked worker exits.
if (mkdir -p "$OUT/early/load"; OUT="$OUT/early"; DS_NODES=d0; DURATION=60; DISTURB_AT=0
    sleep() { test_deadline_sleep "$@"; }
    rolling_worker() {
      local limit=$((SECONDS + 10))
      echo 'load-mod-d0 load-add-d0' >"$OUT/load/d0.active"
      while [ ! -e "$OUT/killed" ]; do
        [ "$SECONDS" -lt "$limit" ] || return 1
        command sleep 0.01
      done
    }
    docker() { case $1 in inspect) echo true ;; kill) touch "$OUT/killed" ;; *) return 1 ;; esac; }
    disturb() { touch "$OUT/release-watchdog"; return 1; }
    rolling_run_load) 2>"$OUT/early-error"; then
  echo 'early disturbance failure was accepted' >&2; exit 1
fi
[ -e "$OUT/early/killed" ] || { echo 'watchdog stopped before its worker' >&2; exit 1; }
# A worker failure also aborts a pending checkpoint, without waiting for its timeout.
(
  . "$HERE/lib.sh"
  mkdir -p "$OUT/failed-checkpoint/load"; OUT="$OUT/failed-checkpoint"; SCALE_DEADLINE_ACTIVE=1
  touch "$OUT/load/d0.failed"
  if wait_until 2 'checkpoint' false >"$OUT/result" 2>&1; then echo 'failed worker accepted during checkpoint' >&2; exit 1; fi
  grep -F 'load worker failed' "$OUT/result" >/dev/null || { echo 'checkpoint hid worker failure' >&2; exit 1; }
  if wait_until 2 'ready checkpoint' true >"$OUT/result" 2>&1; then echo 'ready checkpoint hid failed worker' >&2; exit 1; fi
)
# A Docker error must not look like a completed bootstrap.
(
  . "$HERE/lib.sh"
  docker() { return "$DOCKER_RESULT"; }
  DOCKER_RESULT=124
  if bootstrap_ended example; then echo 'docker timeout accepted as a completed join' >&2; exit 1; fi
  DOCKER_RESULT=1
  if bootstrap_ended example; then echo 'running join accepted as complete' >&2; exit 1; fi
  DOCKER_RESULT=0
  bootstrap_ended example || { echo 'completed join rejected' >&2; exit 1; }
)
echo 'rolling load pause, resume and deadline passed'