Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4608b74

Browse files
committed
extend bootstrap lifecycle test to include restarts
1 parent 60f6db5 commit 4608b74

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

‎tests/bootstrap/test_localstack_container_server.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from localstack import config
55
from localstack.config import in_docker
66
from localstack.utils.bootstrap import LocalstackContainerServer
7+
from localstack.utils.sync import poll_condition
78

89

910
@pytest.mark.skipif(condition=in_docker(), reason="cannot run bootstrap tests in docker")
@@ -17,8 +18,38 @@ def test_lifecycle(self):
1718
server.start()
1819
assert server.wait_is_up(60)
1920

20-
response = requests.get("http://localhost:4566/_localstack/health")
21-
assert response.ok, "expected health check to return OK: %s" % response.text
21+
health_response = requests.get("http://localhost:4566/_localstack/health")
22+
assert health_response.ok, (
23+
"expected health check to return OK: %s" % health_response.text
24+
)
25+
26+
restart_response = requests.post(
27+
"http://localhost:4566/_localstack/health", json={"action": "restart"}
28+
)
29+
assert restart_response.ok, (
30+
"expected restart command via health endpoint to return OK: %s"
31+
% restart_response.text
32+
)
33+
34+
def check_restart_successful():
35+
logs = server.container.get_logs()
36+
if logs.count("Ready.") < 2:
37+
# second ready marker still missing
38+
return False
39+
40+
health_response_after_retry = requests.get(
41+
"http://localhost:4566/_localstack/health"
42+
)
43+
if not health_response_after_retry.ok:
44+
# health endpoint not yet ready again
45+
return False
46+
47+
# second restart marker found and health endpoint returned with 200!
48+
return True
49+
50+
assert poll_condition(
51+
check_restart_successful, 45, 1
52+
), "expected two Ready markers in the logs after triggering restart via health endpoint"
2253
finally:
2354
server.shutdown()
2455

0 commit comments

Comments
 (0)