2
# Copyright (c) 2010 Brian E. Granger
4
# This file is part of pyzmq.
6
# pyzmq is free software; you can redistribute it and/or modify it under
7
# the terms of the Lesser GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
11
# pyzmq is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# Lesser GNU General Public License for more details.
16
# You should have received a copy of the Lesser GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1
#-----------------------------------------------------------------------------
2
# Copyright (c) 2010-2012 Brian Granger, Min Ragan-Kelley
4
# This file is part of pyzmq
6
# Distributed under the terms of the New BSD License. The full license is in
7
# the file COPYING.BSD, distributed as part of this software.
8
#-----------------------------------------------------------------------------
20
10
#-----------------------------------------------------------------------------
24
14
from unittest import TestCase
27
from zmq.tests import BaseZMQTestCase
17
from zmq.tests import BaseZMQTestCase, have_gevent, GreenTest
29
19
#-----------------------------------------------------------------------------
35
25
def test_basic(self):
36
26
s1, s2 = self.create_bound_pair(zmq.REQ, zmq.REP)
38
msg1 = 'message 1'.encode()
39
29
msg2 = self.ping_pong(s1, s2, msg1)
40
30
self.assertEquals(msg1, msg2)
43
33
s1, s2 = self.create_bound_pair(zmq.REQ, zmq.REP)
45
35
for i in range(10):
47
37
msg2 = self.ping_pong(s1, s2, msg1)
48
38
self.assertEquals(msg1, msg2)
50
40
def test_bad_send_recv(self):
51
41
s1, s2 = self.create_bound_pair(zmq.REQ, zmq.REP)
52
for copy in (True,False):
53
self.assertRaisesErrno(zmq.EFSM, s1.recv, copy=copy)
54
self.assertRaisesErrno(zmq.EFSM, s2.send, 'asdf'.encode(), copy=copy)
43
if zmq.zmq_version() != '2.1.8':
44
# this doesn't work on 2.1.8
45
for copy in (True,False):
46
self.assertRaisesErrno(zmq.EFSM, s1.recv, copy=copy)
47
self.assertRaisesErrno(zmq.EFSM, s2.send, b'asdf', copy=copy)
56
49
# I have to have this or we die on an Abort trap.
57
msg1 = 'asdf'.encode()
58
51
msg2 = self.ping_pong(s1, s2, msg1)
59
52
self.assertEquals(msg1, msg2)
71
64
def test_large_msg(self):
72
65
s1, s2 = self.create_bound_pair(zmq.REQ, zmq.REP)
73
msg1 = 10000*'X'.encode()
75
68
for i in range(10):
76
69
msg2 = self.ping_pong(s1, s2, msg1)
77
70
self.assertEquals(msg1, msg2)
73
class TestReqRepGreen(GreenTest, TestReqRep):