Merge pull request #2282 from ulyssessouza/avoid-race-condition-on-autoremove

Avoid race condition on short execution
This commit is contained in:
Ian Campbell 2019-03-25 12:00:28 +00:00 committed by GitHub
commit 5abf671442
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -123,7 +123,9 @@ class ContainerCollectionTest(BaseIntegrationTest):
def test_run_with_auto_remove(self):
client = docker.from_env(version=TEST_API_VERSION)
out = client.containers.run(
'alpine', 'echo hello', auto_remove=True
# sleep(2) to allow any communication with the container
# before it gets removed by the host.
'alpine', 'sh -c "echo hello && sleep 2"', auto_remove=True
)
assert out == b'hello\n'
@ -132,7 +134,10 @@ class ContainerCollectionTest(BaseIntegrationTest):
client = docker.from_env(version=TEST_API_VERSION)
with pytest.raises(docker.errors.ContainerError) as e:
client.containers.run(
'alpine', 'sh -c ">&2 echo error && exit 1"', auto_remove=True
# sleep(2) to allow any communication with the container
# before it gets removed by the host.
'alpine', 'sh -c ">&2 echo error && sleep 2 && exit 1"',
auto_remove=True
)
assert e.value.exit_status == 1
assert e.value.stderr is None