ZIO
Python and C++ interface to ZeroMQ and Zyre
test_node.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 '''
3 test zio.Node
4 '''
5 
6 import zio
7 import zmq
8 import time
9 
10 import unittest
11 
12 class TestNode(unittest.TestCase):
13 
14  origin = 42
15 
16  def setUp(self):
17  self.snode = zio.Node("server", self.origin)
18  sport = self.snode.port("sport", zmq.SERVER)
19  sport.bind()
20  self.snode.online()
21 
22  self.cnode = zio.Node("client")
23  cport = self.cnode.port("cport", zmq.CLIENT)
24  cport.connect("server", "sport")
25  self.cnode.online()
26 
27  def test_noport(self):
28  try:
29  p = self.snode.port("no such port")
30  except KeyError:
31  return
32  raise RuntimeError("zio.Node should raise error on unknown port")
33 
34  def test_pingpong(self):
35  sport = self.snode.port("sport")
36  cport = self.cnode.port("cport")
37 
38  msg = zio.Message(form="TEXT", label="This is a message to you, Rudy",
39  payload=["Stop your messing around",
40  "Better think of your future"])
41  cport.send(msg);
42  msg2 = sport.recv(timeout=1000)
43  msg2.payload=['Time you straighten right out',
44  "Else you'll wind up in jail"]
45  assert (type(msg2.payload[0]) == bytes)
46  #print("sending to rid %d" % msg2.routing_id)
47  sport.send(msg2) # should forward the routing_id
48  msg3 = cport.recv(timeout=1000)
49  assert (msg2.payload[0] == msg3.payload[0])
50 
51  def tearDown(self):
52  self.snode.offline()
53  self.cnode.offline()
54 
55 if __name__ == '__main__':
56  unittest.main()
57 
An identified vertex in a ported, directed graph.
Definition: node.hpp:30
def tearDown(self)
Definition: test_node.py:51
def test_pingpong(self)
Definition: test_node.py:34
def test_noport(self)
Definition: test_node.py:27
def setUp(self)
Definition: test_node.py:16
a ZIO message
Definition: message.hpp:59