@@ -77,6 +77,9 @@ def wait_for(condition: Callable[..., bool]) -> bool:
77
77
return condition ()
78
78
79
79
80
+ _NOT_EXITED_STATUSES = {"running" , "created" }
81
+
82
+
80
83
def wait_for_logs (
81
84
container : "DockerContainer" ,
82
85
predicate : Union [Callable , str ],
@@ -103,11 +106,13 @@ def wait_for_logs(
103
106
"""
104
107
if isinstance (predicate , str ):
105
108
predicate = re .compile (predicate , re .MULTILINE ).search
109
+ wrapped = container .get_wrapped_container ()
106
110
start = time .time ()
107
111
while True :
108
112
duration = time .time () - start
109
- stdout = container .get_logs ()[0 ].decode ()
110
- stderr = container .get_logs ()[1 ].decode ()
113
+ stdout , stderr = container .get_logs ()
114
+ stdout = stdout .decode ()
115
+ stderr = stderr .decode ()
111
116
predicate_result = (
112
117
predicate (stdout ) or predicate (stderr )
113
118
if predicate_streams_and is False
@@ -118,6 +123,8 @@ def wait_for_logs(
118
123
return duration
119
124
if duration > timeout :
120
125
raise TimeoutError (f"Container did not emit logs satisfying predicate in { timeout :.3f} " "seconds" )
121
- if raise_on_exit and container .get_wrapped_container ().status != "running" :
122
- raise RuntimeError ("Container exited before emitting logs satisfying predicate" )
126
+ if raise_on_exit :
127
+ wrapped .reload ()
128
+ if wrapped .status not in _NOT_EXITED_STATUSES :
129
+ raise RuntimeError ("Container exited before emitting logs satisfying predicate" )
123
130
time .sleep (interval )
0 commit comments