From 13e48c769d8027cfbd62a5c87c8cb1bbcfc10a85 Mon Sep 17 00:00:00 2001 From: Mark Mennell Date: Sat, 11 Apr 2026 17:14:01 +0800 Subject: [PATCH] wait on message instead of sleep --- docker/postgres/init/002-fmsgd-dd.sql | 1 + test/tests/001-send-message.sh | 8 +++----- test/tests/002-reply-message.sh | 8 +++----- test/tests/003-reply-invalid-pid.sh | 1 - test/tests/004-add-to-recipient.sh | 11 +++-------- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/docker/postgres/init/002-fmsgd-dd.sql b/docker/postgres/init/002-fmsgd-dd.sql index d25ebe3..5081af4 100644 --- a/docker/postgres/init/002-fmsgd-dd.sql +++ b/docker/postgres/init/002-fmsgd-dd.sql @@ -85,3 +85,4 @@ drop trigger if exists trg_msg_add_to_insert on msg_add_to; create trigger trg_msg_add_to_insert after insert on msg_add_to for each row execute function notify_msg_to_insert(); + diff --git a/test/tests/001-send-message.sh b/test/tests/001-send-message.sh index 2ff8fa8..9f57a75 100644 --- a/test/tests/001-send-message.sh +++ b/test/tests/001-send-message.sh @@ -6,16 +6,14 @@ set -euo pipefail echo " Sending message: @alice@hairpin.local → @bob@example.com" export FMSG_API_URL="$HAIRPIN_API_URL" printf '@alice@hairpin.local\n' | fmsg login -sleep 3 fmsg send '@bob@example.com' "Hello Bob, this is an integration test." echo " Waiting for cross-instance delivery..." -sleep 5 - -echo " Reading messages as @bob@example.com" export FMSG_API_URL="$EXAMPLE_API_URL" printf '@bob@example.com\n' | fmsg login -sleep 3 +fmsg wait --timeout 15 >/dev/null + +echo " Reading messages as @bob@example.com" MSG_OUTPUT=$(fmsg list) echo "$MSG_OUTPUT" diff --git a/test/tests/002-reply-message.sh b/test/tests/002-reply-message.sh index a93d371..d3f6df6 100644 --- a/test/tests/002-reply-message.sh +++ b/test/tests/002-reply-message.sh @@ -6,16 +6,14 @@ set -euo pipefail echo " Sending reply: @bob@example.com → @alice@hairpin.local (pid 1)" export FMSG_API_URL="$EXAMPLE_API_URL" printf '@bob@example.com\n' | fmsg login -sleep 3 fmsg send --pid 1 '@alice@hairpin.local' "Hey there Alice, got your message!" echo " Waiting for cross-instance delivery..." -sleep 5 - -echo " Reading messages as @alice@hairpin.local" export FMSG_API_URL="$HAIRPIN_API_URL" printf '@alice@hairpin.local\n' | fmsg login -sleep 3 +fmsg wait --timeout 15 >/dev/null + +echo " Reading messages as @alice@hairpin.local" MSG_OUTPUT=$(fmsg list) echo "$MSG_OUTPUT" diff --git a/test/tests/003-reply-invalid-pid.sh b/test/tests/003-reply-invalid-pid.sh index 97103d0..d91a6c1 100644 --- a/test/tests/003-reply-invalid-pid.sh +++ b/test/tests/003-reply-invalid-pid.sh @@ -5,7 +5,6 @@ set -euo pipefail echo " Sending reply with invalid pid 99: @bob@example.com → @alice@hairpin.local" export FMSG_API_URL="$EXAMPLE_API_URL" printf '@bob@example.com\n' | fmsg login -sleep 3 if fmsg send --pid 99 '@alice@hairpin.local' "This should fail" 2>/dev/null; then echo " FAIL: send with invalid pid 99 succeeded but should have failed" diff --git a/test/tests/004-add-to-recipient.sh b/test/tests/004-add-to-recipient.sh index 8ad6173..005be67 100644 --- a/test/tests/004-add-to-recipient.sh +++ b/test/tests/004-add-to-recipient.sh @@ -7,12 +7,8 @@ set -euo pipefail echo " Sending initial message: @alice@hairpin.local → @bob@example.com" export FMSG_API_URL="$HAIRPIN_API_URL" printf '@alice@hairpin.local\n' | fmsg login -sleep 3 fmsg send '@bob@example.com' "Hello Bob, this is the add-to integration test." -echo " Waiting for delivery..." -sleep 3 - echo " Getting message ID from alice's sent messages" MSG_ID=$(fmsg list | grep -oE '\b[0-9]+\b' | head -1) if [ -z "$MSG_ID" ]; then @@ -25,12 +21,11 @@ echo " Adding @carol@example.com as recipient via add-to $MSG_ID" fmsg add-to "$MSG_ID" '@carol@example.com' echo " Waiting for cross-instance delivery..." -sleep 3 - -echo " Reading messages as @carol@example.com" export FMSG_API_URL="$EXAMPLE_API_URL" printf '@carol@example.com\n' | fmsg login -sleep 3 +fmsg wait --timeout 15 >/dev/null + +echo " Reading messages as @carol@example.com" MSG_OUTPUT=$(fmsg list) echo "$MSG_OUTPUT"