Пример #1
0
    def test_retry_logic(self):
        peer = PeerId('testnet')
        self.assertTrue(peer.can_retry(0))

        retry_interval = peer.retry_interval

        peer.increment_retry_attempt(0)
        self.assertFalse(peer.can_retry(0))
        self.assertFalse(peer.can_retry(retry_interval - 1))
        self.assertTrue(peer.can_retry(retry_interval))
        self.assertTrue(peer.can_retry(retry_interval + 1))

        peer.increment_retry_attempt(0)
        self.assertFalse(peer.can_retry(retry_interval))

        retry_interval *= settings.PEER_CONNECTION_RETRY_INTERVAL_MULTIPLIER
        self.assertFalse(peer.can_retry(retry_interval - 1))
        self.assertTrue(peer.can_retry(retry_interval))
        self.assertTrue(peer.can_retry(retry_interval))

        # Retry until we reach max retry interval.
        while peer.retry_interval < settings.PEER_CONNECTION_RETRY_MAX_RETRY_INTERVAL:
            peer.increment_retry_attempt(0)
        # We need to call it once more because peer.retry_interval is always one step behind.
        peer.increment_retry_attempt(0)

        # Confirm we are at the max retry interval.
        self.assertFalse(
            peer.can_retry(settings.PEER_CONNECTION_RETRY_MAX_RETRY_INTERVAL -
                           1))
        self.assertTrue(
            peer.can_retry(settings.PEER_CONNECTION_RETRY_MAX_RETRY_INTERVAL))
        self.assertTrue(
            peer.can_retry(settings.PEER_CONNECTION_RETRY_MAX_RETRY_INTERVAL +
                           1))

        # It shouldn't change with another retry.
        peer.increment_retry_attempt(0)
        self.assertFalse(
            peer.can_retry(settings.PEER_CONNECTION_RETRY_MAX_RETRY_INTERVAL -
                           1))
        self.assertTrue(
            peer.can_retry(settings.PEER_CONNECTION_RETRY_MAX_RETRY_INTERVAL))
        self.assertTrue(
            peer.can_retry(settings.PEER_CONNECTION_RETRY_MAX_RETRY_INTERVAL +
                           1))

        # Finally, reset it.
        peer.reset_retry_timestamp()
        self.assertTrue(peer.can_retry(0))
Пример #2
0
    def test_retry_connection(self):
        p = PeerId()
        interval = p.retry_interval
        p.update_retry_timestamp(0)
        self.assertEqual(
            settings.PEER_CONNECTION_RETRY_INTERVAL_MULTIPLIER * interval,
            p.retry_interval)
        self.assertEqual(p.retry_interval, p.retry_timestamp)

        # when retry_interval is already 180
        p.retry_interval = 190
        p.update_retry_timestamp(0)
        self.assertEqual(180, p.retry_interval)

        # reset
        p.reset_retry_timestamp()
        self.assertEqual(p.retry_interval, 5)
        self.assertEqual(p.retry_timestamp, 0)
Пример #3
0
    def test_retry_connection(self):
        p = PeerId()
        interval = p.retry_interval
        p.increment_retry_attempt(0)
        self.assertEqual(
            settings.PEER_CONNECTION_RETRY_INTERVAL_MULTIPLIER * interval,
            p.retry_interval)
        self.assertEqual(interval, p.retry_timestamp)

        # when retry_interval is already 180
        p.retry_interval = settings.PEER_CONNECTION_RETRY_MAX_RETRY_INTERVAL + 10
        p.increment_retry_attempt(0)
        self.assertEqual(settings.PEER_CONNECTION_RETRY_MAX_RETRY_INTERVAL,
                         p.retry_interval)

        # reset
        p.reset_retry_timestamp()
        self.assertEqual(p.retry_interval, 5)
        self.assertEqual(p.retry_timestamp, 0)