Example #1
0
 def test_simple(self):
     simple_gen._messages = []
     self.assertEqual(simple_gen._messages, [])
     waiter = Waiter(simple_gen, interval=1)
     waiter.join()
     self.assertEqual(simple_gen._messages, [
         'Nope.',
         'Yup.',
     ])
Example #2
0
 def test_simple(self):
     simple_gen._messages = []
     self.assertEqual(simple_gen._messages, [])
     waiter = Waiter(simple_gen, interval=1)
     waiter.join()
     self.assertEqual(simple_gen._messages, [
         'Nope.',
         'Yup.',
     ])
Example #3
0
    def test_exceeded_retries(self):
        client = Failed()
        waiter = Waiter(client.request,
                        args=['http://aws.amazon.com/'],
                        kwargs={'timeout': 1},
                        retries=1,
                        interval=1)

        with self.assertRaises(RetriesExceededError) as cm:
            final = waiter.join()

        self.assertTrue('exceeded the number of retries' in str(cm.exception))
Example #4
0
    def test_exceeded_timeout(self):
        client = Complex()
        waiter = Waiter(client.request,
                        args=['http://aws.amazon.com/'],
                        kwargs={'timeout': 0.3},
                        retries=1,
                        interval=1)

        with self.assertRaises(TimeoutExceededError) as cm:
            final = waiter.join(timeout=0.1)

        self.assertTrue('exceeded the timeout' in str(cm.exception))
Example #5
0
    def test_exceeded_retries(self):
        client = Failed()
        waiter = Waiter(
            client.request,
            args=['http://aws.amazon.com/'],
            kwargs={'timeout': 1},
            retries=1,
            interval=1
        )

        with self.assertRaises(RetriesExceededError) as cm:
            final = waiter.join()

        self.assertTrue('exceeded the number of retries' in str(cm.exception))
Example #6
0
    def test_exceeded_timeout(self):
        client = Complex()
        waiter = Waiter(
            client.request,
            args=['http://aws.amazon.com/'],
            kwargs={'timeout': 0.3},
            retries=1,
            interval=1
        )

        with self.assertRaises(TimeoutExceededError) as cm:
            final = waiter.join(timeout=0.1)

        self.assertTrue('exceeded the timeout' in str(cm.exception))
Example #7
0
 def test_complex(self):
     client = Complex()
     waiter = Waiter(client.request,
                     args=['http://aws.amazon.com/'],
                     kwargs={'timeout': 5},
                     retries=1,
                     interval=0.5)
     waiter.messages = []
     final = waiter.join(before_attempt=before_running,
                         before_wait=before_sleeping)
     self.assertEqual(waiter.messages, [
         "About to attempt 'request'...",
         "Whelp, that didn't work. Sleeping for 0.5...",
         "About to attempt 'request'..."
     ])
     self.assertEqual(
         final,
         'Got a 200 from http://aws.amazon.com/ in less than 5 seconds.')
Example #8
0
    def test_errors(self):
        client = Complex()

        # First, invalid retries
        with self.assertRaises(ValueError) as cm:
            waiter = Waiter(client.request,
                            args=['http://aws.amazon.com/'],
                            kwargs={'timeout': 5},
                            retries=-1,
                            interval=0.5)

        self.assertTrue('Retries must be greater' in str(cm.exception))

        # Then invalid interval
        with self.assertRaises(ValueError) as cm:
            waiter = Waiter(client.request,
                            args=['http://aws.amazon.com/'],
                            kwargs={'timeout': 5},
                            retries=0,
                            interval=-0.1)

        self.assertTrue('Interval must be greater' in str(cm.exception))
Example #9
0
 def test_complex(self):
     client = Complex()
     waiter = Waiter(
         client.request,
         args=['http://aws.amazon.com/'],
         kwargs={'timeout': 5},
         retries=1,
         interval=0.5
     )
     waiter.messages = []
     final = waiter.join(
         before_attempt=before_running,
         before_wait=before_sleeping
     )
     self.assertEqual(waiter.messages, [
         "About to attempt 'request'...",
         "Whelp, that didn't work. Sleeping for 0.5...",
         "About to attempt 'request'..."
     ])
     self.assertEqual(
         final,
         'Got a 200 from http://aws.amazon.com/ in less than 5 seconds.'
     )