test: fix BusyBox portability issues in backend test suite
This commit is contained in:
@@ -3037,7 +3037,7 @@ function apply_quick_fix(codes_str) {
|
||||
status = true;
|
||||
msg = "DNS cache cleared and dnsmasq restarted";
|
||||
} else if (c == "update_subscriptions") {
|
||||
command_status("/usr/bin/tachyon component_action update_subscriptions >/dev/null 2>&1 &");
|
||||
command_status(command_from_args([ "/usr/bin/tachyon", "component_action_async", "update_subscriptions", "update" ]));
|
||||
status = true;
|
||||
msg = "Subscription update triggered";
|
||||
} else if (c == "reset_firewall") {
|
||||
|
||||
@@ -153,7 +153,7 @@ UCODE
|
||||
|
||||
lock_command="$(ucode -L "$LIB_DIR" "$SPAWN_UC")"
|
||||
# Opened the way procd opens it, in this shell, so the child inherits it.
|
||||
( eval "exec 1000>\"\$LOCK_FILE\""; eval "$lock_command"; sleep 0.4 )
|
||||
( eval "exec 1000>\"\$LOCK_FILE\""; eval "$lock_command"; sleep 1 )
|
||||
|
||||
lock_seen="$(tr -d ' \n' < "$LOCK_OUT")"
|
||||
[ "$lock_seen" = 0 ] \
|
||||
@@ -174,7 +174,7 @@ UCODE
|
||||
|
||||
pid_command="$(ucode -L "$LIB_DIR" "$SPAWN_UC")"
|
||||
eval "$pid_command" >/dev/null
|
||||
sleep 0.3
|
||||
sleep 1
|
||||
|
||||
pid="$(tr -d ' \n' < "$PID_OUT")"
|
||||
[ -n "$pid" ] || fail "background_command_with_pid wrote no pid"
|
||||
|
||||
@@ -22,7 +22,7 @@ classify() {
|
||||
|
||||
# Prints the classified types joined by '+' so a multi-fact line is one token.
|
||||
classify_joined() {
|
||||
classify "$1" | paste -sd '+' -
|
||||
classify "$1" | tr '\n' '+' | sed 's/+$//'
|
||||
}
|
||||
|
||||
assert_eq() {
|
||||
@@ -126,7 +126,7 @@ done
|
||||
run_case() {
|
||||
local body="$1"
|
||||
local tmp
|
||||
tmp="$(mktemp "${TMPDIR:-/tmp}/tachyon_ec_case.XXXXXX.uc")"
|
||||
tmp="$(mktemp "${TMPDIR:-/tmp}/tachyon_ec_case_XXXXXX")"
|
||||
{
|
||||
printf '%s\n' 'let events = require("core.events");'
|
||||
printf '%s\n' 'let ec = require("service.event_controller");'
|
||||
|
||||
@@ -52,7 +52,8 @@ done < <(find "$TACHYON_LIB" -name '*.uc' | sort)
|
||||
[ "$found" -eq 0 ] || fail "nested functions are used before their declaration (ucode does not hoist them)"
|
||||
|
||||
# The scan is only worth trusting if it fires on a known-bad file.
|
||||
canary="$(mktemp "${TMPDIR:-/tmp}/tachyon_fwd_canary.XXXXXX.uc")"
|
||||
canary="$(mktemp "${TMPDIR:-/tmp}/tachyon_fwd_canary_XXXXXX")"
|
||||
trap 'rm -f "$canary"' EXIT
|
||||
cat > "$canary" <<'EOF'
|
||||
function outer() {
|
||||
let self = {};
|
||||
@@ -63,14 +64,13 @@ function outer() {
|
||||
EOF
|
||||
[ -n "$(scan_forward_refs "$canary")" ] \
|
||||
|| { rm -f "$canary"; fail "the forward-reference scan does not detect a known-bad file"; }
|
||||
rm -f "$canary"
|
||||
|
||||
# ── 2. runtime invocation ───────────────────────────────────────────────────
|
||||
# Calling the handlers is what actually proves the bindings resolve. The probes
|
||||
# they drive touch nft and /proc, which do not exist in the test container, so
|
||||
# run_probe's isolation absorbs the failures — a null binding would still raise
|
||||
# "left-hand side is not a function" before any probe body runs.
|
||||
driver="$(mktemp "${TMPDIR:-/tmp}/tachyon_fwd.XXXXXX.uc")"
|
||||
driver="$(mktemp "${TMPDIR:-/tmp}/tachyon_fwd_XXXXXX")"
|
||||
cat > "$driver" <<'EOF'
|
||||
let events = require("core.events");
|
||||
let ec = require("service.event_controller");
|
||||
|
||||
@@ -37,7 +37,7 @@ set_line="$(grep -n "uci set dhcp.@dnsmasq\[0\].noresolv" "$WATCHDOG_UC" | cut -
|
||||
# watchdog.uc is a CLI module with no exports, so the function is lifted out of
|
||||
# the source verbatim — extracted, not copied, so a change to the logic changes
|
||||
# the test's subject too. The shell and uci calls are replaced by recorders.
|
||||
DNS_UC="$(mktemp "${TMPDIR:-/tmp}/tachyon_dns_idem.XXXXXX.uc")"
|
||||
DNS_UC="$(mktemp "${TMPDIR:-/tmp}/tachyon_dns_idem_XXXXXX")"
|
||||
trap 'rm -f "$DNS_UC"' EXIT
|
||||
|
||||
# The stubs go in first: ucode captures a closure's upvalues when the closure is
|
||||
|
||||
@@ -82,7 +82,7 @@ done
|
||||
# CLI module with no exports, so the ladder block is lifted out of the source
|
||||
# verbatim — extracted, not copied, so a change to the logic changes the test's
|
||||
# subject too.
|
||||
LADDER_UC="$(mktemp "${TMPDIR:-/tmp}/tachyon_ladder.XXXXXX.uc")"
|
||||
LADDER_UC="$(mktemp "${TMPDIR:-/tmp}/tachyon_ladder_XXXXXX")"
|
||||
trap 'rm -f "$LADDER_UC"' EXIT
|
||||
|
||||
sed -n '/^const ESCALATION_LIGHT/,/^}$/p;' "$WATCHDOG_UC" > "$LADDER_UC"
|
||||
|
||||
@@ -98,7 +98,7 @@ grep -qE 'standing down, WAN repair|standing down, sing-box restart' "$WATCHDOG_
|
||||
# watchdog.uc is a CLI module with no exports, so the block is lifted out of the
|
||||
# source verbatim — extracted, not copied, so a change to the logic changes the
|
||||
# test's subject too.
|
||||
SUPPRESS_UC="$(mktemp "${TMPDIR:-/tmp}/tachyon_suppress.XXXXXX.uc")"
|
||||
SUPPRESS_UC="$(mktemp "${TMPDIR:-/tmp}/tachyon_suppress_XXXXXX")"
|
||||
trap 'rm -f "$SUPPRESS_UC"' EXIT
|
||||
|
||||
# log_message, as_string, sprintf are module-level in watchdog.uc, outside the
|
||||
|
||||
@@ -263,7 +263,7 @@ ORPHAN_PROBE_PPID=""
|
||||
for _ in $(seq 1 20); do
|
||||
ORPHAN_PROBE_PPID="$(awk '/^PPid:/ { print $2 }' "/proc/$ORPHAN_PROBE_PID/status" 2>/dev/null || true)"
|
||||
[ -n "$ORPHAN_PROBE_PPID" ] && break
|
||||
sleep 0.05
|
||||
sleep 1
|
||||
done
|
||||
[ -n "$ORPHAN_PROBE_PPID" ] ||
|
||||
fail "failed to create an orphaned init.d probe fixture"
|
||||
|
||||
@@ -249,7 +249,7 @@ TACHYON_RT_TABLES="$WORK_DIR/rt_tables_upgrade" \
|
||||
# roll the new build back. The hook must give up on its own instead.
|
||||
cat >"$WORK_DIR/hanging-init" <<'SH'
|
||||
#!/usr/bin/env bash
|
||||
sleep 600
|
||||
sleep 5
|
||||
SH
|
||||
chmod 0755 "$WORK_DIR/hanging-init"
|
||||
: >"$WORK_DIR/rt_tables_hang"
|
||||
|
||||
@@ -224,7 +224,7 @@ state_ucode mark-pending-reload "$PENDING_RELOAD_FILE" "reload_busy"
|
||||
state_ucode run-pending-reload-if-requested "$PENDING_RELOAD_FILE" "$WORK_DIR/fake-init"
|
||||
for _ in $(seq 1 20); do
|
||||
[ -s "$TACHYON_FAKE_INIT_CAPTURE" ] && break
|
||||
sleep 0.1
|
||||
sleep 1
|
||||
done
|
||||
assert_eq "reload" \
|
||||
"$(cat "$TACHYON_FAKE_INIT_CAPTURE")" \
|
||||
|
||||
@@ -124,7 +124,7 @@ for _ in $(seq 1 30); do
|
||||
if JSON_VALUE="$final_status" node -e 'process.exit(JSON.parse(process.env.JSON_VALUE).running ? 1 : 0)' >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
sleep 1
|
||||
done
|
||||
|
||||
JSON_VALUE="$final_status" node - <<'NODE'
|
||||
|
||||
Reference in New Issue
Block a user