예제 #1
0
 def test_node_get_next_message(self):
     # Test get_next_message
     now = time.time()
     node = self._create_node()
     # No Messages, return None
     self.assertIsNone(node.get_next_message(now))
     msg = Message()
     msg2 = Message()
     msg.sign_from_node(node)
     msg2.sign_from_node(node)
     now = time.time()
     # Add only 1 message
     node.enqueue_message(msg, now)
     self.assertEquals(node.get_next_message(now + 5), msg)
     now = time.time()
     node.enqueue_message(msg, now)
     node.enqueue_message(msg2, now)
     # Should not return anything since the time is the same
     self.assertIsNone(node.get_next_message(now))
     # Take out 1 message
     self.assertNotIn(node.get_next_message(now + 5),
                      node.MessageQ.Messages)
     # Take out last message
     self.assertNotIn(node.get_next_message(now + 5),
                      node.MessageQ.Messages)
     # No messages left, should return None
     self.assertEquals(node.get_next_message(now + 5), None)
예제 #2
0
 def test_node_reset_peer_stats(self):
     # Test that reset_peers does not break
     now = time.time()
     node = self._create_node()
     node2 = self._create_node()
     node.initialize_stats(node2)
     msg = Message()
     msg.sign_from_node(node)
     stats1 = str(node.Stats.get_stats(["Address", "MessageQueue",
                                        "MessageQueueLength"]))
     # Nothing changes since all are the original defaults
     node.reset_peer_stats(["Address", "MessageQueue",
                            "MessageQueueLength"])
     stats2 = str(node.Stats.get_stats(["Address", "MessageQueue",
                                        "MessageQueueLength"]))
     self.assertEquals(stats1, stats2)
     node.enqueue_message(msg, now)
     stats3 = (node.Stats.get_stats(["Address", "MessageQueue",
                                     "MessageQueueLength"]))
     node.reset_peer_stats(["Address", "MessageQueue",
                            "MessageQueueLength"])
     stats4 = (node.Stats.get_stats(["Address", "MessageQueue",
                                     "MessageQueueLength"]))
     # All values are either sample or value metrics that are not changed
     # by the reset_peer_stats
     self.assertEquals(stats3, stats4)
예제 #3
0
 def test_node_reset_peer_stats(self):
     # Test that reset_peers does not break
     now = time.time()
     node = self._create_node()
     node2 = self._create_node()
     node.initialize_stats(node2)
     msg = Message()
     msg.sign_from_node(node)
     stats1 = str(
         node.Stats.get_stats(
             ["Address", "MessageQueue", "MessageQueueLength"]))
     # Nothing changes since all are the original defaults
     node.reset_peer_stats(
         ["Address", "MessageQueue", "MessageQueueLength"])
     stats2 = str(
         node.Stats.get_stats(
             ["Address", "MessageQueue", "MessageQueueLength"]))
     self.assertEqual(stats1, stats2)
     node.enqueue_message(msg, now)
     stats3 = (node.Stats.get_stats(
         ["Address", "MessageQueue", "MessageQueueLength"]))
     node.reset_peer_stats(
         ["Address", "MessageQueue", "MessageQueueLength"])
     stats4 = (node.Stats.get_stats(
         ["Address", "MessageQueue", "MessageQueueLength"]))
     # All values are either sample or value metrics that are not changed
     # by the reset_peer_stats
     self.assertEqual(stats3, stats4)
예제 #4
0
 def test_node_get_next_message(self):
     # Test get_next_message
     now = time.time()
     node = self._create_node()
     node2 = self._create_node()
     # No Messages, return None
     self.assertIsNone(node.get_next_message(now))
     msg = Message()
     msg2 = Message()
     msg.sign_from_node(node)
     msg2.sign_from_node(node2)
     now = time.time()
     # Add only 1 message
     node.enqueue_message(msg, now)
     self.assertEqual(node.get_next_message(now + 5), msg)
     now = time.time()
     node.enqueue_message(msg, now)
     node.enqueue_message(msg2, now)
     # Should not return anything since the time is the same
     self.assertIsNone(node.get_next_message(now))
     # Take out 1 message
     self.assertNotIn(node.get_next_message(now + 5),
                      node.MessageQ.Messages)
     # Take out last message
     self.assertNotIn(node.get_next_message(now + 5),
                      node.MessageQ.Messages)
     # No messages left, should return None
     self.assertEqual(node.get_next_message(now + 5), None)
