Skip to content

Commit

Permalink
Fix pagila RPM url and wait patiently for the server start
Browse files Browse the repository at this point in the history
Previous epel7 mirror URL does not work after RHEL7 EOL, but the same
RPM is still available in koji. A test for a correct download should
hopefully make the download failure easier to debug in the future.

The check functions did not actually wait when the first podman exec
failed, so in case the server was not up soon, the check failed too
early. It is ok to wait for the server a bit, so let's repeat the
podman exec with psql until it succeeds or 30s pass.
  • Loading branch information
hhorak authored and phracek committed Sep 4, 2024
1 parent 7758a90 commit b7f073f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
6 changes: 3 additions & 3 deletions test/pagila.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ die() { echo "$*" >&2 ; exit 1; }
test -z "$CID" && die "Please specify \$CID variable"
# test -d common || die "Please run me from git root directory"

pagila_mirror=https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/
pagila_koji=https://kojipkgs.fedoraproject.org//packages/pagila/0.10.1/3.el7/noarch/
pagila_base="pagila-0.10.1-3.el7.noarch.rpm"
pagila=$pagila_mirror$pagila_base
pagila=$pagila_koji$pagila_base
pagila_file="$PWD/postgresql-container-pagila.sql"
pagila_sha256sum=b968d9498d866bff8f47d9e50edf49feeff108d4164bff2aa167dc3eae802701

Expand All @@ -20,7 +20,7 @@ pagila_sha256sum=b968d9498d866bff8f47d9e50edf49feeff108d4164bff2aa167dc3eae80270
test ! -f "$pagila_file" || exit 0

set -o pipefail
curl -s "$pagila" > "$pagila_base"
curl -s "$pagila" > "$pagila_base" || die "ERROR: Could not download $pagila"
for file in ./usr/share/pagila/pagila-schema.sql \
./usr/share/pagila/pagila-data.sql \
./usr/share/pagila/pagila-insert-data.sql ; \
Expand Down
29 changes: 20 additions & 9 deletions test/pg-test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ data_pagila_check ()
2'
# Deliberately moving heredoc into the container, otherwise it does not work
# in podman 1.6.x due to https://bugzilla.redhat.com/show_bug.cgi?id=1827324
local output=$(docker exec -i "$CID" bash -c "psql -tA <<EOF
SECONDS=15
local output
while [ $SECONDS -gt 0 ] ; do
output=$(docker exec -i "$CID" bash -c "psql -tA <<EOF
select count(*) from information_schema.tables where table_schema = 'public';
select count(*) from information_schema.triggers;
select count(*) from staff;
EOF"
EOF" 2>/dev/null || :
)
test "$exp_output" = "$output" \
|| error "Unexpected output: '$output', expected: '$exp_output'"
test "$exp_output" = "$output" && return
sleep 1
done
error "Unexpected output: '$output', expected: '$exp_output', and/or we waited too long"
}

data_empty_create ()
Expand All @@ -82,11 +87,17 @@ data_empty_check ()
3'
# Deliberately moving heredoc into the container, otherwise it does not work
# in podman 1.6.x due to https://bugzilla.redhat.com/show_bug.cgi?id=1827324
local output=$(docker exec -i "$CID" bash -c "psql -tA <<EOF
SECONDS=15
local output
while [ $SECONDS -gt 0 ] ; do
output=$(docker exec -i "$CID" bash -c "psql -tA <<EOF
select * from blah order by id;
EOF"
EOF" 2>/dev/null || :
)
test "$exp_output" = "$output" || error "Unexpected output '$output'"
test "$exp_output" = "$output" && return
sleep 1
done
error "Unexpected output '$output', expected: '$exp_output', and/or we waited too long"
}

# wait_for_postgres CID
Expand All @@ -105,9 +116,9 @@ wait_for_postgres ()
output=$(docker exec -i "$cid" bash -c \
"psql -h localhost -tA -c 'select 1;' 2>/dev/null || :")
case $output in
1*) return ;;
1*) debug "server up" ; return ;;
"") ;;
*) echo "$output" ; false ;;
*) debug "server down" ; echo "$output" ; false ;;
esac
sleep 1
counter=$(( counter + 1 ))
Expand Down
1 change: 1 addition & 0 deletions test/run_upgrade_test
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ background_container ()
{
CID=$(eval "docker run -d $2 $1 $3")
test -n "$CID"
info "Started container $CID" >&2
}

# run_server DATADIR IMAGE_ID DOCKER_ARGS
Expand Down

0 comments on commit b7f073f

Please sign in to comment.