示例#1
0
def test__calculate_timeout__engagement_is_shorter_than_timeout(
    freezer,  # This freezes time so that timeout can be compared with ==
    mock_engagement_manager: mock.MagicMock,
    engagement_credentials: EngagementCredentials,
):
    """
    Tests that the original request timeout is truncated when time until engagement expiration is sooner than timeout.
    """
    mock_engagement_manager.get_engagement.return_value = {}
    client_timeout = 1.0
    seconds_left = 0.5
    qpu_client = QPUClient(
        quantum_processor_id="some-processor",
        engagement_manager=mock_engagement_manager,
        request_timeout=client_timeout,
    )
    _engagement = engagement(
        quantum_processor_id="some-processor",
        seconds_left=seconds_left,
        credentials=engagement_credentials,
        port=1234,
    )
    mock_engagement_manager.get_engagement.return_value = _engagement

    assert qpu_client._calculate_timeout(
        engagement=_engagement) == seconds_left
示例#2
0
def test__calculate_timeout__engagement_is_longer_than_timeout(
    mock_engagement_manager: mock.MagicMock,
    engagement_credentials: EngagementCredentials,
):
    """
    Tests that the original request timeout is honored when time until engagement expiration is longer than timeout.
    """
    client_timeout = 0.1
    qpu_client = QPUClient(
        quantum_processor_id="some-processor",
        engagement_manager=mock_engagement_manager,
        request_timeout=client_timeout,
    )
    _engagement = engagement(
        quantum_processor_id="some-processor",
        seconds_left=qpu_client.timeout * 10,
        credentials=engagement_credentials,
        port=1234,
    )
    mock_engagement_manager.get_engagement.return_value = _engagement

    assert qpu_client._calculate_timeout(
        engagement=_engagement) == client_timeout