def test_gossip_dowrite(self): # Test _dowrite puts a message on the wire core = self._setup(8804) newNode = self._create_node(8805) newNode.is_peer = True core.add_node(newNode) core2 = Gossip pak = Packet() data = "test the pack" pak.Data = data # Test correct sending of bytes status = core._do_write(pak.pack(), newNode) self.assertTrue(status) stats = core.PacketStats.get_stats(["BytesSent"]) self.assertNotEqual(stats["BytesSent"], [0, 0]) # Test failure of message that is too big # This will print out an error core.MaximumPacketSize = 0 status = core._do_write(pak.pack(), newNode) self.assertFalse(status)
def test_pack_unpack(self): # Test packing a paket and a packed packet can be unpacked correctly pak = Packet() data = "test the pack" pak.Data = data # Store original attributes original = [pak.PackedFormat, pak.TimeToLive, pak.SequenceNumber, pak.IsAcknowledgement, pak.IsReliable, str(pak.SenderID)] packed = pak.pack() # Change the packet to see if it will be returned to original pak.SequenceNumber = 1234 pak.unpack(packed) # Store the attrubites of the unpacked pack new = [pak.PackedFormat, pak.TimeToLive, pak.SequenceNumber, pak.IsAcknowledgement, pak.IsReliable, str(pak.SenderID)] self.assertEquals(original, new) self.assertEquals("test the pack", pak.Data)
def test_pack_unpack(self): # Test packing a paket and a packed packet can be unpacked correctly pak = Packet() data = "test the pack" pak.Data = data # Store original attributes original = [ pak.PackedFormat, pak.TimeToLive, pak.SequenceNumber, pak.IsAcknowledgement, pak.IsReliable, str(pak.SenderID) ] packed = pak.pack() # Change the packet to see if it will be returned to original pak.SequenceNumber = 1234 pak.unpack(packed) # Store the attrubites of the unpacked pack new = [ pak.PackedFormat, pak.TimeToLive, pak.SequenceNumber, pak.IsAcknowledgement, pak.IsReliable, str(pak.SenderID) ] self.assertEqual(original, new) self.assertEqual("test the pack", pak.Data.decode())