Пример #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.',
     ])
Пример #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.',
     ])
Пример #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))
Пример #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))
Пример #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))
Пример #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))
Пример #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.')
Пример #8
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.'
     )