Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9da0db8

Browse files
committed
Fix the PUB/SUB tests
FX kindly reminded that the Subscriber must be reading on the ZMQ socket *before* the send from the publisher to get the message. In other words, the test failures were a perfectly expected behavior from ZMQ. Thus, this changeset add some retry logic to give the time to the subscriber.run coroutine to trigger a read.
1 parent a6f57e7 commit 9da0db8

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

tests/test_middleware.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
from zerorpc import zmq
3333
import zerorpc
34-
from testutils import teardown, random_ipc_endpoint, skip
34+
from testutils import teardown, random_ipc_endpoint
3535

3636

3737
def test_resolve_endpoint():
@@ -343,7 +343,6 @@ def echo(self, msg):
343343
]
344344

345345

346-
@skip("PUB/SUB is badly broken in ZMQ and make this test fails")
347346
def test_task_context_pubsub():
348347
endpoint = random_ipc_endpoint()
349348
subscriber_ctx = zerorpc.Context()
@@ -368,8 +367,12 @@ def echo(self, msg):
368367
c.connect(endpoint)
369368

370369
trigger.clear()
371-
c.echo('pub...')
372-
trigger.wait()
370+
# We need this retry logic to wait that the subscriber.run coroutine starts
371+
# reading (the published messages will go to /dev/null until then).
372+
for attempt in xrange(0, 10):
373+
c.echo('pub...')
374+
if trigger.wait(0.2):
375+
break
373376

374377
subscriber.stop()
375378
subscriber_task.join()

tests/test_pubpush.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import gevent.event
2828
import zerorpc
2929

30-
from testutils import teardown, random_ipc_endpoint, skip
30+
from testutils import teardown, random_ipc_endpoint
3131

3232

3333
def test_pushpull_inheritance():
@@ -53,7 +53,6 @@ def lolita(self, a, b):
5353
print 'done'
5454

5555

56-
@skip("PUB/SUB is badly broken in ZMQ and make this test fails")
5756
def test_pubsub_inheritance():
5857
endpoint = random_ipc_endpoint()
5958

@@ -72,10 +71,15 @@ def lolita(self, a, b):
7271
gevent.spawn(subscriber.run)
7372

7473
trigger.clear()
75-
publisher.lolita(1, 2)
76-
trigger.wait()
77-
print 'done'
74+
# We need this retry logic to wait that the subscriber.run coroutine starts
75+
# reading (the published messages will go to /dev/null until then).
76+
for attempt in xrange(0, 10):
77+
publisher.lolita(1, 2)
78+
if trigger.wait(0.2):
79+
print 'done'
80+
return
7881

82+
raise RuntimeError("The subscriber didn't receive any published message")
7983

8084
def test_pushpull_composite():
8185
endpoint = random_ipc_endpoint()
@@ -101,7 +105,6 @@ def lolita(self, a, b):
101105
print 'done'
102106

103107

104-
@skip("PUB/SUB is badly broken in ZMQ and make this test fails")
105108
def test_pubsub_composite():
106109
endpoint = random_ipc_endpoint()
107110
trigger = gevent.event.Event()
@@ -121,6 +124,12 @@ def lolita(self, a, b):
121124
gevent.spawn(subscriber.run)
122125

123126
trigger.clear()
124-
publisher.lolita(1, 2)
125-
trigger.wait()
126-
print 'done'
127+
# We need this retry logic to wait that the subscriber.run coroutine starts
128+
# reading (the published messages will go to /dev/null until then).
129+
for attempt in xrange(0, 10):
130+
publisher.lolita(1, 2)
131+
if trigger.wait(0.2):
132+
print 'done'
133+
return
134+
135+
raise RuntimeError("The subscriber didn't receive any published message")

0 commit comments

Comments
 (0)