11
11
LOGGER = logging .getLogger (__name__ )
12
12
13
13
14
+ def get_healthy_status (
15
+ container : TrackedContainer ,
16
+ env : list [str ] | None ,
17
+ cmd : list [str ] | None ,
18
+ user : str | None ,
19
+ ) -> str :
20
+ running_container = container .run_detached (
21
+ tty = True ,
22
+ environment = env ,
23
+ command = cmd ,
24
+ user = user ,
25
+ )
26
+
27
+ # giving some time to let the server start
28
+ finish_time = time .time () + 10
29
+ sleep_time = 1
30
+ while time .time () < finish_time :
31
+ time .sleep (sleep_time )
32
+
33
+ status = get_health (running_container )
34
+ if status == "healthy" :
35
+ return status
36
+
37
+ return get_health (running_container )
38
+
39
+
14
40
@pytest .mark .parametrize (
15
41
"env,cmd,user" ,
16
42
[
@@ -60,22 +86,7 @@ def test_healthy(
60
86
cmd : list [str ] | None ,
61
87
user : str | None ,
62
88
) -> None :
63
- running_container = container .run_detached (
64
- tty = True ,
65
- environment = env ,
66
- command = cmd ,
67
- user = user ,
68
- )
69
-
70
- # giving some time to let the server start
71
- finish_time = time .time () + 10
72
- sleep_time = 0.1
73
- while time .time () < finish_time :
74
- time .sleep (sleep_time )
75
- if get_health (running_container ) == "healthy" :
76
- return
77
-
78
- assert get_health (running_container ) == "healthy"
89
+ assert get_healthy_status (container , env , cmd , user ) == "healthy"
79
90
80
91
81
92
@pytest .mark .parametrize (
@@ -108,22 +119,7 @@ def test_healthy_with_proxy(
108
119
cmd : list [str ] | None ,
109
120
user : str | None ,
110
121
) -> None :
111
- running_container = container .run_detached (
112
- tty = True ,
113
- environment = env ,
114
- command = cmd ,
115
- user = user ,
116
- )
117
-
118
- # giving some time to let the server start
119
- finish_time = time .time () + 10
120
- sleep_time = 0.1
121
- while time .time () < finish_time :
122
- time .sleep (sleep_time )
123
- if get_health (running_container ) == "healthy" :
124
- return
125
-
126
- assert get_health (running_container ) == "healthy"
122
+ assert get_healthy_status (container , env , cmd , user ) == "healthy"
127
123
128
124
129
125
@pytest .mark .parametrize (
@@ -145,18 +141,6 @@ def test_not_healthy(
145
141
env : list [str ] | None ,
146
142
cmd : list [str ] | None ,
147
143
) -> None :
148
- running_container = container .run_detached (
149
- tty = True ,
150
- environment = env ,
151
- command = cmd ,
152
- )
153
-
154
- # giving some time to let the server start
155
- finish_time = time .time () + 5
156
- sleep_time = 0.1
157
- while time .time () < finish_time :
158
- time .sleep (sleep_time )
159
- if get_health (running_container ) == "healthy" :
160
- raise RuntimeError ("Container should not be healthy for this testcase" )
161
-
162
- assert get_health (running_container ) != "healthy"
144
+ assert (
145
+ get_healthy_status (container , env , cmd , user = None ) != "healthy"
146
+ ), "Container should not be healthy for this testcase"
0 commit comments