-
Notifications
You must be signed in to change notification settings - Fork 258
test/system: Ensure that the local temporary Docker registry is ready #1817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 j | ||
| local -i num_of_retries=30 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this should be |
||
| local -i ret_val=1 | ||
|
|
||
| for ((j = 0; j < num_of_retries; j++)); do | ||
| ret_val=0 | ||
| error_details="$( (timeout 5s openssl s_client \ | ||
| -CAfile "$DOCKER_REG_CERTS_DIR/domain.crt" \ | ||
| -connect "$DOCKER_REG_URI" </dev/null >/dev/null) 2>&1)" || ret_val="$?" | ||
|
Comment on lines
+237
to
+239
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The double subshell |
||
|
|
||
| if [ "$ret_val" -eq 0 ]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this is a little easier to read as a case statement? Something like WDYT? |
||
| 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 1 | ||
| done | ||
|
|
||
| if [ "$ret_val" -ne 0 ]; then | ||
| if [ "$j" -eq "$num_of_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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure robust error handling and maintain consistency with the rest of the
_setup_docker_registryfunction (where all commands are executed using BATS'runand verified withassert_success), we should execute_wait_for_docker_registryusingrunand assert its success. This guarantees that if the registry fails to reach a ready state, the test suite setup will fail immediately and cleanly with a clear error report.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional.
First, using only
runandassert_successis an anti-pattern. We shouldn't be doing that.Second, until recently
run --separate-stderrdidn't work or had undefined behaviour insidesetup_suite()because BATS_TEST_TMPDIR isn't defined. Usingrunin this function used insetup_suite()takes us closer to using some feature ofrunthat doesn't work.