def test_logout_1(self): """ Test that a logout packet is send. """ mock = Sysmock() mock.system.add_unused_local_address(CLIENT) with patch(mock): loop = Mainloop() mock.expect_tcp_syn(CLIENT, SERVER) mock.do_tcp_syn_ack(SERVER, CLIENT) mock.do_tcp_input(SERVER, CLIENT, packets.welcome()) conn = NxtcpConnection(loop, SERVER.address) mock.run_events(loop.run_once) # the expected packet mock.expect_tcp_output(CLIENT, SERVER, packets.logout(name=b'name', )) # put the verb upstream conn.send_verb(verbs.LogoutVerb(name=b'name', )) mock.run_events(loop.run_once)
def test_request_2(self): """ Test that a request packet is send. """ mock = Sysmock() mock.system.add_unused_local_address(CLIENT) with patch(mock): loop = Mainloop() mock.expect_tcp_syn(CLIENT, SERVER) mock.do_tcp_syn_ack(SERVER, CLIENT) mock.do_tcp_input(SERVER, CLIENT, packets.welcome()) conn = NxtcpConnection(loop, SERVER.address) mock.run_events(loop.run_once) # the expected packet mock.expect_tcp_output( CLIENT, SERVER, packets.request( name=b'name', unidirectional=True, messageref=0, timeout_ms=0, payload=b'payload', )) # put the verb upstream conn.send_verb( verbs.RequestVerb( name=b'name', unidirectional=True, messageref=None, timeout=None, payload=b'payload', )) mock.run_events(loop.run_once)
def test_keepalive_1(self): """ Test if the connection will respond with a pong when the server sends a ping. """ mock = Sysmock() mock.system.add_unused_local_address(CLIENT) with patch(mock): loop = Mainloop() mock.expect_tcp_syn(CLIENT, SERVER) mock.do_tcp_syn_ack(SERVER, CLIENT) mock.do_tcp_input(SERVER, CLIENT, packets.welcome()) conn = NxtcpConnection(loop, SERVER.address) mock.expect_sleep(5.0) mock.do_tcp_input(SERVER, CLIENT, packets.ping()) mock.expect_tcp_output(CLIENT, SERVER, packets.pong()) mock.run_events(loop.run_once)
def test_subscribe_1(self): """ Test that a subscribe packet is send. """ mock = Sysmock() mock.system.add_unused_local_address(CLIENT) with patch(mock): loop = Mainloop() mock.expect_tcp_syn(CLIENT, SERVER) mock.do_tcp_syn_ack(SERVER, CLIENT) mock.do_tcp_input(SERVER, CLIENT, packets.welcome()) conn = NxtcpConnection(loop, SERVER.address) mock.run_events(loop.run_once) # the expected packet mock.expect_tcp_output( CLIENT, SERVER, packets.subscribe( messageref=1234, name=b'name', topic=b'topic', )) # put the verb upstream conn.send_verb( verbs.SubscribeVerb( messageref=1234, name=b'name', topic=b'topic', )) mock.run_events(loop.run_once)