File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: Copyright The Lima Authors
2+ # SPDX-License-Identifier: Apache-2.0
3+
4+ # This test verifies that when a container is destroyed, its ports can be reused
5+ # immediately and are not subject to being freed by a polling loop. See #4066.
6+
7+ load " ../helpers/load"
8+
9+ : " ${TEMPLATE:= default} " # Alternative: "docker"
10+
11+ NAME=nginx
12+
13+ local_setup_file () {
14+ limactl delete --force " $NAME " || :
15+ limactl start --yes --name " $NAME " --mount " $BATS_TMPDIR " " template://${TEMPLATE} " 3>& - 4>& -
16+ }
17+
18+ local_teardown_file () {
19+ limactl delete --force " $NAME "
20+ }
21+
22+ ctrctl () {
23+ if [[ $( limactl ls " $NAME " --yq .config.containerd.user) == true ]]; then
24+ limactl shell $NAME nerdctl " $@ "
25+ else
26+ limactl shell $NAME docker " $@ "
27+ fi
28+ }
29+
30+ nginx_start () {
31+ echo " $COUNTER " > " ${BATS_TEST_TMPDIR} /index.html"
32+ ctrctl run -d --name nginx -p 8080:80 -v " ${BATS_TEST_TMPDIR} :/usr/share/nginx/html:ro" nginx
33+ }
34+
35+ nginx_stop () {
36+ ctrctl stop nginx
37+ ctrctl rm nginx
38+ }
39+
40+ verify_port () {
41+ run curl --silent http://127.0.0.1:8080
42+ # If nginx is not quite ready and doesn't send any response at all, give it one extra chance
43+ if [[ $status -eq 52 ]]; then
44+ sleep 0.5
45+ run curl --silent http://127.0.0.1:8080
46+ fi
47+ assert_success
48+ assert_output " $COUNTER "
49+ }
50+
51+ @test ' Verify that the container is working' {
52+ COUNTER=0
53+ ctrctl pull --quiet nginx
54+ nginx_start
55+ verify_port
56+ }
57+
58+ @test ' Stop and restart the container multiple times' {
59+ for COUNTER in {1..100}; do
60+ nginx_stop
61+ nginx_start
62+ verify_port
63+ done
64+ }
You can’t perform that action at this time.
0 commit comments