mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
The clients, gateway and relay all employ an internal design that is based on an eventloop. This gives us a lot of control in how various IO components interact with each other. Great control also comes with a source of bugs, the latest of which made the relay busy-loop once it started relaying some traffic. Eventloops are notoriously hard to unit-test because they compose various IO bits together. Instead of writing unit tests, we can go and assert the process state after the performance tests. Those generate a fair bit of load on all our components but after that, they should suspend. The most effective tests survive even large refactorings and for that, they need to be coded against a stable API / property. Asserting that the process sleeps when it is idle from an application PoV is such a property. Related: #4511.
59 lines
1.4 KiB
Bash
Executable File
59 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
function client() {
|
|
docker compose exec -it client "$@"
|
|
}
|
|
|
|
function gateway() {
|
|
docker compose exec -it gateway "$@"
|
|
}
|
|
|
|
function install_iptables_drop_rules() {
|
|
sudo iptables -I FORWARD 1 -s 172.28.0.100 -d 172.28.0.105 -j DROP
|
|
sudo iptables -I FORWARD 1 -s 172.28.0.105 -d 172.28.0.100 -j DROP
|
|
trap remove_iptables_drop_rules EXIT # Cleanup after us
|
|
}
|
|
|
|
function remove_iptables_drop_rules() {
|
|
sudo iptables -D FORWARD -s 172.28.0.100 -d 172.28.0.105 -j DROP
|
|
sudo iptables -D FORWARD -s 172.28.0.105 -d 172.28.0.100 -j DROP
|
|
}
|
|
|
|
function client_curl_resource() {
|
|
client curl --fail "$1"
|
|
}
|
|
|
|
function client_ping_resource() {
|
|
client timeout 30 \
|
|
sh -c "until ping -W 1 -c 1 $1 &>/dev/null; do true; done"
|
|
}
|
|
|
|
function client_nslookup() {
|
|
# Skip the first 3 lines so that grep won't see the DNS server IP
|
|
# `tee` here copies stdout to stderr
|
|
client timeout 30 sh -c "nslookup $1 | tee >(cat 1>&2) | tail -n +4"
|
|
}
|
|
|
|
function assert_equals() {
|
|
local expected="$1"
|
|
local actual="$2"
|
|
|
|
if [[ "$expected" != "$actual" ]]; then
|
|
echo "Expected $expected but got $actual"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function process_state() {
|
|
local process_name="$1"
|
|
|
|
ps -C "$process_name" -o state=
|
|
}
|
|
|
|
function assert_process_state {
|
|
local process_name="$1"
|
|
local expected_state="$2"
|
|
|
|
assert_equals "$(process_state "$process_name")" "$expected_state"
|
|
}
|