test_pubsub.py revision 781d71db
1# Copyright (C) PyZMQ Developers
2# Distributed under the terms of the Modified BSD License.
3
4
5import time
6from unittest import TestCase
7
8import zmq
9
10from zmq.tests import BaseZMQTestCase, have_gevent, GreenTest
11
12
13class TestPubSub(BaseZMQTestCase):
14
15    pass
16
17    # We are disabling this test while an issue is being resolved.
18    def test_basic(self):
19        s1, s2 = self.create_bound_pair(zmq.PUB, zmq.SUB)
20        s2.setsockopt(zmq.SUBSCRIBE,b'')
21        time.sleep(0.1)
22        msg1 = b'message'
23        s1.send(msg1)
24        msg2 = s2.recv()  # This is blocking!
25        self.assertEqual(msg1, msg2)
26
27    def test_topic(self):
28        s1, s2 = self.create_bound_pair(zmq.PUB, zmq.SUB)
29        s2.setsockopt(zmq.SUBSCRIBE, b'x')
30        time.sleep(0.1)
31        msg1 = b'message'
32        s1.send(msg1)
33        self.assertRaisesErrno(zmq.EAGAIN, s2.recv, zmq.NOBLOCK)
34        msg1 = b'xmessage'
35        s1.send(msg1)
36        msg2 = s2.recv()
37        self.assertEqual(msg1, msg2)
38
39if have_gevent:
40    class TestPubSubGreen(GreenTest, TestPubSub):
41        pass
42