diff options
-rw-r--r-- | docker/types/daemon.py | 1 | ||||
-rw-r--r-- | docker/utils/socket.py | 3 | ||||
-rw-r--r-- | test-requirements.txt | 5 | ||||
-rw-r--r-- | tests/integration/api_container_test.py | 13 | ||||
-rw-r--r-- | tests/integration/models_containers_test.py | 7 |
5 files changed, 7 insertions, 22 deletions
diff --git a/docker/types/daemon.py b/docker/types/daemon.py index ba0334d..852f3d8 100644 --- a/docker/types/daemon.py +++ b/docker/types/daemon.py @@ -59,5 +59,4 @@ class CancellableStream(object): sock = sock_fp._sock sock.shutdown(socket.SHUT_RDWR) - sock.makefile().close() sock.close() diff --git a/docker/utils/socket.py b/docker/utils/socket.py index c3a5f90..0945f0a 100644 --- a/docker/utils/socket.py +++ b/docker/utils/socket.py @@ -22,8 +22,7 @@ def read(socket, n=4096): recoverable_errors = (errno.EINTR, errno.EDEADLK, errno.EWOULDBLOCK) - # wait for data to become available - if not isinstance(socket, NpipeSocket): + if six.PY3 and not isinstance(socket, NpipeSocket): select.select([socket], [], []) try: diff --git a/test-requirements.txt b/test-requirements.txt index f79e815..09680b6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,6 @@ +coverage==3.7.1 +flake8==3.4.1 mock==1.0.1 pytest==2.9.1 -coverage==3.7.1 pytest-cov==2.1.0 -flake8==3.4.1 +pytest-timeout==1.2.1 diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py index cc2c071..e212518 100644 --- a/tests/integration/api_container_test.py +++ b/tests/integration/api_container_test.py @@ -881,6 +881,7 @@ Line2''' assert logs == (snippet + '\n').encode(encoding='ascii') + @pytest.mark.timeout(5) def test_logs_streaming_and_follow_and_cancel(self): snippet = 'Flowering Nights (Sakuya Iyazoi)' container = self.client.create_container( @@ -892,17 +893,11 @@ Line2''' logs = six.binary_type() generator = self.client.logs(id, stream=True, follow=True) - - exit_timer = threading.Timer(3, os._exit, args=[1]) - exit_timer.start() - threading.Timer(1, generator.close).start() for chunk in generator: logs += chunk - exit_timer.cancel() - assert logs == (snippet + '\n').encode(encoding='ascii') def test_logs_with_dict_instead_of_id(self): @@ -1251,6 +1246,7 @@ class AttachContainerTest(BaseAPIIntegrationTest): output = self.client.attach(container, stream=False, logs=True) assert output == 'hello\n'.encode(encoding='ascii') + @pytest.mark.timeout(5) def test_attach_stream_and_cancel(self): container = self.client.create_container( BUSYBOX, 'sh -c "echo hello && sleep 60"', @@ -1260,17 +1256,12 @@ class AttachContainerTest(BaseAPIIntegrationTest): self.client.start(container) output = self.client.attach(container, stream=True, logs=True) - exit_timer = threading.Timer(3, os._exit, args=[1]) - exit_timer.start() - threading.Timer(1, output.close).start() lines = [] for line in output: lines.append(line) - exit_timer.cancel() - assert len(lines) == 1 assert lines[0] == 'hello\r\n'.encode(encoding='ascii') diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py index 41faff3..6ddb034 100644 --- a/tests/integration/models_containers_test.py +++ b/tests/integration/models_containers_test.py @@ -1,4 +1,3 @@ -import os import tempfile import threading @@ -143,21 +142,17 @@ class ContainerCollectionTest(BaseIntegrationTest): assert logs[0] == b'hello\n' assert logs[1] == b'world\n' + @pytest.mark.timeout(5) def test_run_with_streamed_logs_and_cancel(self): client = docker.from_env(version=TEST_API_VERSION) out = client.containers.run( 'alpine', 'sh -c "echo hello && echo world"', stream=True ) - exit_timer = threading.Timer(3, os._exit, args=[1]) - exit_timer.start() - threading.Timer(1, out.close).start() logs = [line for line in out] - exit_timer.cancel() - assert len(logs) == 2 assert logs[0] == b'hello\n' assert logs[1] == b'world\n' |