Tests: a stress script for the races, DNS checks on a Windows-shaped host, and a table of the bugs each check guards (#641)

This commit is contained in:
Precious Okwu authored and GitHub committed 2026-11-20 19:32:04 +01:00
1 parent 92c8347621
commit fbc92e164d
9 files changed
+813 -4

No files matched your search

+14
View File
@@ -55,6 +55,20 @@ fails when a script names an image the list lacks. `tests/e2e.sh` ends with
`Docker Hub allowance used during the run (whole network): N`, which should
be 0; other machines on the same network count against it too.
Every bug fix adds a check that fails without the fix and passes with it (a
line in `tests/e2e.sh` or `tests/linux-host.sh`, a case in `tests/stress.sh`,
or a unit test), and names it in `tests/regressions.tsv` with the issue or
pull request and one line on what broke. A listed check that fails says
which bug it guards; `python3 tests/lib/check-regressions.py` fails when the
table names a check that is gone. `KIRI_TEST_ONLY='^udp-'` runs only the
`tests/e2e.sh` checks whose names match. `tests/stress.sh` runs the races
(starts beside `docker system df`, `rm -f` against `docker run --rm` and
against starts, a minute of churn) in two to five minutes;
`KIRI_STRESS_ROUNDS` and `KIRI_STRESS_SECONDS` make it longer. On a Linux
test host, `sudo KIRI_TEST_ALLOW_HOST_CHANGES=1 KIRI_ENGINE_RESTART='...'
tests/wsl-shape.sh` runs the DNS checks with the host shaped like WSL 2 (its
resolver an address of its own on `lo`) and puts the host back afterwards.
## Every feature ships on macOS, Windows and Linux together
- A feature comes in one pull request, for all three systems, built and
+36 -3
View File
@@ -5,6 +5,16 @@
# tests/e2e.sh # functional tests (DOCKER_CONTEXT=kiri-dev for another Kiri)
# SOAK=500 tests/e2e.sh # plus a leak soak of 500 container runs
# KIRI_TEST_STRICT=1 tests/e2e.sh # what the setup lacks fails, not skipped
# KIRI_TEST_ONLY='^udp-|^build-dns$' tests/e2e.sh # only the checks named
#
# KIRI_TEST_ONLY is an extended regular expression matched against each
# check's name: the others are neither run nor counted, but the lines that
# set up for them (containers, networks, files) still run, so a check picked
# alone sees what it would in a full run (so a check must not be what undoes
# a set-up line's change). Its summary says how many it left out.
#
# A failing check that guards a known bug (tests/regressions.tsv) prints a
# "guards: #N" line under its FAIL with what broke.
#
# Checks for another system's feature are skipped, as are those needing what
# this setup lacks; the summary counts them by reason (`only`, `needs` below).
@@ -78,6 +88,7 @@ t() {
FAIL=$((FAIL + 1))
FAILED+=("$name")
printf ' FAIL %s\n want: %s\n got: %s\n' "$name" "$want" "$(echo "$got" | head -5)"
kiri_guard "$name"
fi
}
@@ -94,13 +105,29 @@ code() {
FAIL=$((FAIL + 1))
FAILED+=("$name")
printf ' FAIL %s: exit %s, want %s\n' "$name" "$got" "$want"
kiri_guard "$name"
fi
}
# selected NAME: whether KIRI_TEST_ONLY (unset: every check) picks check NAME.
UNSELECTED=0
selected() {
[ -z "${KIRI_TEST_ONLY:-}" ] && return 0
[[ $1 =~ $KIRI_TEST_ONLY ]] && return 0
UNSELECTED=$((UNSELECTED + 1))
return 1
}
# Which bug a failing check guards (tests/regressions.tsv): kiri_guard NAME.
# shellcheck source=SCRIPTDIR/lib/regressions.sh
. "$(dirname "$0")/lib/regressions.sh"
# A listed check that no longer exists would never print its line: say so.
command -v python3 >/dev/null && ! python3 "$(dirname "$0")/lib/check-regressions.py" >/dev/null 2>&1 &&
echo "e2e: tests/regressions.tsv names a check that is gone; see python3 tests/lib/check-regressions.py"
section() { printf '\n== %s\n' "$1"; SEC_ONLY=; SEC_NEEDS=; }
# skip NAME REASON: not run here, counted by reason in the summary.
SKIP_WHY=()
skip() { SKIP=$((SKIP + 1)); SKIP_WHY+=("$2"); printf ' SKIP %s (%s)\n' "$1" "$2"; }
skip() { selected "$1" || return 0; SKIP=$((SKIP + 1)); SKIP_WHY+=("$2"); printf ' SKIP %s (%s)\n' "$1" "$2"; }
# Where each check runs. Kiri runs containers in its own Linux VM on macOS
# (SYS=mac), and on the host's own kernel on Linux (linux) and in WSL 2
@@ -147,12 +174,14 @@ needs() {
}
# skip_setup NAME REASON: missing in this setup, a failure under KIRI_TEST_STRICT=1.
skip_setup() {
selected "$1" || return 0
if [ "${KIRI_TEST_STRICT:-0}" = 1 ]; then
FAIL=$((FAIL + 1)); FAILED+=("$1"); printf ' FAIL %s (strict: %s)\n' "$1" "$2"
FAIL=$((FAIL + 1)); FAILED+=("$1"); printf ' FAIL %s (strict: %s)\n' "$1" "$2"; kiri_guard "$1"
else skip "$@"; fi
}
# Whether check $1 runs in this section: called first by t and code.
gate() {
selected "$1" || return 1
if [ -n "${SEC_ONLY:-}" ] && ! on "$SEC_ONLY"; then skip "$1" "$(sys_names "$SEC_ONLY") only"; return 1; fi
if [ -n "${SEC_NEEDS:-}" ] && [ -n "$(missing "$SEC_NEEDS")" ]; then skip_setup "$1" "$(missing "$SEC_NEEDS")"; return 1; fi
}
@@ -1448,7 +1477,10 @@ needs amd64 t rosetta-node "v22" $D run --rm --platform linux/amd64 node:22-alpi
only mac t rosetta-no-auxv-29 "no type 29" $D run --rm alpine sh -c 'od -An -v -tu8 -w16 /proc/self/auxv | awk "\$1 == 29 { n++ } END { print n ? \"type 29 given\" : \"no type 29\" }"'
# Back to the engine's own architecture for the rest (an Intel Mac's is amd64).
ARCH=$($D version -f '{{.Server.Arch}}' 2>/dev/null)
t native-again "$([ "$ARCH" = amd64 ] && echo x86_64 || echo aarch64)" bash -c ". '$IMAGES_SH'; kiri_fetch alpine:latest linux/$ARCH && kiri_fetch node:22-alpine linux/$ARCH && $D run --rm alpine uname -m"
# A set-up line, not part of the check: with KIRI_TEST_ONLY the checks after
# this need the native alpine back whether native-again runs or not.
kiri_fetch alpine:latest "linux/$ARCH"; kiri_fetch node:22-alpine "linux/$ARCH"
t native-again "$([ "$ARCH" = amd64 ] && echo x86_64 || echo aarch64)" $D run --rm alpine uname -m
$D rmi "$AMD64_ONLY" >/dev/null 2>&1
section "security: seccomp, capabilities, read-only"
@@ -1724,6 +1756,7 @@ if [ -n "$HUB_LEFT0" ] && [ -n "$HUB_LEFT1" ]; then
else echo "$HUB_MSG: $((HUB_LEFT0 - HUB_LEFT1))"; fi
fi
printf '\n%d passed, %d failed, %d skipped\n' "$PASS" "$FAIL" "$SKIP"
[ -n "${KIRI_TEST_ONLY:-}" ] && echo "not selected by KIRI_TEST_ONLY: $UNSELECTED"
# Skips by reason, so they show and can't quietly grow.
[ "$SKIP" -gt 0 ] && echo "skipped: $(printf '%s\n' "${SKIP_WHY[@]}" | sort | uniq -c | sort -rn | sed 's/^ *\([0-9]*\) /\1 /' | paste -sd, - | sed 's/,/, /g')"
for f in "${FAILED[@]+"${FAILED[@]}"}"; do echo " failed: $f"; done
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
"""tests/regressions.tsv must name only checks that still exist. Each line
is a check name, a tab, the issue or pull request (#N), a tab, and one line
on what broke. A check exists when a test script runs it by that name
(t NAME or code NAME; a case of tests/stress.sh, selected NAME); a name
with a / is a file under the repo.
Reads the files only (no engine, no network); prints what is wrong and
exits 1 if anything is.
python3 tests/lib/check-regressions.py
"""
import pathlib
import re
import sys
TESTS = pathlib.Path(__file__).resolve().parent.parent
TABLE = TESTS / "regressions.tsv"
def defined():
names = set()
run = re.compile(r"(?:^|[\s;(&|])(?:t|code|check|selected)\s+\"?([a-z0-9][a-z0-9_-]*)\"?\s")
for p in sorted(TESTS.glob("*.sh")):
for line in p.read_text().splitlines():
if line.lstrip().startswith("#"):
continue
names.update(m.group(1) for m in run.finditer(line + " "))
return names
def main():
have = defined()
bad = 0
seen = set()
rows = 0
for n, line in enumerate(TABLE.read_text().splitlines(), 1):
if not line.strip() or line.startswith("#"):
continue
rows += 1
cols = line.split("\t")
where = f"tests/regressions.tsv:{n}"
if len(cols) != 3 or not re.fullmatch(r"#[0-9]+", cols[1]) or not cols[2].strip():
print(f"{where}: want NAME<tab>#N<tab>what broke, got {line!r}")
bad += 1
continue
name = cols[0]
if name in seen:
print(f"{where}: {name} is listed twice")
bad += 1
seen.add(name)
if "/" in name:
if not (TESTS.parent / name).is_file():
print(f"{where}: no file {name}")
bad += 1
elif name not in have:
print(f"{where}: no check named {name} in tests/*.sh")
bad += 1
print(f"{rows} regression checks listed, {bad} problem(s)")
return 1 if bad else 0
if __name__ == "__main__":
sys.exit(main())
+15
View File
@@ -0,0 +1,15 @@
# shellcheck shell=sh
# Which bug a check guards, from tests/regressions.tsv. Sourced by the
# suites; their t and code helpers call kiri_guard NAME on a failure, which
# prints, for a listed check, a line such as
#
# guards: #621 a container start hung for ever when it ran beside docker system df
#
# and nothing for any other check.
KIRI_REGRESSIONS=${KIRI_REGRESSIONS:-$(cd "$(dirname "$0")" && pwd)/regressions.tsv}
kiri_guard() {
[ -r "$KIRI_REGRESSIONS" ] || return 0
awk -F '\t' -v n="$1" '$1 == n { printf " guards: %s %s\n", $2, $3 }' "$KIRI_REGRESSIONS"
}
+173
View File
@@ -0,0 +1,173 @@
#!/bin/bash
# Makes a Linux host look like a Windows (WSL 2) install to the engine, or
# puts it back. WSL 2 gives each distro one resolver: an address of its own
# outside 127/8 on `lo` (10.255.255.254), forwarding to Windows. A Linux host
# with systemd-resolved has 127.0.0.53 instead, so checks that depend on the
# WSL shape (#624) pass there whatever the engine does. Usage, as root:
#
# KIRI_TEST_ALLOW_HOST_CHANGES=1 tests/lib/wsl-shape.sh up # shape the host
# KIRI_TEST_ALLOW_HOST_CHANGES=1 tests/lib/wsl-shape.sh down # put it back
# tests/lib/wsl-shape.sh status # what is in place
#
# `up` adds the address to `lo` (KIRI_SHAPE_ADDR, default 10.255.255.254),
# starts a small forwarder there on port 53 (UDP and TCP, python3) to the
# host's real upstream resolver (KIRI_SHAPE_UPSTREAM, default the first
# non-loopback one systemd-resolved or /etc/resolv.conf names), and
# bind-mounts a resolv.conf naming only that address over /etc/resolv.conf.
# Nothing in /etc is written: the file or symlink there stays as it is, and
# a reboot undoes the mount, the address and the forwarder by itself.
#
# `down` undoes exactly what `up` did, also after a crash part-way: each
# change is noted in /run/kiri-test-wsl-shape before it is made. While the
# shape is up, systemd-resolved may take the shaped file's address as a
# server of its own; `down` restarts it then, so it forgets it.
#
# The engine reads the host's resolver when its agent starts: start (or
# restart) the engine after `up`, and again after `down`. tests/wsl-shape.sh
# does all of it around the DNS checks of tests/e2e.sh.
set -u
STATE=/run/kiri-test-wsl-shape
ADDR=${KIRI_SHAPE_ADDR:-10.255.255.254}
say() { echo "wsl-shape: $*"; }
die() { echo "wsl-shape: $*" >&2; exit 1; }
guard() {
[ "$(uname -s)" = Linux ] || die "Linux hosts only"
[ "${KIRI_TEST_ALLOW_HOST_CHANGES:-0}" = 1 ] || die "this changes the host's DNS; set KIRI_TEST_ALLOW_HOST_CHANGES=1 to allow it"
[ "$(id -u)" = 0 ] || die "run as root"
command -v ip >/dev/null || die "needs ip (iproute2)"
}
# The first IPv4 nameserver in file $1 that is not loopback and not ours.
upstream_in() { sed -n 's/^nameserver[[:space:]]*\([0-9.]*\).*/\1/p' "$1" 2>/dev/null | grep -v -e '^127\.' -e "^${ADDR//./\\.}\$" | head -1; }
has_addr() { ip -4 -o addr show dev lo | grep -qF " inet $ADDR/"; }
forwarder_up() { [ -s "$STATE/forwarder.pid" ] && kill -0 "$(cat "$STATE/forwarder.pid")" 2>/dev/null; }
mounted() { [ -s "$STATE/mounted-on" ] && grep -qs " $(cat "$STATE/mounted-on") " /proc/self/mountinfo; }
# The forwarder: each UDP query is sent on to the upstream and its answer
# sent back; each TCP connection is relayed to the upstream's port 53.
FORWARDER='import socket, sys, threading
addr, up = sys.argv[1], sys.argv[2]
def udp_one(srv, data, peer):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.settimeout(5)
try:
s.sendto(data, (up, 53)); srv.sendto(s.recv(65535), peer)
except OSError: pass
finally: s.close()
def udp():
srv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); srv.bind((addr, 53))
while True:
data, peer = srv.recvfrom(65535)
threading.Thread(target=udp_one, args=(srv, data, peer), daemon=True).start()
def pipe(a, b):
try:
while True:
d = a.recv(65535)
if not d: break
b.sendall(d)
except OSError: pass
finally:
for s in (a, b):
try: s.shutdown(socket.SHUT_RDWR)
except OSError: pass
def tcp_one(c):
try: u = socket.create_connection((up, 53), timeout=5); u.settimeout(None)
except OSError: c.close(); return
threading.Thread(target=pipe, args=(c, u), daemon=True).start(); pipe(u, c)
def tcp():
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM); srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind((addr, 53)); srv.listen(64)
while True:
c, _ = srv.accept(); threading.Thread(target=tcp_one, args=(c,), daemon=True).start()
threading.Thread(target=tcp, daemon=True).start()
udp()'
# A lookup of example.com through the forwarder: 0 when it answers.
PROBE='import random, socket, struct, sys
q = struct.pack(">HHHHHH", random.randrange(65536), 0x100, 1, 0, 0, 0) + b"\x07example\x03com\x00\x00\x01\x00\x01"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.settimeout(3); s.sendto(q, (sys.argv[1], 53))
sys.exit(0 if s.recv(65535)[:2] == q[:2] else 1)'
status() {
if [ -L /etc/resolv.conf ]; then echo "/etc/resolv.conf: a symlink to $(readlink /etc/resolv.conf)"; else echo "/etc/resolv.conf: a file"; fi
sed -n 's/^\(nameserver.*\)/ \1/p' /etc/resolv.conf
echo "lo: $(ip -4 -o addr show dev lo | awk '{printf "%s ", $4}')"
if [ -d "$STATE" ]; then
echo "shape: up (upstream $(cat "$STATE/upstream" 2>/dev/null); forwarder $(forwarder_up && echo running || echo stopped); resolv.conf mounted over $(cat "$STATE/mounted-on" 2>/dev/null): $(mounted && echo yes || echo no))"
else
echo "shape: down"
fi
command -v systemctl >/dev/null && echo "systemd-resolved: $(systemctl is-active systemd-resolved 2>/dev/null)"
return 0
}
up() {
guard
command -v python3 >/dev/null || die "needs python3 for the forwarder"
local up_ns target
if [ -s "$STATE/upstream" ]; then up_ns=$(cat "$STATE/upstream")
else
up_ns=${KIRI_SHAPE_UPSTREAM:-$(upstream_in /run/systemd/resolve/resolv.conf)}
[ -n "$up_ns" ] || up_ns=$(upstream_in /etc/resolv.conf)
[ -n "$up_ns" ] || die "no upstream resolver found; set KIRI_SHAPE_UPSTREAM"
fi
if has_addr && forwarder_up && mounted; then say "already up"; status; return 0; fi
# The file the mount covers: /etc/resolv.conf, or where its symlink leads.
target=$(readlink -f /etc/resolv.conf)
[ -f "$target" ] || die "/etc/resolv.conf leads to $target, which is not a file"
say "changes: address $ADDR on lo; a DNS forwarder on $ADDR:53 to $up_ns; a resolv.conf naming only $ADDR mounted over $target (the /etc/resolv.conf in use); undo with: down"
mkdir -p "$STATE"
echo "$up_ns" > "$STATE/upstream"
command -v systemctl >/dev/null && systemctl is-active -q systemd-resolved 2>/dev/null && touch "$STATE/resolved-was-active"
if ! has_addr; then
touch "$STATE/addr-added"
ip addr add "$ADDR/32" dev lo || die "could not add $ADDR to lo"
elif [ ! -e "$STATE/addr-added" ]; then
say "$ADDR was already on lo: left there on down"
fi
if ! forwarder_up; then
printf '%s\n' "$FORWARDER" > "$STATE/forwarder.py"
setsid python3 "$STATE/forwarder.py" "$ADDR" "$up_ns" > "$STATE/forwarder.log" 2>&1 < /dev/null &
echo $! > "$STATE/forwarder.pid"
local ok=
for _ in $(seq 20); do python3 -c "$PROBE" "$ADDR" 2>/dev/null && { ok=1; break; }; sleep 0.25; done
[ -n "$ok" ] || { say "the forwarder does not answer: $(tail -2 "$STATE/forwarder.log")"; down; exit 1; }
fi
if ! grep -qs " $target " /proc/self/mountinfo; then
printf '# made by tests/lib/wsl-shape.sh, as WSL 2 generates it\nnameserver %s\n' "$ADDR" > "$STATE/resolv.conf"
echo "$target" > "$STATE/mounted-on"
mount --bind "$STATE/resolv.conf" "$target" || { say "could not mount over $target"; down; exit 1; }
fi
status
}
down() {
guard
[ -d "$STATE" ] || { say "nothing to undo"; status; return 0; }
say "putting the host back"
local target
if [ -s "$STATE/mounted-on" ]; then
target=$(cat "$STATE/mounted-on")
while grep -qs " $target " /proc/self/mountinfo; do umount "$target" || die "could not unmount $target"; done
fi
if [ -s "$STATE/forwarder.pid" ]; then
kill "$(cat "$STATE/forwarder.pid")" 2>/dev/null
for _ in $(seq 20); do forwarder_up || break; sleep 0.1; done
fi
if [ -e "$STATE/addr-added" ] && has_addr; then ip addr del "$ADDR/32" dev lo || die "could not remove $ADDR from lo"; fi
# systemd-resolved reads a resolv.conf that is not its own as servers of
# its own; it kept the shaped address after the file came back.
if [ -e "$STATE/resolved-was-active" ] && command -v resolvectl >/dev/null && resolvectl dns 2>/dev/null | grep -qF "$ADDR"; then
say "systemd-resolved took $ADDR as a server: restarting it"
systemctl restart systemd-resolved
fi
rm -rf "$STATE"
status
}
case ${1:-} in
up) up ;;
down) down ;;
status) status ;;
*) sed -n '2,/^$/p' "$0" | sed 's/^# \{0,1\}//'; exit 2 ;;
esac
+4 -1
View File
@@ -24,10 +24,13 @@ $D cp "$(dirname "$0")/lib/images.sh" "$N":/images.sh >/dev/null
$D exec -e KIRI_TEST_REGISTRY="$KIRI_REG" "$N" sh -c '. /images.sh; export DOCKER_HOST=unix:///root/.kiri/run/docker.sock; kiri_seed_images $KIRI_IMAGES_LINUX_HOST' ||
echo "linux-host: an image could not be fetched; the checks that run it will fail"
PASS=0; FAIL=0
# A failing check that guards a known bug prints which (tests/regressions.tsv).
# shellcheck source=SCRIPTDIR/lib/regressions.sh
. "$(dirname "$0")/lib/regressions.sh"
t() {
local name=$1 want=$2; shift 2
local got; got=$($D exec "$N" sh -c "export DOCKER_HOST=unix:///root/.kiri/run/docker.sock; $*" 2>&1 | tr -d '\r')
if [[ "$got" == *"$want"* ]]; then PASS=$((PASS + 1)); else FAIL=$((FAIL + 1)); printf ' FAIL %s\n want: %s\n got: %s\n' "$name" "$want" "$(echo "$got" | head -3)"; fi
if [[ "$got" == *"$want"* ]]; then PASS=$((PASS + 1)); else FAIL=$((FAIL + 1)); printf ' FAIL %s\n want: %s\n got: %s\n' "$name" "$want" "$(echo "$got" | head -3)"; kiri_guard "$name"; fi
}
t server-os "linux" "docker version --format '{{.Server.Os}}'"
t run "3." "docker run --rm alpine cat /etc/alpine-release"
+105
View File
@@ -0,0 +1,105 @@
# Checks that guard a real bug: check name, tab, issue or pull request, tab,
# what broke. A failing check listed here prints a "guards:" line naming it.
# A name with a / is a test file (tests/ui/...). Every bug fix adds its check
# here; python3 tests/lib/check-regressions.py fails when a name is gone.
connection-close-start #588 a start sent with Connection: close was never closed, so Docker.DotNet hung until its timeout (#520)
http10-start-closes #588 an HTTP/1.0 request stayed open after its answer (#479)
keep-alive-start-stays #588 the connection-close fix must not close a kept-alive connection
connection-close-said #588 the answer to Connection: close did not say Connection: close
http10-ping-closes #588 an HTTP/1.0 ping stayed open after its answer (#479)
pid-mode-inspect #588 --pid was accepted and ignored; inspect lost HostConfig.PidMode (#347)
pid-container-sees #588 --pid container:NAME did not join that container's PID namespace (#347)
pid-container-pid1 #588 --pid container:NAME did not see the other container's PID 1 (#347)
pid-host-sees-more #588 --pid host did not show the host's processes (#347)
pid-own-default #588 a container without --pid must keep its own PID namespace (#347)
pid-container-stopped #588 joining a stopped container's PID namespace was not refused (#347)
pid-container-unknown #588 --pid container:missing was not refused with Docker's message (#347, #600)
bridge-name-refused #588 a network's own bridge name was reported but never applied (#423)
bridge-name-nothing-made #588 a refused bridge name still made the network (#423)
bridge-name-empty #588 an empty bridge name, Docker's unset, must still be accepted (#423)
port-exposed-null #588 an exposed port that is not published was missing from inspect, so Traefik found no port (#492)
port-exposed-stopped #588 a stopped container's exposed ports were shown wrongly in inspect (#492)
volumes-from-running #588 --volumes-from was accepted and ignored (#450)
volumes-from-ro #588 --volumes-from :ro was not read-only (#450)
volumes-from-inspect #588 inspect did not show the mounts --volumes-from gave (#450)
volumes-from-stopped #588 --volumes-from a stopped container gave nothing (#450)
volumes-from-unknown #588 --volumes-from a missing container was not refused with Docker's message (#450, #600)
volumes-from-anon-kept #588 an anonymous volume still used by another container was removed with its first owner (#450)
top-aux #588 docker top ignored ps_args such as aux (#348)
top-aux-master #588 docker top aux did not give ps's columns (#348)
top-eo #588 docker top -eo did not give the columns asked for (#348)
top-eo-rss #588 docker top -eo rss gave no memory column (#348)
top-ps-args-refused #588 unsupported ps_args were silently ignored instead of refused (#348)
ij-setup #588 sets up the damaged image list check below (#440)
ij-info-warns #588 a repaired images.json gave no docker info warning (#440)
ij-info-names-lost #588 the repair warning did not name the images it lost (#440)
ij-layers-kept #588 a lost image's unpacked layers were deleted by the repair (#440)
ij-layers-kept-next-start #588 a lost image's unpacked layers were deleted at the next start (#440)
ij-warning-gone #588 the repair warning stayed after the kept copy was removed (#440)
image-inspect-rootfs-diffid #596 image inspect gave compressed blob digests as RootFS.Layers, not the uncompressed diff IDs
image-labels-inspect #596 image labels were missing from inspect
image-labels-filter #596 the label filter on the image list did not match image labels
image-labels-filter-not #596 the label! filter on the image list did not exclude labelled images
image-labels-api-empty #596 an image without labels did not show Docker's empty Labels shape
container-labels-inherited #596 a container did not inherit its image's labels
container-labels-override #596 a container's own --label did not win over its image's
commit-keeps-labels #596 docker commit dropped the image's labels
link-missing #600 a missing --link container was a 404, so the docker CLI pulled the image first
netns-missing #600 a missing --network container: was a 404, so the docker CLI pulled the image first
limit-shares-default #612 --cpu-shares 1024, Docker's default, gave less CPU weight than setting nothing
limit-shares-inspect #612 inspect did not give back the --cpu-shares asked for
status-tag #612 an image tag answered 204, not Docker's 201
status-connect #612 network connect answered 204, not Docker's 200
status-disconnect #612 network disconnect answered 204, not Docker's 200
status-exec-detached #612 a detached exec start answered 204, not Docker's 200
status-start-still-204 #612 the status fix must keep a container start at 204
api-too-old #612 an API version older than 1.24 was served instead of refused
api-too-old-status #612 an API version older than 1.24 was not a 400
api-min-served #612 the oldest supported API version must still be served
api-newer-served #612 an API version newer than the engine's must still be served
cp-proc-by-link #612 docker cp walked into the kernel's /proc through a link to /
cp-sys-by-link #612 docker cp walked into the kernel's /sys through a link to /
cp-link-still-copies #612 the /proc and /sys fix must still copy through links
cp-tar-mode #612 docker cp archives put file type bits in the mode field
diff-never-started #612 docker diff failed on a container that never started
commit-never-started #612 docker commit failed on a container that never started (chroot: No such file or directory)
create-missing-network #612 a container on a missing network was refused at create, not at start as Docker does
missing-network-inspect #612 a container created on a missing network could not be inspected
start-missing-network #612 the start of a container on a missing network was not refused
start-missing-network-status #612 the start of a container on a missing network did not give Docker's status
run-missing-network #612 docker run on a missing network did not give Docker's message
run-missing-network-no-pull #612 docker run on a missing network made the docker CLI pull the image first
run-missing-network-removed #612 docker run --rm on a missing network left the container behind
starts-beside-df #621 a container start hung for ever when it ran beside docker system df
rm-f-stuck-start #621 a stuck start could not be removed: rm -f, kill and stop never answered
agent-dies-beside-stuck-start #621 an agent that died beside a stuck start went unnoticed and every request hung
rm-f-during-start #621 rm -f sent while containers start must answer and leave nothing behind
stop-during-start #621 stop sent while containers start must answer and leave nothing behind
churn-beside-df #621 create, start, exec and rm beside docker system df must each answer within its limit
rm-f-exit-code #622 docker run --rm exited 0, not 137, when docker rm -f raced it
image-ls-untagged-row #623 the image list hid untagged images
image-ls-dangling #623 the image list's dangling=true filter did not work
image-ls-dangling-false #623 the image list's dangling=false filter did not work
image-ls-until #623 the image list's until filter did not work
system-prune-label #623 a system prune with a label filter failed on the build cache after pruning containers
image-prune-label-keeps #623 an image prune with a label filter deleted untagged images without the label
image-prune-all-label-keeps #623 an image prune -a with a label filter deleted unused images without the label
network-prune-until #623 a network prune did not read until as Docker does
volume-prune-keeps-opts #623 a volume prune deleted volumes made with driver options
build-prune-until-date #623 a build-cache prune did not take until as a date
dns-default-bridge-gateway #624 on a host whose resolver is one of its own addresses (WSL), the default bridge got a loopback resolver
dns-default-bridge-no-loopback #624 on a host whose resolver is one of its own addresses (WSL), the default bridge got 127.0.0.11
build-resolvconf #624 on a host whose resolver is one of its own addresses (WSL), build steps did not get Kiri's resolver
build-no-public-resolver #624 on a host whose resolver is one of its own addresses (WSL), BuildKit put 8.8.8.8 in build steps
user-net-own-dns-server #624 a container on a user network could not bind port 53 for its own DNS server
user-net-own-dns-names #624 a container running its own DNS server must still resolve the network's names
user-net-own-dns-upstream #624 a container running its own DNS server must still resolve names outside
top-l #625 docker top -l was refused or gave the wrong columns
top-l-values #625 docker top -l gave wrong values
top-efl-cmd #625 docker top -efl gave the wrong command column
top-sort #625 docker top --sort was ignored
top-sort-k #625 docker top k KEY was ignored
top-width #625 docker top ignored column widths such as pid:8
top-title-refused #625 docker top accepted a PID title on a column other than pid, which Docker refuses
top-title-no-pid #625 docker top with a renamed pid column did not give Docker's error
tests/ui/setup-wsl-unknown.js #627 Windows' first start flashed Install WSL before kiri-win said whether WSL is there
Can't render this file because it contains an unexpected character in line 2 and column 52.
+342
View File
@@ -0,0 +1,342 @@
#!/bin/bash
# Race and load checks: the engine kept busy from several sides at once, as
# the races fixed in #621 and #622 needed to show. Each case runs a counted
# number of rounds with a time limit on every command, says what it
# measured, and passes or fails. Usage:
#
# tests/stress.sh # every case, two to five minutes
# tests/stress.sh rm-f-exit-code # only the cases named
# KIRI_STRESS_ROUNDS=3 tests/stress.sh # three times the rounds
# KIRI_STRESS_SECONDS=600 tests/stress.sh # churn-beside-df for 10 minutes (default 60)
# KIRI_TEST_CLI=kiri tests/stress.sh # through kiri's own commands
#
# The cases:
# starts-beside-df container starts beside four loops of system df on a
# volume of many files: none may hang or fail (#621)
# rm-f-exit-code docker run --rm, then rm -f at varied delays: each run
# exits 137, never 0; and four waiters on one rm -f (#622)
# rm-f-during-start rm -f sent while several containers start at once
# stop-during-start stop sent while several containers start at once:
# each answers within its limit and nothing is left
# (on a Linux host or WSL, no cgroup or interface either)
# That part only sees what this shell can see: run from
# a container beside the engine, give the container the
# host's cgroup view (--cgroupns host) or it counts 0
# without having looked.
# churn-beside-df create, start, exec, rm and volume churn beside system
# df loops: no command over its limit, none failed
#
# The engine is found as tests/e2e.sh finds it (DOCKER_CONTEXT, default
# kiri); images come from KIRI_TEST_REGISTRY (tests/lib/images.sh). It only
# touches what it makes (names kiri-stress-*, label kiri-stress=1), removes
# it at the end, and never prunes. Exits non-zero if any case fails.
set -u
export DOCKER_CONTEXT=${DOCKER_CONTEXT:-kiri}
D=docker
SOCK=$(docker context inspect "$DOCKER_CONTEXT" --format '{{.Endpoints.docker.Host}}' 2>/dev/null); SOCK=${SOCK#unix://}
[ -S "$SOCK" ] || { echo "stress: no engine socket for context $DOCKER_CONTEXT ($SOCK)"; exit 1; }
export KIRI_SOCKET=$SOCK
# KIRI_TEST_CLI=kiri: the commands go through `kiri`, found as tests/e2e.sh does.
if [ "${KIRI_TEST_CLI:-docker}" = kiri ]; then
if [ -z "${KIRI:-}" ]; then
KIRI=$(for p in $(lsof -t "$SOCK" 2>/dev/null); do lsof -a -d txt -Fn -p "$p" 2>/dev/null; done | sed -n 's/^n//p' | grep '/kiri$' | head -1)
[ -x "$KIRI" ] || KIRI=$(cd "$(dirname "$0")/.." && pwd)/target/release/kiri
fi
[ -x "$KIRI" ] || { echo "stress: KIRI_TEST_CLI=kiri, but no kiri binary found (set KIRI)"; exit 1; }
D=$KIRI
echo "stress: commands go through $KIRI"
fi
ROUNDS=${KIRI_STRESS_ROUNDS:-1}
CHURN_SECONDS=${KIRI_STRESS_SECONDS:-60}
P=kiri-stress
L=(--label "$P=1")
IMG=alpine:latest
WORK=$(mktemp -d)
PASS=0 FAIL=0 SKIP=0 FAILED=()
T_START=$SECONDS
# $D quoted: the kiri binary's path may hold a space (Kiri Repro.app).
kiri_docker() { "$D" "$@"; }
# shellcheck source=SCRIPTDIR/lib/images.sh
. "$(dirname "$0")/lib/images.sh"
# shellcheck source=SCRIPTDIR/lib/regressions.sh
. "$(dirname "$0")/lib/regressions.sh"
# On macOS the engine's Linux is Kiri's VM, which this shell cannot see; on a
# Linux host and in WSL it is this host, so leftovers there are looked for too.
KVER=$(perl -e 'alarm 30; exec @ARGV' "$D" version --format '{{.Server.KernelVersion}}' 2>/dev/null)
case ${KIRI_TEST_SYSTEM:-} in
mac | linux | wsl) SYS=$KIRI_TEST_SYSTEM ;;
*) case $KVER in *-kiri) SYS=mac ;; *[Mm]icrosoft*) SYS=wsl ;; *) SYS=linux ;; esac ;;
esac
echo "stress: $SYS (kernel $KVER), rounds x$ROUNDS, churn ${CHURN_SECONDS}s"
# tm LIMIT COMMAND...: runs it with a time limit, printing "EXIT MS TIMEDOUT".
# A command still running at LIMIT seconds is killed (exit 137, TIMEDOUT 1).
# Its output goes to $TM_OUT (default nowhere).
tm() {
perl -e '
use Time::HiRes qw(time);
my $lim = shift; my $t0 = time; my $to = 0;
my $pid = fork() // die "fork: $!";
if (!$pid) { open STDOUT, ">>", ($ENV{TM_OUT} || "/dev/null"); open STDERR, ">&STDOUT"; exec @ARGV; exit 127 }
$SIG{ALRM} = sub { $to = 1; kill "KILL", $pid };
alarm $lim;
while (waitpid($pid, 0) == -1 && $!{EINTR}) {}
my $st = $?; alarm 0;
printf "%d %d %d\n", ($st & 127) ? 128 + ($st & 127) : $st >> 8, (time - $t0) * 1000, $to;
' "$@"
}
# lim SECS COMMAND...: the command, output kept, killed at SECS seconds.
lim() { perl -e 'alarm shift; exec @ARGV' "$@"; }
# stats FILE COLUMN: "p50 X ms, max Y ms" of that column's numbers.
stats() { awk -v c="$2" '{print $c}' "$1" | sort -n | awk '{a[NR]=$1} END {if (NR) printf "p50 %d ms, max %d ms", a[int((NR+1)/2)], a[NR]; else printf "none"}'; }
# Which cases run: the names given, KIRI_TEST_ONLY's pattern, else all.
CASES=" $* "
selected() {
[ "$CASES" = " " ] || [[ "$CASES" == *" $1 "* ]] || return 1
[ -z "${KIRI_TEST_ONLY:-}" ] || [[ $1 =~ $KIRI_TEST_ONLY ]]
}
case_start() { printf '\n== %s: %s\n' "$1" "$2"; }
# check NAME OK MEASURED: the case's verdict (OK is 1 or 0) and what it saw.
check() {
echo " measured: $3"
if [ "$2" = 1 ]; then PASS=$((PASS + 1)); echo " ok $1"
else FAIL=$((FAIL + 1)); FAILED+=("$1"); echo " FAIL $1"; kiri_guard "$1"; fi
}
# df loops: N background loops asking /system/df (what docker system df
# asks) until $WORK/df.stop exists; each answer's code and time in df.log.
# df_stop ends them and sets DF_SEEN to what they measured.
df_start() {
rm -f "$WORK/df.stop" "$WORK/df.log"; DF_PIDS=
for _ in $(seq "$1"); do
(while [ -d "$WORK" ] && [ ! -e "$WORK/df.stop" ]; do curl -s -m 30 -o /dev/null -w '%{http_code} %{time_total}\n' --unix-socket "$SOCK" http://d/system/df >> "$WORK/df.log"; done) &
DF_PIDS="$DF_PIDS $!"
done
}
df_stop() {
touch "$WORK/df.stop"
# shellcheck disable=SC2086
[ -n "${DF_PIDS:-}" ] && wait $DF_PIDS 2>/dev/null; DF_PIDS=
DF_SEEN=$(awk '$1 == 200 {n++; t = $2 > t ? $2 : t} $1 != 200 {bad++} END {printf "%d df answers (max %.1f s), %d df errors or timeouts", n, t, bad}' "$WORK/df.log" 2>/dev/null)
}
# Linux host and WSL: cgroup directories and host interfaces left for the
# container ids in file $1 (their veths are kv<first 9 of the id>...).
host_leftovers() {
[ "$SYS" = mac ] && { echo "not looked for (the VM)"; return; }
local cg=0 ifs=0 id i
while read -r id; do
[ -n "$id" ] || continue
[ -n "$(find /sys/fs/cgroup -type d -name "*$id*" 2>/dev/null | head -1)" ] && cg=$((cg + 1))
for i in /sys/class/net/kv"${id:0:9}"*; do [ -e "$i" ] && { ifs=$((ifs + 1)); break; }; done
done < "$1"
echo "$cg cgroups, $ifs interfaces"
}
# Everything this script made, each removal given a limit (a stuck one is
# reported, not waited for).
cleanup() {
# Loops still running (the script was stopped): ended before $WORK goes.
# shellcheck disable=SC2086
[ -n "${DF_PIDS:-}" ] && { kill $DF_PIDS 2>/dev/null; wait $DF_PIDS 2>/dev/null; DF_PIDS=; }
# shellcheck disable=SC2086
[ -n "${WPIDS:-}" ] && { kill $WPIDS 2>/dev/null; wait $WPIDS 2>/dev/null; WPIDS=; }
local c v left=0
for c in $(lim 20 "$D" ps -aq --filter "label=$P=1" 2>/dev/null); do
[ "$(tm 20 "$D" rm -f -v "$c" | cut -d' ' -f1)" = 0 ] || left=$((left + 1))
done
for v in $(lim 20 "$D" volume ls -q --filter "label=$P=1" 2>/dev/null); do tm 20 "$D" volume rm -f "$v" >/dev/null; done
[ "$left" = 0 ] || echo "stress: $left container(s) could not be removed"
}
trap 'cleanup; rm -rf "$WORK"' EXIT
trap 'exit 130' INT TERM
# The volume system df walks: 20,000 empty files, made once a run.
fill_dfwalk() {
tm 20 "$D" volume create "${L[@]}" $P-dfwalk >/dev/null
# shellcheck disable=SC2016 # expanded by the container's shell
tm 180 "$D" run --rm "${L[@]}" -v $P-dfwalk:/d $IMG sh -c 'test -d /d/200 || { cd /d; for i in $(seq 200); do mkdir $i; for j in $(seq 100); do : > $i/$j; done; done; }' >/dev/null
}
kiri_seed_images $IMG || echo "stress: $IMG could not be fetched; every case will fail"
cleanup
# (a) A start beside system df: system df measured on a thread of the agent
# while a container's first process was cloned, and that process could
# inherit the allocator's lock held by the measuring thread and hang for
# good (#621). A volume of 20,000 files makes each measurement take a while.
if selected starts-beside-df; then
N=$((100 * ROUNDS)) LIM=15
case_start starts-beside-df "$N starts beside 4 system df loops, $LIM s a start"
fill_dfwalk
df_start 4
: > "$WORK/a.log"; stuck=0
for i in $(seq "$N"); do
read -r rc ms to <<<"$(tm $LIM "$D" run -d "${L[@]}" --name "$P-df-$i" $IMG true)"
echo "$rc $ms $to" >> "$WORK/a.log"
[ "$to" = 1 ] && { stuck=$((stuck + 1)); echo " start $i: no answer in $LIM s"; }
# A wedged engine: three stuck starts say enough.
[ "$stuck" -ge 3 ] && { echo " stopped after $stuck stuck starts"; break; }
done
df_stop; dfm=$DF_SEEN
ran=$(wc -l < "$WORK/a.log" | tr -d ' ')
failed=$(awk '$3 == 0 && $1 != 0' "$WORK/a.log" | wc -l | tr -d ' ')
for i in $(seq "$ran"); do tm $LIM "$D" rm -f "$P-df-$i" >/dev/null; done
check starts-beside-df "$([ "$stuck" = 0 ] && [ "$failed" = 0 ] && [ "$ran" = "$N" ] && echo 1)" \
"$ran starts, $stuck stuck, $failed failed; start $(stats "$WORK/a.log" 2); $dfm"
fi
# (b) rm -f racing docker run --rm: the container's own removal recorded a
# second exit code, 0, over the kill's 137, and the run exited 0 (#622).
if selected rm-f-exit-code; then
PER=$((8 * ROUNDS)) WAITERS=$((10 * ROUNDS))
case_start rm-f-exit-code "$PER runs at each of 6 delays, rm -f then; $WAITERS runs with 4 waiters; 60 s a run"
: > "$WORK/b.log"; B_TIMEOUTS=0
for d in 0 0.02 0.05 0.1 0.2 0.5; do
# A wedged engine: three runs that never ended say enough.
[ "$B_TIMEOUTS" -ge 3 ] && { echo " stopped after $B_TIMEOUTS runs got no answer"; break; }
for i in $(seq "$PER"); do
n=$P-rm-$i
: > "$WORK/b.out"
TM_OUT=$WORK/b.out tm 60 "$D" run --rm "${L[@]}" --name "$n" $IMG sleep 300 > "$WORK/b.run" &
pid=$!
sleep $d
# rm -f may land before the container exists: again until the run ends.
for _ in $(seq 60); do
tm 15 "$D" rm -f "$n" >/dev/null
kill -0 $pid 2>/dev/null || break
sleep 0.3
kill -0 $pid 2>/dev/null || break
done
wait $pid
read -r rc _ to < "$WORK/b.run"
# rm -f before the CLI attached or started it: the container is gone
# or going and the run says so (a 404 or 409, as Docker gives), which
# is not this race.
[ "$rc" != 137 ] && [ "$rc" != 0 ] && [ "$to" = 0 ] && grep -qE 'received 404|No such container|is being removed|removal of container|removed before it finished starting' "$WORK/b.out" && rc=gone
echo "$d $rc $to" >> "$WORK/b.log"
[ "$to" = 1 ] && B_TIMEOUTS=$((B_TIMEOUTS + 1))
[ "$rc" = 137 ] || echo "${d}s exit $rc: $(tr -d '\r' < "$WORK/b.out" | grep . | grep -v "^Run '" | tail -1)" >> "$WORK/b.msgs"
done
done
tally=$(awk '{print ($3 == 1 ? "timeout" : $2 == "gone" ? "removed-before-attach" : "exit " $2)}' "$WORK/b.log" | sort | uniq -c | awk '{c=$1; $1=""; printf "%s%s x%d", s, substr($0, 2), c; s=", "}')
zero=$(awk '$2 == 0' "$WORK/b.log" | wc -l | tr -d ' ')
bad=$(awk '($2 != 137 && $2 != "gone") || $3 == 1' "$WORK/b.log" | wc -l | tr -d ' ')
badd=$(awk '($2 != 137 && $2 != "gone") || $3 == 1 {print $1 "s:" $2}' "$WORK/b.log" | sort | uniq -c | awk '{printf "%s%s x%d", s, $2, $1; s=", "}')
# The same race seen by four waiters at once: wait until removed, until the
# next exit, until not running (over the API), and docker wait.
: > "$WORK/w.log"
[ "$B_TIMEOUTS" -ge 3 ] && WAITERS=0
for i in $(seq "$WAITERS"); do
n=$P-w-$i
tm 30 "$D" run -d --rm "${L[@]}" --name "$n" $IMG sleep 300 >/dev/null
for c in removed next-exit not-running; do
curl -s -m 30 --unix-socket "$SOCK" -X POST "http://d/containers/$n/wait?condition=$c" > "$WORK/w.$c" &
done
lim 30 "$D" wait "$n" > "$WORK/w.cli" 2>&1 &
sleep 0.1
tm 15 "$D" rm -f "$n" >/dev/null
wait
echo "removed=$(grep -o '"StatusCode":[0-9]*' "$WORK/w.removed" | cut -d: -f2) next-exit=$(grep -o '"StatusCode":[0-9]*' "$WORK/w.next-exit" | cut -d: -f2) not-running=$(grep -o '"StatusCode":[0-9]*' "$WORK/w.not-running" | cut -d: -f2) docker-wait=$(tr -d '\r\n' < "$WORK/w.cli")" >> "$WORK/w.log"
done
wbad=$(grep -vc '^removed=137 next-exit=137 not-running=137 docker-wait=137$' "$WORK/w.log")
wfirst=$(grep -v '^removed=137 next-exit=137 not-running=137 docker-wait=137$' "$WORK/w.log" | sort | uniq -c | head -3 | sed 's/^ *//' | paste -sd ';' -)
[ -s "$WORK/b.msgs" ] && sed "s/$P-rm-[0-9]*/NAME/g" "$WORK/b.msgs" | sort | uniq -c | sort -rn | head -5 | sed 's/^ */ seen /'
check rm-f-exit-code "$([ "$bad" = 0 ] && [ "$wbad" = 0 ] && echo 1)" \
"$(wc -l < "$WORK/b.log" | tr -d ' ') runs: $tally; exit 0 in $zero${badd:+ (not 137 at: $badd)}; waiters: $wbad of $WAITERS rounds saw another code${wfirst:+ ($wfirst)}"
fi
# (c) rm -f or stop sent while several containers start at once, beside
# system df so that a start can hang as in (a). A start that hung held its
# container's lock, so neither answered (#621). What the
# racing start answers is not judged, only that every command answers and
# nothing is left behind.
during_start() { # NAME VERB
local name=$1 verb=$2 K=6 R=$((3 * ROUNDS)) r i d pids slow=0 left=0 cmds=0
case_start "$name" "$R rounds of $K starts at once beside 4 system df loops, $verb sent meanwhile; 20 s a create, 30 s a start, 15 s a $verb"
: > "$WORK/c.ids"; : > "$WORK/c.log"
fill_dfwalk
df_start 4
for r in $(seq "$R"); do
for i in $(seq $K); do
: > "$WORK/c.id"
echo "create $(TM_OUT=$WORK/c.id tm 20 "$D" create "${L[@]}" --name "$P-c-$i" $IMG sleep 300)" >> "$WORK/c.log"
tr -d '\r' < "$WORK/c.id" | grep -E '^[0-9a-f]{12,}$' >> "$WORK/c.ids"
done
pids=
for i in $(seq $K); do (echo "start $(tm 30 "$D" start "$P-c-$i")" >> "$WORK/c.log") & pids="$pids $!"; done
# Into the start at a different moment each round.
d=$(awk -v r="$r" 'BEGIN {printf "%.2f", (r % 4) * 0.05}')
sleep "$d"
for i in $(seq $K); do
if [ "$verb" = stop ]; then (echo "stop $(tm 15 "$D" stop -t 1 "$P-c-$i")" >> "$WORK/c.log") &
else (echo "rm $(tm 15 "$D" rm -f "$P-c-$i")" >> "$WORK/c.log") &
fi
pids="$pids $!"
done
# Not a bare wait: the df loops run on until df_stop.
# shellcheck disable=SC2086
wait $pids
# A stopped container is then removed, which must also answer.
if [ "$verb" = stop ]; then
for i in $(seq $K); do echo "rm $(tm 15 "$D" rm -f "$P-c-$i")" >> "$WORK/c.log"; done
fi
# Gone answers "No such container"; no answer at all counts as left too.
for i in $(seq $K); do lim 15 "$D" container inspect "$P-c-$i" 2>&1 | grep -q 'No such' || left=$((left + 1)); done
# A wedged engine: one round with commands over their limit says enough.
awk '$4 == 1 {f=1} END {exit !f}' "$WORK/c.log" && { echo " stopped after round $r: commands over their limit"; break; }
done
local dfm; df_stop; dfm=$DF_SEEN
# Interfaces and cgroups go a moment after the answer: up to 10 s.
local host hleft
for _ in $(seq 20); do
host=$(host_leftovers "$WORK/c.ids"); hleft=$(echo "$host" | awk '{print $1 + $3}')
{ [ "$SYS" = mac ] || [ "$hleft" = 0 ]; } && break
sleep 0.5
done
cmds=$(wc -l < "$WORK/c.log" | tr -d ' ')
slow=$(awk '$4 == 1' "$WORK/c.log" | wc -l | tr -d ' ')
local slows; slows=$(awk '$4 == 1 {print $1}' "$WORK/c.log" | sort | uniq -c | awk '{printf "%s%s x%d", s, $2, $1; s=", "}')
check "$name" "$([ "$slow" = 0 ] && [ "$left" = 0 ] && { [ "$SYS" = mac ] || [ "$hleft" = 0 ]; } && echo 1)" \
"$cmds commands, $slow over their limit${slows:+ ($slows)}; start $(awk '$1 == "start"' "$WORK/c.log" | stats /dev/stdin 3), $verb $(awk -v v="$verb" '$1 == v' "$WORK/c.log" | stats /dev/stdin 3); left: $left containers, $host (given 10 s to go); $dfm"
}
selected rm-f-during-start && during_start rm-f-during-start rm
selected stop-during-start && during_start stop-during-start stop
# (d) Everyday commands beside system df for a while: every command must
# answer within its limit, and none may fail.
if selected churn-beside-df; then
W=3
case_start churn-beside-df "${CHURN_SECONDS}s of $W workers (volume create, run, exec, rm -f, volume rm) beside 4 system df loops; 30 s a command"
fill_dfwalk
df_start 4
end=$((SECONDS + CHURN_SECONDS)) WPIDS=
for w in $(seq $W); do
(
k=0
while [ $SECONDS -lt $end ]; do
k=$((k + 1)); n=$P-ch-$w-$k v=$P-chv-$w-$k
echo "volume-create $(tm 30 "$D" volume create "${L[@]}" "$v")"
echo "run $(tm 30 "$D" run -d "${L[@]}" --name "$n" -v "$v:/data" $IMG sh -c 'echo hi > /data/f; sleep 30')"
echo "exec $(tm 30 "$D" exec "$n" cat /data/f)"
echo "rm $(tm 30 "$D" rm -f "$n")"
echo "volume-rm $(tm 30 "$D" volume rm "$v")"
done > "$WORK/d.$w.log"
) &
WPIDS="$WPIDS $!"
done
# shellcheck disable=SC2086
wait $WPIDS; WPIDS=
df_stop; dfm=$DF_SEEN
cat "$WORK"/d.*.log > "$WORK/d.log"
cmds=$(wc -l < "$WORK/d.log" | tr -d ' ')
over=$(awk '$4 == 1' "$WORK/d.log" | wc -l | tr -d ' ')
errs=$(awk '$4 == 0 && $2 != 0' "$WORK/d.log" | wc -l | tr -d ' ')
per=$(for op in volume-create run exec rm volume-rm; do printf '%s %s; ' "$op" "$(awk -v o=$op '$1 == o' "$WORK/d.log" | stats /dev/stdin 3)"; done)
which=$(awk '$4 == 1 || $2 != 0 {print $1 ($4 == 1 ? ":timeout" : ":exit" $2)}' "$WORK/d.log" | sort | uniq -c | awk '{printf "%s%s x%d", s, $2, $1; s=", "}')
check churn-beside-df "$([ "$cmds" -gt 0 ] && [ "$over" = 0 ] && [ "$errs" = 0 ] && echo 1)" \
"$cmds commands, $over over their limit, $errs failed${which:+ ($which)}; ${per}$dfm"
fi
printf '\n%d passed, %d failed, %d skipped in %d s\n' "$PASS" "$FAIL" "$SKIP" $((SECONDS - T_START))
for f in "${FAILED[@]+"${FAILED[@]}"}"; do echo " failed: $f"; done
[ "$FAIL" -eq 0 ]
+61
View File
@@ -0,0 +1,61 @@
#!/bin/bash
# The DNS checks of tests/e2e.sh on a Linux host shaped like a Windows (WSL
# 2) install: the host's only resolver an address of its own on `lo`
# (tests/lib/wsl-shape.sh). These are the checks that failed on a real
# Windows install before #624 and pass on a plain Linux host either way.
# Usage, as root, with the engine on this host:
#
# KIRI_TEST_ALLOW_HOST_CHANGES=1 KIRI_ENGINE_RESTART='systemctl restart kiri' tests/wsl-shape.sh
#
# It shapes the host, restarts the engine with KIRI_ENGINE_RESTART (a shell
# command; the engine reads the resolver when its agent starts), runs the
# checks (KIRI_TEST_ONLY, below) and, also when they fail or it is stopped,
# puts the host back and restarts the engine again. Without
# KIRI_ENGINE_RESTART, start the engine yourself while the shape is up
# (tests/lib/wsl-shape.sh up); the wrapper refuses an engine whose agent
# started before the shape. Everything else is passed on to tests/e2e.sh
# (DOCKER_CONTEXT, KIRI_TEST_REGISTRY, KIRI_TEST_STRICT...). Exits as it does.
set -u
HERE=$(cd "$(dirname "$0")" && pwd)
SHAPE=$HERE/lib/wsl-shape.sh
CHECKS='^(dns-default-bridge-gateway|dns-default-bridge-no-loopback|build-resolvconf|build-no-public-resolver|build-dns|udp-dns|udp-dns-tcp-same-port|udp-many|udp-port-listed|udp-inspect|user-net-own-dns-server|user-net-own-dns-names|user-net-own-dns-upstream)$'
export DOCKER_CONTEXT=${DOCKER_CONTEXT:-kiri}
SOCK=$(docker context inspect "$DOCKER_CONTEXT" --format '{{.Endpoints.docker.Host}}' 2>/dev/null); SOCK=${SOCK#unix://}
restart_engine() {
echo "wsl-shape: restarting the engine: $KIRI_ENGINE_RESTART"
bash -c "$KIRI_ENGINE_RESTART" || return 1
for _ in $(seq 120); do docker version >/dev/null 2>&1 && return 0; sleep 0.5; done
echo "wsl-shape: the engine does not answer after the restart"; return 1
}
# The engine's agents (kiri-init children of the process serving $SOCK)
# that started before the shape went up, and so read the old resolver.
stale_agents() {
local epid since a
epid=$(ss -xlpn 2>/dev/null | grep -F " $SOCK " | sed -n 's/.*pid=\([0-9]*\).*/\1/p' | head -1)
[ -n "$epid" ] || return 0
since=$(( $(date +%s) - $(stat -c %Y /run/kiri-test-wsl-shape) ))
for a in $(pgrep -P "$epid" -x kiri-init); do
[ "$(ps -o etimes= -p "$a" | tr -d ' ')" -gt "$since" ] && echo "$a"
done
}
finish() {
local rc=$?
trap - EXIT INT TERM
"$SHAPE" down
[ -n "${KIRI_ENGINE_RESTART:-}" ] && restart_engine
exit "$rc"
}
"$SHAPE" up || exit 1
trap finish EXIT
trap 'exit 130' INT TERM
if [ -n "${KIRI_ENGINE_RESTART:-}" ]; then
restart_engine || exit 1
elif [ -n "$(stale_agents)" ]; then
echo "wsl-shape: the engine's agent started before the shape and still uses the old resolver; restart the engine, or set KIRI_ENGINE_RESTART"
exit 1
fi
KIRI_TEST_ONLY=${KIRI_TEST_ONLY:-$CHECKS} "$HERE/e2e.sh"