From da5b281b96cedde6c5c8fb15b090bc54e8e0e95a Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Mon, 21 Oct 2024 11:58:32 +0200 Subject: [PATCH] ci: add regression test for boot race condition If two instances start up at the same time, they end up with different keys on both ends. Test this with different delays of 2 (working), 1 (flaky) and 0 (broken) seconds. Signed-off-by: Paul Spooren --- .ci/boot_race/a.toml | 14 +++++++++ .ci/boot_race/b.toml | 14 +++++++++ .ci/boot_race/run.sh | 48 +++++++++++++++++++++++++++++++ .github/workflows/regressions.yml | 12 ++++++++ 4 files changed, 88 insertions(+) create mode 100644 .ci/boot_race/a.toml create mode 100644 .ci/boot_race/b.toml create mode 100644 .ci/boot_race/run.sh diff --git a/.ci/boot_race/a.toml b/.ci/boot_race/a.toml new file mode 100644 index 00000000..d8e69fc1 --- /dev/null +++ b/.ci/boot_race/a.toml @@ -0,0 +1,14 @@ +public_key = "rp-a-public-key" +secret_key = "rp-a-secret-key" +listen = ["127.0.0.1:9999"] +verbosity = "Verbose" + +[api] +listen_path = [] +listen_fd = [] +stream_fd = [] + +[[peers]] +public_key = "rp-b-public-key" +endpoint = "127.0.0.1:9998" +key_out = "rp-b-key-out.txt" diff --git a/.ci/boot_race/b.toml b/.ci/boot_race/b.toml new file mode 100644 index 00000000..b7609759 --- /dev/null +++ b/.ci/boot_race/b.toml @@ -0,0 +1,14 @@ +public_key = "rp-b-public-key" +secret_key = "rp-b-secret-key" +listen = ["127.0.0.1:9998"] +verbosity = "Verbose" + +[api] +listen_path = [] +listen_fd = [] +stream_fd = [] + +[[peers]] +public_key = "rp-a-public-key" +endpoint = "127.0.0.1:9999" +key_out = "rp-a-key-out.txt" diff --git a/.ci/boot_race/run.sh b/.ci/boot_race/run.sh new file mode 100644 index 00000000..4df21f0c --- /dev/null +++ b/.ci/boot_race/run.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +iterations="$1" +sleep_time="$2" +config_a="$3" +config_b="$4" + +PWD="$(pwd)" +EXEC="$PWD/target/release/rosenpass" + +i=0 +while [ "$i" -ne "$iterations" ]; do + echo "=> Iteration $i" + + # flush the PSK files + echo "A" >rp-a-key-out.txt + echo "B" >rp-b-key-out.txt + + # start the two instances + echo "Starting instance A" + "$EXEC" exchange-config "$config_a" & + PID_A=$! + sleep "$sleep_time" + echo "Starting instance B" + "$EXEC" exchange-config "$config_b" & + PID_B=$! + + # give the key exchange some time to complete + sleep 3 + + # kill the instances + kill $PID_A + kill $PID_B + + # compare the keys + if cmp -s rp-a-key-out.txt rp-b-key-out.txt; then + echo "Keys match" + else + echo "::warning title=Key Exchange Race Condition::The key exchange resulted in different keys. Delay was ${sleep_time}s." + # TODO: set this to 1 when the race condition is fixed + exit 0 + fi + + # give the instances some time to shut down + sleep 2 + + i=$((i + 1)) +done diff --git a/.github/workflows/regressions.yml b/.github/workflows/regressions.yml index 53c45bdc..632a36f5 100644 --- a/.github/workflows/regressions.yml +++ b/.github/workflows/regressions.yml @@ -23,3 +23,15 @@ jobs: - run: .ci/run-regression.sh 100 20 - run: | [ $(ls -1 output/ate/out | wc -l) -eq 100 ] + + boot-race: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: cargo build --bin rosenpass --release + - run: chmod +x .ci/boot_race/run.sh + - run: cargo run --release --bin rosenpass gen-keys .ci/boot_race/a.toml + - run: cargo run --release --bin rosenpass gen-keys .ci/boot_race/b.toml + - run: .ci/boot_race/run.sh 5 2 .ci/boot_race/a.toml .ci/boot_race/b.toml + - run: .ci/boot_race/run.sh 5 1 .ci/boot_race/a.toml .ci/boot_race/b.toml + - run: .ci/boot_race/run.sh 5 0 .ci/boot_race/a.toml .ci/boot_race/b.toml