Skip to content

Commit

Permalink
Fix 5.4.z PR builder (#832)
Browse files Browse the repository at this point in the history
When #816 was
backported in
67da84b,
a conflict caused some functions to go missing
  • Loading branch information
JackPGreen authored Nov 21, 2024
1 parent 574a3b7 commit 2658f69
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 51 deletions.
87 changes: 87 additions & 0 deletions .github/scripts/abstract-simple-smoke-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail ${RUNNER_DEBUG:+-x}

# Performs simple validation tests on an already-running Hazelcast instance
# Abstract as could be from Docker, Homebrew, local binary etc
# Because abstract, expects callers to implement required, but absent functions
function test_package() {
local expected_distribution_type=$1
local expected_version=$2

test_health
test_map_read_write

# Deliberately last step as it doesn't block-and-wait until the instance is initialized
# Otherwise would have false positives if instance still starting and logs empty
check_metadata "${expected_distribution_type}" "${expected_version}"
}

# Search logs for entries _like_:
# Hazelcast Platform 5.5.0 (20240725) starting at [172.17.0.2]:5701
# To validate the version and distribution is correct
function check_metadata() {
local expected_distribution_type=$1
local expected_version=$2

logs=$(get_hz_logs)

if [[ -z "${logs}" ]]; then
echoerr "Failed to read logs"
exit 1;
fi

if grep -q "${expected_distribution_type} ${expected_version}" <<< "${logs}"; then
echo "Expected contents (${expected_distribution_type}) and version (${expected_version}) identified."
else
echoerr "Failed to find ${expected_distribution_type} ${expected_version} in logs:"
echoerr "${logs}"
exit 1;
fi
}

function test_health() {
local attempts=0
local max_attempts=30
until curl --silent --fail "127.0.0.1:5701/hazelcast/health/ready"; do
if [[ ${attempts} -eq ${max_attempts} ]];then
echoerr "Hazelcast not responding"
exit 1;
fi
printf '.'
attempts=$((attempts+1))
sleep 2
done
}

function test_map_read_write() {
install_clc

local key="some-key"
local expected="some-value"
echo "Putting value '${expected}' for key '${key}'"
clc --timeout 5s map set -n some-map "${key}" "${expected}" --log.path stderr
echo "Getting value for key '${key}'"
local actual
actual=$(clc map get --format delimited -n some-map "${key}" --log.path stderr)

if [[ "${expected}" != "${actual}" ]]; then
echoerr "Expected to read '${expected}' but got '${actual}'"
exit 1;
fi
}

function install_clc() {
while ! curl https://hazelcast.com/clc/install.sh | bash
do
echo "Retrying clc installation..."
sleep 3
done
export PATH=${PATH}:${HOME}/.hazelcast/bin
clc config add default cluster.name=dev cluster.address=localhost
}

# Prints the given message to stderr
function echoerr() {
echo "::error::ERROR - $*" 1>&2;
}
63 changes: 12 additions & 51 deletions .github/scripts/simple-smoke-test.sh
Original file line number Diff line number Diff line change
@@ -1,62 +1,23 @@
#!/usr/bin/env bash

set -e
set -o pipefail
set -o errexit ${RUNNER_DEBUG:+-x}

function test_docker_image() {
local image=$1
local container_name=$2
local expected_distribution_type=$3
# shellcheck source=../.github/scripts/abstract-simple-smoke-test.sh
. .github/scripts/abstract-simple-smoke-test.sh

if [ "$(docker ps --all --quiet --filter name="$container_name")" ]; then
echo "Removing existing '$container_name' container"
docker container rm --force "$container_name"
fi

echo "Checking if $image is EE"
if docker run --rm $image bash -c 'compgen -G lib/*enterprise*'; then
echo "EE contents identified"
distribution_type="ee"
else
echo "No EE contents identified - assuming OSS"
distribution_type="oss"
fi

if [[ "$distribution_type" != "$expected_distribution_type" ]]; then
echo "Distribution was $distribution_type, not $expected_distribution_type as expected"
exit 1
fi
function remove_container_if_exists() {
local containers
containers=$(docker ps --all --quiet --filter name="${container_name}")

echo "Starting container '$container_name' from image '$image'"
docker run -it --name "$container_name" -e HZ_LICENSEKEY -e HZ_INSTANCETRACKING_FILENAME -d -p5701:5701 "$image"
local key="some-key"
local expected="some-value"
echo "Putting value '$expected' for key '$key'"
while ! clc --timeout 5s map set -n some-map $key $expected --log.path stderr
do
echo "Retrying..."
sleep 3
done
echo "Getting value for key '$key'"
local actual
actual=$(clc map get --format delimited -n some-map $key --log.path stderr)
echo "Stopping container $container_name}"
docker stop "$container_name"

if [ "$expected" != "$actual" ]; then
echo "Expected to read '${expected}' but got '${actual}'"
exit 1;
if [[ -n "${containers}" ]]; then
echo "Removing existing '${container_name}' container"
docker container rm --force "${container_name}"
fi
}

function install_clc() {
while ! curl https://hazelcast.com/clc/install.sh | bash
do
echo "Retrying clc installation..."
sleep 3
done
export PATH=$PATH:$HOME/.hazelcast/bin
clc config add default cluster.name=dev cluster.address=localhost
function start_container() {
echo "Starting container '${container_name}' from image '${image}'"
docker run -it --name "${container_name}" -e HZ_LICENSEKEY -e HZ_INSTANCETRACKING_FILENAME -d -p5701:5701 "${image}"
}

function get_hz_logs() {
Expand Down

0 comments on commit 2658f69

Please sign in to comment.