From e304f91b4636b59a056ff795d91895c725c6255f Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Mon, 29 Jan 2018 17:07:15 -0800 Subject: Update detach tests to work with AF_INET as well Signed-off-by: Joffrey F --- tests/helpers.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'tests/helpers.py') diff --git a/tests/helpers.py b/tests/helpers.py index 7c68f6d..c4ea364 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -6,8 +6,8 @@ import tarfile import tempfile import time import re -import socket import six +import socket import docker import pytest @@ -107,16 +107,23 @@ def swarm_listen_addr(): return '0.0.0.0:{0}'.format(random.randrange(10000, 25000)) -def assert_socket_closed_with_keys(sock, inputs): +def assert_cat_socket_detached_with_keys(sock, inputs): if six.PY3: sock = sock._sock for i in inputs: sock.send(i) - time.sleep(1) - - with pytest.raises(socket.error): + time.sleep(0.5) + + # If we're using a Unix socket, the sock.send call will fail with a + # BrokenPipeError ; INET sockets will just stop receiving / sending data + # but will not raise an error + if sock.family == getattr(socket, 'AF_UNIX', -1): + with pytest.raises(socket.error): + sock.send(b'make sure the socket is closed\n') + else: sock.send(b"make sure the socket is closed\n") + assert sock.recv(32) == b'' def ctrl_with(char): -- cgit v1.2.1