Kaydet (Commit) 284c3d90 authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) Joffrey F

Remove redundant single-socket select call

Clean up + use pytest-timeout
Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst 719d4e9e
......@@ -59,5 +59,4 @@ class CancellableStream(object):
sock = sock_fp._sock
sock.shutdown(socket.SHUT_RDWR)
sock.makefile().close()
sock.close()
......@@ -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:
......
......@@ -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')
......
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'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment