forked from mtusi2026/mtusi2026lab2
Wait for periodic Docker healthcheck after API restart
This commit is contained in:
@@ -17,7 +17,12 @@ chat=c.call('POST','/api/v1/chats',201,actor=a,body={'title':'Lifecycle','member
|
|||||||
marker='synthetic-private-body-marker';msg=c.message(a,chat,marker)['json']
|
marker='synthetic-private-body-marker';msg=c.message(a,chat,marker)['json']
|
||||||
container=compose('ps','-q','api')
|
container=compose('ps','-q','api')
|
||||||
inspect=lambda:json.loads(subprocess.check_output(['docker','inspect',container],text=True))[0]
|
inspect=lambda:json.loads(subprocess.check_output(['docker','inspect',container],text=True))[0]
|
||||||
before=inspect();assert before['Config']['User']=='10001:10001' and before['State']['Health']['Status']=='healthy'
|
before=inspect()
|
||||||
|
# HTTP readiness can precede Docker's next periodic healthcheck after restart.
|
||||||
|
deadline=time.monotonic()+20
|
||||||
|
while before['State']['Health']['Status']!='healthy' and time.monotonic()<deadline:
|
||||||
|
time.sleep(.2);before=inspect()
|
||||||
|
assert before['Config']['User']=='10001:10001' and before['State']['Health']['Status']=='healthy'
|
||||||
pid1=compose('exec','-T','api','cat','/proc/1/comm');assert pid1=='messenger'
|
pid1=compose('exec','-T','api','cat','/proc/1/comm');assert pid1=='messenger'
|
||||||
start=time.monotonic();compose('stop','api');seconds=time.monotonic()-start
|
start=time.monotonic();compose('stop','api');seconds=time.monotonic()-start
|
||||||
stopped=inspect();assert stopped['State']['ExitCode']==0 and not stopped['State']['OOMKilled'] and seconds<7
|
stopped=inspect();assert stopped['State']['ExitCode']==0 and not stopped['State']['OOMKilled'] and seconds<7
|
||||||
|
|||||||
Reference in New Issue
Block a user