Fix flaky log test by using container status, instead of boolean state.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-03-07 15:08:31 -05:00
parent 3f7e5bf768
commit 8d9adc0902
1 changed files with 9 additions and 10 deletions

View File

@ -78,21 +78,20 @@ class ContainerCountCondition(object):
class ContainerStateCondition(object):
def __init__(self, client, name, running):
def __init__(self, client, name, status):
self.client = client
self.name = name
self.running = running
self.status = status
def __call__(self):
try:
container = self.client.inspect_container(self.name)
return container['State']['Running'] == self.running
return container['State']['Status'] == self.status
except errors.APIError:
return False
def __str__(self):
state = 'running' if self.running else 'stopped'
return "waiting for container to be %s" % state
return "waiting for container to be %s" % self.status
class CLITestCase(DockerClientTestCase):
@ -1073,26 +1072,26 @@ class CLITestCase(DockerClientTestCase):
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
running=True))
'running'))
os.kill(proc.pid, signal.SIGINT)
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
running=False))
'exited'))
def test_run_handles_sigterm(self):
proc = start_process(self.base_dir, ['run', '-T', 'simple', 'top'])
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
running=True))
'running'))
os.kill(proc.pid, signal.SIGTERM)
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
running=False))
'exited'))
def test_rm(self):
service = self.project.get_service('simple')
@ -1207,7 +1206,7 @@ class CLITestCase(DockerClientTestCase):
wait_on_condition(ContainerStateCondition(
self.project.client,
'logscomposefile_another_1',
running=False))
'exited'))
os.kill(proc.pid, signal.SIGINT)
result = wait_on_process(proc, returncode=1)