From e7649063f09c2386e03f79942e3f5e2aabc1d80d Mon Sep 17 00:00:00 2001 From: Rolv Apneseth Date: Thu, 25 Jun 2026 15:37:06 +0100 Subject: [PATCH] test/system: Ensure that the local temporary Docker registry is ready ... before proceeding to avoid potential races. Some changes by Debarshi Ray. https://github.com/containers/toolbox/pull/1811 https://github.com/containers/toolbox/pull/1817 Signed-off-by: Rolv Apneseth --- test/system/libs/helpers.bash | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index e47640655..18d0329b4 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -204,6 +204,8 @@ function _setup_docker_registry() { "${IMAGES[docker-reg]}" assert_success + _wait_for_docker_registry + run podman login \ --authfile "${BATS_SUITE_TMPDIR}/authfile.json" \ --username user \ @@ -223,6 +225,53 @@ function _setup_docker_registry() { } +function _wait_for_docker_registry() { + local error_details + local error_message + local -i max_retries=30 + local -i ret_val=1 + local -i retries + + for ((retries = 0; retries < max_retries; retries++)); do + ret_val=0 + error_details="$( (timeout 5s openssl s_client \ + -CAfile "$DOCKER_REG_CERTS_DIR/domain.crt" \ + -connect "$DOCKER_REG_URI" /dev/null) 2>&1)" || ret_val="$?" + + if [ "$ret_val" -eq 0 ]; then + break + elif [ "$ret_val" -eq 125 ]; then + error_message="timeout(1) failed" + break + elif [ "$ret_val" -eq 126 ]; then + error_message="Failed to invoke openssl(1) or timeout(1)" + break + elif [ "$ret_val" -eq 127 ]; then + error_message="openssl(1) not found" + break + elif [ "$ret_val" -eq 137 ]; then + error_message="SIGKILL received by openssl(1) or timeout(1)" + break + fi + + sleep 1s + done + + if [ "$ret_val" -ne 0 ]; then + if [ "$retries" -eq "$max_retries" ]; then + error_message="Docker registry at $DOCKER_REG_URI did not reach a ready state" + fi + + echo "$error_message" >&2 + if [ "$error_details" != "" ]; then + echo "$error_details" >&2 + fi + fi + + return "$ret_val" +} + + # Stop, removes and cleans after a locally hosted Docker registry function _clean_docker_registry() { # Stop Docker registry container