def test_get_all_returns_all_ready_tasks(self): task1 = make_task(duet.completed_future(None)) task2 = make_task(duet.completed_future(None)) task3 = make_task(duet.AwaitableFuture()) task4 = make_task(duet.completed_future(None)) rs = impl.ReadySet() rs.register(task1) rs.register(task2) rs.register(task3) rs.register(task4) tasks = rs.get_all() assert tasks == [task1, task2, task4]
def test_task_added_at_most_once(self): task = make_task(duet.completed_future(None)) rs = impl.ReadySet() rs.register(task) rs.register(task) tasks = rs.get_all() assert tasks == [task]
def test_futures_not_flushed_if_tasks_ready(self): future = CompleteOnFlush() task1 = make_task(future) task2 = make_task(duet.completed_future(None)) rs = impl.ReadySet() rs.register(task1) rs.register(task2) tasks = rs.get_all() assert tasks == [task2] assert not future.flushed
def func(value): return duet.completed_future(value * 2)
@uses_async_mock @mock.patch.object(quantum, 'QuantumEngineServiceAsyncClient', autospec=True) def test_api_retry_5xx_errors(client_constructor): grpc_client = setup_mock_(client_constructor) grpc_client.get_quantum_program.side_effect = exceptions.ServiceUnavailable('internal error') client = EngineClient(max_retry_delay_seconds=0.3) with pytest.raises(TimeoutError, match='Reached max retry attempts.*internal error'): client.get_program('proj', 'prog', False) assert grpc_client.get_quantum_program.call_count == 3 @uses_async_mock @mock.patch('duet.sleep', return_value=duet.completed_future(None)) @mock.patch.object(quantum, 'QuantumEngineServiceAsyncClient', autospec=True) def test_api_retry_times(client_constructor, mock_sleep): grpc_client = setup_mock_(client_constructor) grpc_client.get_quantum_program.side_effect = exceptions.ServiceUnavailable('internal error') client = EngineClient(max_retry_delay_seconds=0.3) with pytest.raises(TimeoutError, match='Reached max retry attempts.*internal error'): client.get_program('proj', 'prog', False) assert grpc_client.get_quantum_program.call_count == 3 assert len(mock_sleep.call_args_list) == 2 assert all(x == y for (x, _), y in zip(mock_sleep.call_args_list, [(0.1,), (0.2,)])) @uses_async_mock