Skip to content

Commit

Permalink
Fix clean-start check
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Jan 17, 2025
1 parent 5840b94 commit 20f5469
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 23 additions & 7 deletions bin/lib.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env bash
set -Eeu

echo_versioner_env_vars()
{
Expand Down Expand Up @@ -130,24 +128,42 @@ exit_non_zero_unless_started_cleanly()
# Handle known warnings (eg waiting on Gem upgrade)
# local -r SHADOW_WARNING="server.rb:(.*): warning: shadowing outer local variable - filename"
# DOCKER_LOG=$(strip_known_warning "${DOCKER_LOG}" "${SHADOW_WARNING}")

local -r SERVICE_NAME="${1}"
echo
echo "Checking if ${SERVICE_NAME} started cleanly."
if [ "$(top_5)" != "$(clean_top_5)" ]; then

local -r DOCKER_LOG=$(docker logs "${CONTAINER_NAME}" 2>&1)
local -r top_5=$(echo "${DOCKER_LOG}" | head -5)

if ! array_prefix "$(clean_top_5)" "${top_5}" ; then
echo "${SERVICE_NAME} did not start cleanly: docker log..."
echo 'expected------------------'
echo "$(clean_top_5)"
clean_top_5
echo
echo 'actual--------------------'
echo "$(top_5)"
echo "${top_5}"
echo
echo 'diff--------------------'
grep -Fxvf <(clean_top_5) <(top_5)
grep -Fxvf <(clean_top_5) <(echo "${top_5}")
echo
exit 42
fi
}

array_prefix()
{
readarray -t expected_lines <<<"${1}"
readarray -t actual_lines <<<"${2}"
for i in {0..4}
do
if ! [[ "${actual_lines[$i]}" =~ ^"${expected_lines[$i]}" ]] ; then
return 1 # false
fi
done
return 0 # true
}

top_5()
{
docker logs "${CONTAINER_NAME}" 2>&1 | head -5
Expand All @@ -158,7 +174,7 @@ clean_top_5()
# 1st 5 lines on Puma
local -r L1="Puma starting in single mode..."
local -r L2='* Puma version: 6.5.0 ("Sky'"'"'s Version")'
local -r L3='* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux-musl]'
local -r L3='* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f)' # [x86_64-linux-musl]
local -r L4="* Min threads: 0"
local -r L5="* Max threads: 5"
#
Expand Down
2 changes: 1 addition & 1 deletion bin/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -Eeu

export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
Expand Down

0 comments on commit 20f5469

Please sign in to comment.