예제 #5
0
 def test_node_message_dropped(self):
     # Test behavior if message is believe to be "dropped"
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     oldRTO = node.Estimator.RTO
     node.message_dropped(msg)
     newRTO = node.Estimator.RTO
     # Should increase RTO and "re-add" msg to the MessageQueue
     self.assertLess(oldRTO, newRTO)
     self.assertIn(msg.Identifier, node.MessageQ.Messages)
예제 #6
0
 def test_node_message_dropped(self):
     # Test behavior if message is believe to be "dropped"
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     oldRTO = node.Estimator.RTO
     node.message_dropped(msg)
     newRTO = node.Estimator.RTO
     # Should increase RTO and "re-add" msg to the MessageQueue
     self.assertLess(oldRTO, newRTO)
     self.assertIn(msg.Identifier, node.MessageQ.Messages)
예제 #7
0
 def test_node_enqueue_message(self):
     # Test correct enqueue of a message to MessageQueue
     node = self._create_node()
     before = str(node.MessageQ)
     msg = Message()
     msg.sign_from_node(node)
     now = time.time()
     # Add message
     node.enqueue_message(msg, now)
     after = str(node.MessageQ)
     self.assertNotEqual(before, after)
     self.assertIn(msg.Identifier, node.MessageQ.Messages)
예제 #8
0
 def test_node_message_delivered(self):
     # Test behavior if message is "delivered"
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     node.enqueue_message(msg, time.time())
     oldRTO = node.Estimator.RTO
     node.message_delivered(msg, 2.0)
     newRTO = node.Estimator.RTO
     # Should update RTO and add identifier to MessageQueue
     self.assertLess(oldRTO, newRTO)
     self.assertNotIn(msg.Identifier, node.MessageQ.Messages)
예제 #9
0
 def test_node_dequeue_message_no_message(self):
     # Test that trying to dequeue a message that is not enqueued does not
     # throw an error
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     now = time.time()
     # Msg was never enqueued
     before = str(node.MessageQ)
     node.dequeue_message(msg)
     after = str(node.MessageQ)
     self.assertEqual(before, after)
예제 #10
0
 def test_node_enqueue_message(self):
     # Test correct enqueue of a message to MessageQueue
     node = self._create_node()
     before = str(node.MessageQ)
     msg = Message()
     msg.sign_from_node(node)
     now = time.time()
     # Add message
     node.enqueue_message(msg, now)
     after = str(node.MessageQ)
     self.assertNotEqual(before, after)
     self.assertIn(msg.Identifier, node.MessageQ.Messages)
예제 #11
0
 def test_node_message_delivered(self):
     # Test behavior if message is "delivered"
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     node.enqueue_message(msg, time.time())
     oldRTO = node.Estimator.RTO
     node.message_delivered(msg, 2.0)
     newRTO = node.Estimator.RTO
     # Should update RTO and add identifier to MessageQueue
     self.assertLess(oldRTO, newRTO)
     self.assertNotIn(msg.Identifier, node.MessageQ.Messages)
예제 #12
0
 def test_node_dequeue_message_no_message(self):
     # Test that trying to dequeue a message that is not enqueued does not
     # throw an error
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     now = time.time()
     # Msg was never enqueued
     before = str(node.MessageQ)
     node.dequeue_message(msg)
     after = str(node.MessageQ)
     self.assertEqual(before, after)
예제 #13
0
 def test_node_dequeue_message(self):
     # Test correct enqueue of a message from MessageQueue
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     now = time.time()
     # must enqueue message before able to dequeue
     node.enqueue_message(msg, now)
     before = str(node.MessageQ)
     node.dequeue_message(msg)
     after = str(node.MessageQ)
     self.assertNotEqual(before, after)
     self.assertNotIn(msg.Identifier, node.MessageQ.Messages)
예제 #14
0
 def test_node_dequeue_message(self):
     # Test correct enqueue of a message from MessageQueue
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     now = time.time()
     # must enqueue message before able to dequeue
     node.enqueue_message(msg, now)
     before = str(node.MessageQ)
     node.dequeue_message(msg)
     after = str(node.MessageQ)
     self.assertNotEqual(before, after)
     self.assertNotIn(msg.Identifier, node.MessageQ.Messages)
 def _create_msg(self):
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     return msg
예제 #16
0
 def _create_msg(self):
     node = self._create_node()
     msg = Message()
     msg.sign_from_node(node)
     return msg