test env: a node with a deliberately wrong clock, via the flake
Exercising the timestamp bound in `p2p::wire_time` needs a peer whose clock is actually wrong, and the honest way to get one is to move the whole process's wall clock — so the peer's signed gossip `announced_at_secs` and every `modified_at` it writes are wrong together, which is the real failure rather than a simulation of one. libfaketime comes from the flake's devShell rather than a system package, so the scenario reproduces on any machine with the flake and is pinned to the same nixpkgs as everything else. The recipe builds first and fakes only the built binary: running cargo itself under a future clock would corrupt its mtime-based freshness check. `-m` selects libfaketime's thread-safe build, since the daemon is thoroughly multi-threaded, and FAKETIME_DONT_FAKE_MONOTONIC keeps QUIC's own timers on the real monotonic clock — without it iroh's timeouts move too and the nodes fail to connect for reasons unrelated to the test.
This commit is contained in:
@@ -220,6 +220,13 @@
|
||||
pkgs.just
|
||||
# `just extension build` packages the browser extension with it.
|
||||
pkgs.zip
|
||||
# `just test-env-daemon-b-skewed` runs a test node under a
|
||||
# deliberately wrong wall clock, to exercise the timestamp bound in
|
||||
# `p2p::wire_time` and the peer-health reporting built on it. Here
|
||||
# rather than as a system package so the scenario is reproducible
|
||||
# on any machine with the flake, and pinned to the same nixpkgs as
|
||||
# everything else.
|
||||
pkgs.libfaketime
|
||||
] ++ commonArgs.buildInputs ++ guiBuildInputs;
|
||||
|
||||
# gpui dlopen()s wayland/X11/Vulkan/ALSA at runtime rather than
|
||||
|
||||
@@ -486,6 +486,47 @@ test-env-daemon-a dir="test-nodes":
|
||||
test-env-daemon-b dir="test-nodes":
|
||||
just daemon-cli --store {{dir}}/node_b
|
||||
|
||||
# Start test node_b with a deliberately wrong wall clock, to exercise the
|
||||
# timestamp bound in `p2p::wire_time` and the peer-health reporting built on it.
|
||||
#
|
||||
# `offset` is libfaketime's own syntax: "+3d" puts node_b three days into the
|
||||
# future, past the 24h bound, so node_a drops everything node_b writes and its
|
||||
# roster row says why. "+13h" lands between the warning threshold and the bound
|
||||
# — still merging, but reported. A negative offset ("-3d") is the harmless case
|
||||
# the bound deliberately does not police: a stamp in the past loses every
|
||||
# comparison it takes part in, so node_a should say nothing at all.
|
||||
#
|
||||
# Three details this gets right that a narrower fake would not:
|
||||
# * It skews the whole process, so node_b's signed gossip `announced_at_secs`
|
||||
# *and* every `modified_at` it writes are wrong together — which is the real
|
||||
# failure rather than a simulation of one.
|
||||
# * It builds first and fakes only the built binary. Running `cargo` itself
|
||||
# under a future clock would corrupt its mtime-based freshness check and
|
||||
# silently mis-decide what to rebuild.
|
||||
# * `-m` selects libfaketime's thread-safe build (the daemon is tokio, i.e.
|
||||
# thoroughly multi-threaded), and FAKETIME_DONT_FAKE_MONOTONIC keeps QUIC's
|
||||
# own timers on the real monotonic clock — without it iroh's timeouts move
|
||||
# too and the nodes fail to connect for reasons unrelated to the test.
|
||||
#
|
||||
# libfaketime comes from the flake (devShells.default), so this needs no system
|
||||
# package; it falls back to one on PATH for a machine without Nix.
|
||||
[group: "dev"]
|
||||
[env("RUST_LOG", "info")]
|
||||
test-env-daemon-b-skewed dir="test-nodes" offset="+3d":
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
cd rust && cargo build --bin syn-cli && cd ..
|
||||
run=(faketime -m "{{offset}}" rust/target/debug/syn-cli daemon --foreground --store "{{dir}}/node_b")
|
||||
export FAKETIME_DONT_FAKE_MONOTONIC=1
|
||||
if command -v faketime >/dev/null 2>&1; then
|
||||
exec "${run[@]}"
|
||||
elif command -v nix >/dev/null 2>&1; then
|
||||
exec nix develop -c "${run[@]}"
|
||||
else
|
||||
echo "Need libfaketime: run this from \`nix develop\`, or install it (Arch: pacman -S libfaketime)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Cap the size of rust/target/ instead of periodically `cargo clean`-ing it.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user