summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlysses Souza <ulysses.souza@docker.com>2019-03-19 17:38:24 +0100
committerUlysses Souza <ulysses.souza@docker.com>2019-03-25 12:42:54 +0100
commit8f42dd14841c43aa8081fe67c9af305391e4952b (patch)
treeb3fb3c3692a7173f91f7534523c8da5d295fd479
parent729c2e783079a9c2948318c70fe7aa22681f1ebe (diff)
downloaddocker-py-8f42dd14841c43aa8081fe67c9af305391e4952b.tar.gz
Avoid race condition on short execution
- Add a sleep of 2 seconds to be sure the logs can be requested before the daemon removes the container when run with auto_remove=True Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
-rw-r--r--tests/integration/models_containers_test.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py
index 92eca36..872f753 100644
--- a/tests/integration/models_containers_test.py
+++ b/tests/integration/models_containers_test.py
@@ -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