def fake_request(self, operation, on_success=lambda: None, on_error=lambda: None): request = SQuery(Task(self.fake_client()), operation, 1, lambda s: None) request.on_error = on_error request.on_success = on_success return request
def query(self, service_name, operation, on_success=lambda: None, on_error=lambda: None): request = Query(self.a_running_task(), operation, 1, lambda s: None) request.on_success = on_success request.on_error = on_error self.send(request, service_name) return request
def do_test_response_time(self, sent_at, replied_at): sender = MagicMock() type(sender.schedule).time_now = PropertyMock(side_effect=[sent_at, replied_at]) request = Query(Task(sender), "foo_operation", 1, lambda s: None) recipient = MagicMock() request.send_to(recipient) request.reply_success() self.assertEqual(replied_at - sent_at, request.response_time)
def test_response_time_on_error(self): sender = MagicMock() sender.schedule.time = MagicMock(return_value=(5, 10, 15)) request = Query(Task(sender), "foo_operation", 1, lambda s: None) recipient = MagicMock() request.send_to(recipient) request.reply_error() with self.assertRaises(AssertionError): request.response_time
def do_test_response_time(self, sent_at, replied_at): sender = MagicMock() type(sender.schedule).time_now = PropertyMock(side_effect = [sent_at, replied_at] ) request = Query(Task(sender), "foo_operation", 1, lambda s: None) recipient = MagicMock() request.send_to(recipient) request.reply_success() self.assertEqual(replied_at - sent_at, request.response_time)
def test_response_time_on_error(self): sender = MagicMock() sender.schedule.time = MagicMock(return_value = (5, 10, 15)) request = Query(Task(sender), "foo_operation", 1, lambda s: None) recipient = MagicMock() request.send_to(recipient) request.reply_error() with self.assertRaises(AssertionError): request.response_time
def create_query(self, task, operation, priority, continuation): return Query(task, operation, priority, continuation)
def query(self, service_name, operation, on_success=lambda:None, on_error=lambda:None): request = Query(self.a_running_task(), operation, 1, lambda s:None) request.on_success = on_success request.on_error = on_error self.send(request, service_name) return request