Skip to content

Commit

Permalink
[tests]: Improve bridge and node tests for OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
prologic committed Jul 25, 2016
1 parent 88856db commit c525fe7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
9 changes: 9 additions & 0 deletions tests/conftest.py
Expand Up @@ -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=6.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 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.skip("Unsupported Platform")


pytest.importorskip("multiprocessing")


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

Expand Down
27 changes: 16 additions & 11 deletions tests/node/test_server.py
Expand Up @@ -3,10 +3,10 @@

from __future__ import print_function

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

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

from pytest import PLATFORM, skip, fixture


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


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


class return_value(Event):
success = True

Expand Down Expand Up @@ -113,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 c525fe7

Please sign in to comment.