Skip to content

Commit e9f31e1

Browse files
committed
Remove redundant single-socket select call
Clean up + use pytest-timeout Signed-off-by: Joffrey F <[email protected]>
1 parent dd743db commit e9f31e1

File tree

5 files changed

+7
-22
lines changed

5 files changed

+7
-22
lines changed

docker/types/daemon.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,4 @@ def close(self):
5959
sock = sock_fp._sock
6060

6161
sock.shutdown(socket.SHUT_RDWR)
62-
sock.makefile().close()
6362
sock.close()

docker/utils/socket.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def read(socket, n=4096):
2222

2323
recoverable_errors = (errno.EINTR, errno.EDEADLK, errno.EWOULDBLOCK)
2424

25-
# wait for data to become available
26-
if not isinstance(socket, NpipeSocket):
25+
if six.PY3 and not isinstance(socket, NpipeSocket):
2726
select.select([socket], [], [])
2827

2928
try:

test-requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
coverage==3.7.1
2+
flake8==3.4.1
13
mock==1.0.1
24
pytest==2.9.1
3-
coverage==3.7.1
45
pytest-cov==2.1.0
5-
flake8==3.4.1
6+
pytest-timeout==1.2.1

tests/integration/api_container_test.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ def test_logs_streaming_and_follow(self):
881881

882882
assert logs == (snippet + '\n').encode(encoding='ascii')
883883

884+
@pytest.mark.timeout(5)
884885
def test_logs_streaming_and_follow_and_cancel(self):
885886
snippet = 'Flowering Nights (Sakuya Iyazoi)'
886887
container = self.client.create_container(
@@ -892,17 +893,11 @@ def test_logs_streaming_and_follow_and_cancel(self):
892893
logs = six.binary_type()
893894

894895
generator = self.client.logs(id, stream=True, follow=True)
895-
896-
exit_timer = threading.Timer(3, os._exit, args=[1])
897-
exit_timer.start()
898-
899896
threading.Timer(1, generator.close).start()
900897

901898
for chunk in generator:
902899
logs += chunk
903900

904-
exit_timer.cancel()
905-
906901
assert logs == (snippet + '\n').encode(encoding='ascii')
907902

908903
def test_logs_with_dict_instead_of_id(self):
@@ -1251,6 +1246,7 @@ def test_attach_no_stream(self):
12511246
output = self.client.attach(container, stream=False, logs=True)
12521247
assert output == 'hello\n'.encode(encoding='ascii')
12531248

1249+
@pytest.mark.timeout(5)
12541250
def test_attach_stream_and_cancel(self):
12551251
container = self.client.create_container(
12561252
BUSYBOX, 'sh -c "echo hello && sleep 60"',
@@ -1260,17 +1256,12 @@ def test_attach_stream_and_cancel(self):
12601256
self.client.start(container)
12611257
output = self.client.attach(container, stream=True, logs=True)
12621258

1263-
exit_timer = threading.Timer(3, os._exit, args=[1])
1264-
exit_timer.start()
1265-
12661259
threading.Timer(1, output.close).start()
12671260

12681261
lines = []
12691262
for line in output:
12701263
lines.append(line)
12711264

1272-
exit_timer.cancel()
1273-
12741265
assert len(lines) == 1
12751266
assert lines[0] == 'hello\r\n'.encode(encoding='ascii')
12761267

tests/integration/models_containers_test.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import tempfile
32
import threading
43

@@ -143,21 +142,17 @@ def test_run_with_streamed_logs(self):
143142
assert logs[0] == b'hello\n'
144143
assert logs[1] == b'world\n'
145144

145+
@pytest.mark.timeout(5)
146146
def test_run_with_streamed_logs_and_cancel(self):
147147
client = docker.from_env(version=TEST_API_VERSION)
148148
out = client.containers.run(
149149
'alpine', 'sh -c "echo hello && echo world"', stream=True
150150
)
151151

152-
exit_timer = threading.Timer(3, os._exit, args=[1])
153-
exit_timer.start()
154-
155152
threading.Timer(1, out.close).start()
156153

157154
logs = [line for line in out]
158155

159-
exit_timer.cancel()
160-
161156
assert len(logs) == 2
162157
assert logs[0] == b'hello\n'
163158
assert logs[1] == b'world\n'

0 commit comments

Comments
 (0)