Merge "Update tests to use AF_INET6" into feature/zuulv3

This commit is contained in:
Zuul 2017-09-07 15:23:07 +00:00 committed by Gerrit Code Review
commit fcc73133f8
2 changed files with 11 additions and 11 deletions

View File

@ -1195,7 +1195,7 @@ class FakeStatsd(threading.Thread):
def __init__(self): def __init__(self):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.daemon = True self.daemon = True
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
self.sock.bind(('', 0)) self.sock.bind(('', 0))
self.port = self.sock.getsockname()[1] self.port = self.sock.getsockname()[1]
self.wake_read, self.wake_write = os.pipe() self.wake_read, self.wake_write = os.pipe()

View File

@ -22,6 +22,7 @@ import os
import os.path import os.path
import socket import socket
import tempfile import tempfile
import testtools
import threading import threading
import time import time
@ -46,16 +47,13 @@ class TestLogStreamer(tests.base.BaseTestCase):
streamer = self.startStreamer(port) streamer = self.startStreamer(port)
self.addCleanup(streamer.stop) self.addCleanup(streamer.stop)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.create_connection((self.host, port))
self.addCleanup(s.close)
self.assertEqual(0, s.connect_ex((self.host, port)))
s.close() s.close()
streamer.stop() streamer.stop()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) with testtools.ExpectedException(ConnectionRefusedError):
self.addCleanup(s.close) s = socket.create_connection((self.host, port))
self.assertNotEqual(0, s.connect_ex((self.host, port)))
s.close() s.close()
@ -80,8 +78,7 @@ class TestStreaming(tests.base.AnsibleZuulTestCase):
root = tempfile.gettempdir() root = tempfile.gettempdir()
self.streamer = zuul.lib.log_streamer.LogStreamer(None, self.host, self.streamer = zuul.lib.log_streamer.LogStreamer(None, self.host,
port, root) port, root)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.create_connection((self.host, port))
s.connect((self.host, port))
self.addCleanup(s.close) self.addCleanup(s.close)
req = '%s\n' % build_uuid req = '%s\n' % build_uuid
@ -237,8 +234,11 @@ class TestStreaming(tests.base.AnsibleZuulTestCase):
self.addCleanup(web_server.stop) self.addCleanup(web_server.stop)
# Wait until web server is started # Wait until web server is started
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: while True:
while s.connect_ex((self.host, 9000)): try:
with socket.create_connection((self.host, 9000)):
break
except ConnectionRefusedError:
time.sleep(0.1) time.sleep(0.1)
# Start a thread with the websocket client # Start a thread with the websocket client