Skip to content

Commit

Permalink
example/test: Reduce sleep duration
Browse files Browse the repository at this point in the history
Crank up the heartbeat interval to reduce the total test runtime

Signed-off-by: Wesley Hershberger <[email protected]>
  • Loading branch information
MggMuggins committed Jul 31, 2024
1 parent f0e91ec commit 423cad9
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions example/test/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if [ -n "${DEBUG:-}" ]; then
fi

if [ -n "${CLUSTER_VERBOSE:-}" ]; then
set -x
cluster_flags+=("--verbose")
fi

Expand All @@ -23,10 +24,12 @@ new_systems() {
rm -r "${test_dir}"
fi

microd_args=("${@}")

for member in $(seq --format c%g "${1}"); do
state_dir="${test_dir}/${member}"
mkdir -p "${state_dir}"
microd --state-dir "${state_dir}" "${cluster_flags[@]}" &
microd --state-dir "${state_dir}" "${cluster_flags[@]}" "${microd_args[@]:2}" &
microctl --state-dir "${state_dir}" waitready
done
}
Expand Down Expand Up @@ -76,7 +79,7 @@ shutdown_systems() {
}

test_misc() {
new_systems 2
new_systems 2 --heartbeat 2s

# Ensure two daemons cannot start in the same state dir
! microd --state-dir "${test_dir}/c1" "${cluster_flags[@]}" || false
Expand All @@ -94,17 +97,16 @@ test_misc() {
}

test_tokens() {
new_systems 3
new_systems 3 --heartbeat 4s
bootstrap_systems

microctl --state-dir "${test_dir}/c1" tokens add default_expiry

microctl --state-dir "${test_dir}/c1" tokens add short_expiry --expire-after 5s
microctl --state-dir "${test_dir}/c1" tokens add short_expiry --expire-after 1s

microctl --state-dir "${test_dir}/c1" tokens add long_expiry --expire-after 400h

# Need at least one heartbeat (every 10s)
sleep 15
sleep 1

! microctl --state-dir "${test_dir}/c1" tokens list --format csv | grep -q short_expiry || false
microctl --state-dir "${test_dir}/c1" tokens list --format csv | grep -q default_expiry
Expand All @@ -115,18 +117,17 @@ test_tokens() {
microd --state-dir "${test_dir}/c4" "${cluster_flags[@]}" &
microctl --state-dir "${test_dir}/c4" waitready

# Assumes that heartbeats are 10s apart
token=$(microctl --state-dir "${test_dir}/c1" tokens add "c4" --expire-after 12s)
token=$(microctl --state-dir "${test_dir}/c1" tokens add "c4" --expire-after 1s)

sleep 12
sleep 1

! microctl --state-dir "${test_dir}/c4" init "c4" "127.0.0.1:9005" --token "${token}" || false

shutdown_systems
}

test_recover() {
new_systems 5
new_systems 5 --heartbeat 2s
bootstrap_systems
shutdown_systems

Expand All @@ -149,11 +150,12 @@ test_recover() {

for member in c1 c2; do
state_dir="${test_dir}/${member}"
microd --state-dir "${state_dir}" "${cluster_flags[@]}" > /dev/null &
microd --state-dir "${state_dir}" "${cluster_flags[@]}" --heartbeat 2s &
done
microctl --state-dir "${test_dir}/c1" waitready

# microcluster takes a long time to update the member roles in the core_cluster_members table
sleep 90
# Allow for a round of heartbeats to update the member roles in core_cluster_members
sleep 3

microctl --state-dir "${test_dir}/c1" cluster list

Expand Down

0 comments on commit 423cad9

Please sign in to comment.