def test_delay_handler(self): handler = deproxy.delay(3, deproxy.simple_handler) t1 = time.time() mc = self.deproxy.make_request("http://localhost:%i/" % self.deproxy_port, default_handler=handler) t2 = time.time() self.assertEquals(int(mc.received_response.code), 200) self.assertGreaterEqual(t2 - t1, 3) self.assertLessEqual(t2 - t1, 3.5)
def test_delay_handler(self): handler = deproxy.delay(3, deproxy.simple_handler) t1 = time.time() mc = self.deproxy.make_request('http://localhost:%i/' % self.deproxy_port, default_handler=handler) t2 = time.time() self.assertEquals(int(mc.received_response.code), 200) self.assertGreaterEqual(t2 - t1, 3) self.assertLessEqual(t2 - t1, 3.5)
def test_orphaned_handling(self): delayed_handler = deproxy.delay(2, deproxy.simple_handler) self.long_running_mc = None class Helper: mc = None helper = Helper() def other_thread(): mc = self.deproxy.make_request("http://localhost:%i/" % self.deproxy_port, default_handler=delayed_handler) helper.mc = mc t = threading.Thread(target=other_thread) t.daemon = True t.start() self.other_client.make_request("http://localhost:%i/" % self.deproxy_port) t.join() self.assertEqual(len(helper.mc.orphaned_handlings), 1)
def test_orphaned_handling(self): delayed_handler = deproxy.delay(2, deproxy.simple_handler) self.long_running_mc = None class Helper: mc = None helper = Helper() def other_thread(): mc = self.deproxy.make_request('http://localhost:%i/' % self.deproxy_port, default_handler=delayed_handler) helper.mc = mc t = threading.Thread(target=other_thread) t.daemon = True t.start() self.other_client.make_request('http://localhost:%i/' % self.deproxy_port) t.join() self.assertEqual(len(helper.mc.orphaned_handlings), 1)