-
Notifications
You must be signed in to change notification settings - Fork 767
Add port monitoring test script #4077
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
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 |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # SPDX-FileCopyrightText: Copyright The Lima Authors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # This test verifies that when a container is destroyed, its ports can be reused | ||
| # immediately and are not subject to being freed by a polling loop. See #4066. | ||
|
|
||
| # This test should not be run in CI as it is not totally reliable: there is always a chance that the server will | ||
| # take longer to actually respond to requests after opening the port. The test works around it by retrying once | ||
| # on curl exit code 52, but have been observed at least once to fail by refusing to connect. | ||
|
|
||
| load "../helpers/load" | ||
|
|
||
| : "${TEMPLATE:=default}" # Alternative: "docker" | ||
|
Member
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. Should this be part of Anyway we should establish the criteria to clarify what should be in test-templates and what else should be in bats.
Member
Author
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.
I think we should, but it will take some time. Until then we can run them in parallel. New tests should be in BATS, I think, if possible with reasonable effort. I don't have the time to rework the whole test-suite at once, but will add a little bit whenever I have some extra time.
Member
Author
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 reason this particular test has a Potentially it could be extended to run with rootful containerd/docker, but I didn't think that was necessary. When we have more tests we can figure out a set of tags to run different groups under different scenarios, but I think it is still too early to bother with that: https://bats-core.readthedocs.io/en/stable/writing-tests.html#tagging-tests |
||
|
|
||
| NAME=nginx | ||
|
|
||
| local_setup_file() { | ||
| limactl delete --force "$NAME" || : | ||
| limactl start --yes --name "$NAME" --mount "$BATS_TMPDIR" "template://${TEMPLATE}" 3>&- 4>&- | ||
| } | ||
|
|
||
| local_teardown_file() { | ||
| limactl delete --force "$NAME" | ||
| } | ||
|
|
||
| ctrctl() { | ||
jandubois marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [[ $(limactl ls "$NAME" --yq .config.containerd.user) == true ]]; then | ||
| limactl shell $NAME nerdctl "$@" | ||
| else | ||
| limactl shell $NAME docker "$@" | ||
| fi | ||
| } | ||
|
|
||
| nginx_start() { | ||
| echo "$COUNTER" >"${BATS_TEST_TMPDIR}/index.html" | ||
| ctrctl run -d --name nginx -p 8080:80 -v "${BATS_TEST_TMPDIR}:/usr/share/nginx/html:ro" nginx | ||
| } | ||
|
|
||
| nginx_stop() { | ||
| ctrctl stop nginx | ||
| ctrctl rm nginx | ||
| } | ||
|
|
||
| verify_port() { | ||
| run curl --silent http://127.0.0.1:8080 | ||
| # If nginx is not quite ready and doesn't send any response at all, give it one extra chance | ||
| if [[ $status -eq 52 ]]; then | ||
| sleep 0.5 | ||
| run curl --silent http://127.0.0.1:8080 | ||
| fi | ||
| assert_success | ||
| assert_output "$COUNTER" | ||
| } | ||
|
|
||
| @test 'Verify that the container is working' { | ||
| COUNTER=0 | ||
| ctrctl pull --quiet nginx | ||
| nginx_start | ||
| verify_port | ||
| } | ||
|
|
||
| @test 'Stop and restart the container multiple times' { | ||
| for COUNTER in {1..100}; do | ||
| nginx_stop | ||
| nginx_start | ||
| verify_port | ||
| done | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.