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