def test_get_remaining_time(self): """get_remaining_time() decreases as the transaction prgresses.""" time = self.mocker.replace('time.time') with self.mocker.order(): self.expect(time()).result(50) self.expect(time()).result(100) self.expect(time()).result(150) self.mocker.replay() timeout_tracer = StorageTimeoutTracer(max_time=75) timer.start_transaction() # 50 seconds have elapsed. self.assertEqual(timeout_tracer.get_remaining_time(), 25) # Another 50 seconds elapse. The remaining time is clamped at zero. self.assertEqual(timeout_tracer.get_remaining_time(), 0)
def test_get_remaining_time_outside_transaction(self): """Outside of a transaction get_remaining_time() returns max_time.""" timeout_tracer = StorageTimeoutTracer(max_time=75) # Outside of transaction, return max_time. self.assertEqual(timeout_tracer.get_remaining_time(), 75)