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