mirror of https://github.com/docker/docker-py.git
Remove redundant single-socket select call
Clean up + use pytest-timeout Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
719d4e9e20
commit
284c3d90d6
|
@ -59,5 +59,4 @@ class CancellableStream(object):
|
||||||
sock = sock_fp._sock
|
sock = sock_fp._sock
|
||||||
|
|
||||||
sock.shutdown(socket.SHUT_RDWR)
|
sock.shutdown(socket.SHUT_RDWR)
|
||||||
sock.makefile().close()
|
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
|
@ -22,8 +22,7 @@ def read(socket, n=4096):
|
||||||
|
|
||||||
recoverable_errors = (errno.EINTR, errno.EDEADLK, errno.EWOULDBLOCK)
|
recoverable_errors = (errno.EINTR, errno.EDEADLK, errno.EWOULDBLOCK)
|
||||||
|
|
||||||
# wait for data to become available
|
if six.PY3 and not isinstance(socket, NpipeSocket):
|
||||||
if not isinstance(socket, NpipeSocket):
|
|
||||||
select.select([socket], [], [])
|
select.select([socket], [], [])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
coverage==3.7.1
|
||||||
|
flake8==3.4.1
|
||||||
mock==1.0.1
|
mock==1.0.1
|
||||||
pytest==2.9.1
|
pytest==2.9.1
|
||||||
coverage==3.7.1
|
|
||||||
pytest-cov==2.1.0
|
pytest-cov==2.1.0
|
||||||
flake8==3.4.1
|
pytest-timeout==1.2.1
|
||||||
|
|
|
@ -881,6 +881,7 @@ Line2'''
|
||||||
|
|
||||||
assert logs == (snippet + '\n').encode(encoding='ascii')
|
assert logs == (snippet + '\n').encode(encoding='ascii')
|
||||||
|
|
||||||
|
@pytest.mark.timeout(5)
|
||||||
def test_logs_streaming_and_follow_and_cancel(self):
|
def test_logs_streaming_and_follow_and_cancel(self):
|
||||||
snippet = 'Flowering Nights (Sakuya Iyazoi)'
|
snippet = 'Flowering Nights (Sakuya Iyazoi)'
|
||||||
container = self.client.create_container(
|
container = self.client.create_container(
|
||||||
|
@ -892,17 +893,11 @@ Line2'''
|
||||||
logs = six.binary_type()
|
logs = six.binary_type()
|
||||||
|
|
||||||
generator = self.client.logs(id, stream=True, follow=True)
|
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()
|
threading.Timer(1, generator.close).start()
|
||||||
|
|
||||||
for chunk in generator:
|
for chunk in generator:
|
||||||
logs += chunk
|
logs += chunk
|
||||||
|
|
||||||
exit_timer.cancel()
|
|
||||||
|
|
||||||
assert logs == (snippet + '\n').encode(encoding='ascii')
|
assert logs == (snippet + '\n').encode(encoding='ascii')
|
||||||
|
|
||||||
def test_logs_with_dict_instead_of_id(self):
|
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)
|
output = self.client.attach(container, stream=False, logs=True)
|
||||||
assert output == 'hello\n'.encode(encoding='ascii')
|
assert output == 'hello\n'.encode(encoding='ascii')
|
||||||
|
|
||||||
|
@pytest.mark.timeout(5)
|
||||||
def test_attach_stream_and_cancel(self):
|
def test_attach_stream_and_cancel(self):
|
||||||
container = self.client.create_container(
|
container = self.client.create_container(
|
||||||
BUSYBOX, 'sh -c "echo hello && sleep 60"',
|
BUSYBOX, 'sh -c "echo hello && sleep 60"',
|
||||||
|
@ -1260,17 +1256,12 @@ class AttachContainerTest(BaseAPIIntegrationTest):
|
||||||
self.client.start(container)
|
self.client.start(container)
|
||||||
output = self.client.attach(container, stream=True, logs=True)
|
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()
|
threading.Timer(1, output.close).start()
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
for line in output:
|
for line in output:
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
|
|
||||||
exit_timer.cancel()
|
|
||||||
|
|
||||||
assert len(lines) == 1
|
assert len(lines) == 1
|
||||||
assert lines[0] == 'hello\r\n'.encode(encoding='ascii')
|
assert lines[0] == 'hello\r\n'.encode(encoding='ascii')
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import os
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
@ -143,21 +142,17 @@ class ContainerCollectionTest(BaseIntegrationTest):
|
||||||
assert logs[0] == b'hello\n'
|
assert logs[0] == b'hello\n'
|
||||||
assert logs[1] == b'world\n'
|
assert logs[1] == b'world\n'
|
||||||
|
|
||||||
|
@pytest.mark.timeout(5)
|
||||||
def test_run_with_streamed_logs_and_cancel(self):
|
def test_run_with_streamed_logs_and_cancel(self):
|
||||||
client = docker.from_env(version=TEST_API_VERSION)
|
client = docker.from_env(version=TEST_API_VERSION)
|
||||||
out = client.containers.run(
|
out = client.containers.run(
|
||||||
'alpine', 'sh -c "echo hello && echo world"', stream=True
|
'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()
|
threading.Timer(1, out.close).start()
|
||||||
|
|
||||||
logs = [line for line in out]
|
logs = [line for line in out]
|
||||||
|
|
||||||
exit_timer.cancel()
|
|
||||||
|
|
||||||
assert len(logs) == 2
|
assert len(logs) == 2
|
||||||
assert logs[0] == b'hello\n'
|
assert logs[0] == b'hello\n'
|
||||||
assert logs[1] == b'world\n'
|
assert logs[1] == b'world\n'
|
||||||
|
|
Loading…
Reference in New Issue