Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[tests]: Improve test reliability on OS X / BSD (#176)
* [tests]: Fix test_tcp_lookup failure by using an invalid FQDN

* [tests]: Fixed test_auto_reconnect node test reliability

* [tests]: Improve bridge and node tests for OS X

* [tests]: Increase general wait/watcher timeout to 30s

* [tests]: Fix tests/node/test_server.py::test_auto_reconnect
  • Loading branch information
prologic committed Jan 16, 2017
1 parent 930ca39 commit a63e641
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
15 changes: 12 additions & 3 deletions tests/conftest.py
Expand Up @@ -26,7 +26,7 @@ def _on_event(self, event, *args, **kwargs):
def clear(self):
self.events.clear()

def wait(self, name, channel=None, timeout=6.0):
def wait(self, name, channel=None, timeout=30.0):
for i in range(int(timeout / TIMEOUT)):
with self._lock:
for event in self.events:
Expand All @@ -37,6 +37,15 @@ def wait(self, name, channel=None, timeout=6.0):
else:
return False

def count(self, name, channel=None, n=1, timeout=30.0):
n = 0
with self._lock:
for event in self.events:
if event.name == name and event.waitingHandlers == 0:
if (channel is None) or (channel in event.channels):
n += 1
return n


class Flag(object):
status = False
Expand All @@ -59,7 +68,7 @@ def call_event(manager, event, *channels):

class WaitEvent(object):

def __init__(self, manager, name, channel=None, timeout=6.0):
def __init__(self, manager, name, channel=None, timeout=30.0):
if channel is None:
channel = getattr(manager, "channel", None)

Expand All @@ -85,7 +94,7 @@ def wait(self):
self.manager.removeHandler(self.handler)


def wait_for(obj, attr, value=True, timeout=3.0):
def wait_for(obj, attr, value=True, timeout=30.0):
from circuits.core.manager import TIMEOUT
for i in range(int(timeout / TIMEOUT)):
if isinstance(value, collections.Callable):
Expand Down
13 changes: 8 additions & 5 deletions tests/core/test_bridge.py
Expand Up @@ -3,18 +3,21 @@

import pytest

if pytest.PLATFORM == "win32":
pytest.skip("Unsupported Platform")

pytest.importorskip("multiprocessing")


from os import getpid
from time import sleep


from circuits import ipc, Component, Event


if pytest.PLATFORM == "win32":
pytest.mark.skip("Unsupported Platform")


pytest.importorskip("multiprocessing")


class hello(Event):
"""hello Event"""

Expand Down
2 changes: 1 addition & 1 deletion tests/net/test_tcp.py
Expand Up @@ -340,7 +340,7 @@ def test_tcp_lookup_failure(manager, watcher, Poller, ipv6):
try:
assert watcher.wait("ready", "client")

client.fire(connect("foo", 1234))
client.fire(connect("foo.bar.baz", 1234))
assert watcher.wait("error", "client")

if pytest.PLATFORM == "win32":
Expand Down
45 changes: 19 additions & 26 deletions tests/node/test_server.py
Expand Up @@ -3,10 +3,11 @@

from __future__ import print_function

from pytest import PLATFORM, skip, fixture
from time import sleep

if PLATFORM == 'win32':
skip('Broken on Windows')

import pytest
from pytest import PLATFORM, fixture


from circuits import Event, Component
Expand All @@ -15,6 +16,10 @@
from circuits.node import Node


if PLATFORM == 'win32':
pytest.mark.skip('Broken on Windows')


class return_value(Event):
success = True

Expand Down Expand Up @@ -57,25 +62,12 @@ def test_auto_reconnect(app, watcher, manager):
node = Node().register(client)
chan = node.add('client1', *app.bind, reconnect_delay=1, connect_timeout=1)
assert watcher.wait('connected', channel=chan)
watcher.clear()

# close server
app.fire(close(), app.channel)
assert watcher.wait('closed', channel=app.channel)

app.unregister()
assert watcher.wait('unregistered', channel=app.channel)

for _ in range(5):
watcher.clear()
assert watcher.wait('connect', channel=chan)
assert watcher.wait('unreachable', channel=chan)

# open server
app = Node(port=app.bind[1], server_ip=app.bind[0])
app.register(manager)

assert watcher.wait('registered', channel=app.channel)
assert watcher.wait('connected_to', channel=app.channel)
assert watcher.wait('connected', channel=chan)

client.unregister()

Expand Down Expand Up @@ -125,28 +117,29 @@ def test_server_send_multicast(app, watcher, manager):
node1 = Node().register(client1)
chan1 = node1.add('client1', *app.bind)
assert watcher.wait('connected', channel=chan1)
watcher.clear()

client2 = App().register(manager)
node2 = Node().register(client2)
chan2 = node2.add('client2', *app.bind)
assert watcher.wait('connected', channel=chan2)
watcher.clear()

client3 = App().register(manager)
node3 = Node().register(client3)
chan3 = node3.add('client3', *app.bind)
assert watcher.wait('connected', channel=chan3)
watcher.clear()

event = return_value()
app.server.send_to(event, app.server.get_socks()[:2])
app.server.send_to(event, app.server.get_socks())
assert watcher.wait('return_value')

event_cnt = 0
with watcher._lock:
for event in watcher.events:
if event.name == 'return_value':
event_cnt += 1

assert event_cnt == 2
for _ in range(3):
if watcher.count("return_value") == 3:
break
sleep(1)
assert watcher.count("return_value") == 3

client1.unregister()
client2.unregister()
Expand Down

0 comments on commit a63e641

Please sign in to comment.