Example #1
0
    def test_wait_healthcheck_timeout(self, requests):
        nginx = NginxDAV()

        def side_effect(url, timeout):
            raise Exception('some error')

        requests.get.side_effect = side_effect
        with self.assertRaises(Exception):
            nginx.wait_healthcheck('myhost.com', timeout=2)
        self.assertGreaterEqual(requests.get.call_count, 2)
        requests.get.assert_has_call('http://myhost.com:8089/healthcheck', timeout=2)
Example #2
0
    def test_wait_healthcheck_timeout(self, requests):
        nginx = NginxDAV()

        def side_effect(url, timeout):
            raise Exception('some error')

        requests.get.side_effect = side_effect
        with self.assertRaises(Exception):
            nginx.wait_healthcheck('myhost.com', timeout=2)
        self.assertGreaterEqual(requests.get.call_count, 2)
        requests.get.assert_has_call('http://myhost.com:8089/healthcheck', timeout=2)
Example #3
0
    def test_wait_healthcheck(self, requests):
        nginx = NginxDAV()
        count = [0]
        response = mock.Mock()
        response.status_code = 200
        response.text = 'WORKING'

        def side_effect(url, timeout):
            count[0] += 1
            if count[0] < 2:
                raise Exception('some error')
            return response

        requests.get.side_effect = side_effect
        nginx.wait_healthcheck('myhost.com', timeout=5)
        self.assertEqual(requests.get.call_count, 2)
        requests.get.assert_has_call('http://myhost.com:8089/healthcheck', timeout=2)
Example #4
0
    def test_wait_healthcheck(self, requests):
        nginx = NginxDAV()
        count = [0]
        response = mock.Mock()
        response.status_code = 200
        response.text = 'WORKING'

        def side_effect(url, timeout):
            count[0] += 1
            if count[0] < 2:
                raise Exception('some error')
            return response

        requests.get.side_effect = side_effect
        nginx.wait_healthcheck('myhost.com', timeout=5)
        self.assertEqual(requests.get.call_count, 2)
        requests.get.assert_has_call('http://myhost.com:8089/healthcheck', timeout=2)