Skip to content

Commit

Permalink
Remove redundant single-socket select call
Browse files Browse the repository at this point in the history
Clean up + use pytest-timeout

Signed-off-by: Joffrey F <joffrey@docker.com>
  • Loading branch information
shin- committed Mar 20, 2018
1 parent 719d4e9 commit 284c3d9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 22 deletions.
1 change: 0 additions & 1 deletion docker/types/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ def close(self):
sock = sock_fp._sock

sock.shutdown(socket.SHUT_RDWR)
sock.makefile().close()
sock.close()
3 changes: 1 addition & 2 deletions docker/utils/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -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
13 changes: 2 additions & 11 deletions tests/integration/api_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ def test_logs_streaming_and_follow(self):

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(
Expand All @@ -892,17 +893,11 @@ def test_logs_streaming_and_follow_and_cancel(self):
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):
Expand Down Expand Up @@ -1251,6 +1246,7 @@ def test_attach_no_stream(self):
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"',
Expand All @@ -1260,17 +1256,12 @@ def test_attach_stream_and_cancel(self):
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')

Expand Down
7 changes: 1 addition & 6 deletions tests/integration/models_containers_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import tempfile
import threading

Expand Down Expand Up @@ -143,21 +142,17 @@ def test_run_with_streamed_logs(self):
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'
Expand Down

0 comments on commit 284c3d9

Please sign in to comment.