コード例 #1
0
    def test_custom_circuitbreaking(self):
        custom_threshold = random.randrange(2, 4, 1)
        custom_delay = 5
        os.environ["PYH_CIRCUIT_FAIL_THRESHOLD"] = str(custom_threshold)
        os.environ["PYH_CIRCUIT_DELAY"] = str(custom_delay)

        pyhystrix.Init()

        temp = {"retried": 0}
        retries = custom_threshold + 2
        url = new_url()

        def _fake_new_conn(self):
            temp["retried"] += 1
            raise ConnectTimeoutError(self, "", (self.host, self.timeout))

        with CustomFailureMock(_fake_new_conn):
            try:
                requests.get(url, max_tries=retries)
            except ConnectionError:
                pass
        self.assertEqual(temp["retried"], custom_threshold)

        time.sleep(custom_delay)
        temp["retried"] = 0

        with CustomFailureMock(_fake_new_conn):
            try:
                requests.get(url, max_tries=retries)
            except ConnectionError:
                pass
            self.assertEqual(temp["retried"], 1)

        del os.environ["PYH_CIRCUIT_FAIL_THRESHOLD"]
        del os.environ["PYH_CIRCUIT_DELAY"]
コード例 #2
0
 def setUp(self):
     pyhystrix.Init()
     self.handler = CustomLogHandler()
     logger.addHandler(self.handler)
コード例 #3
0
 def setUp(self):
     pyhystrix.Init()