4
4
from localstack import config
5
5
from localstack .config import in_docker
6
6
from localstack .utils .bootstrap import LocalstackContainerServer
7
+ from localstack .utils .sync import poll_condition
7
8
8
9
9
10
@pytest .mark .skipif (condition = in_docker (), reason = "cannot run bootstrap tests in docker" )
@@ -17,8 +18,38 @@ def test_lifecycle(self):
17
18
server .start ()
18
19
assert server .wait_is_up (60 )
19
20
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"
22
53
finally :
23
54
server .shutdown ()
24
55
0 commit comments