コード例 #1
0
def test_resource_timing_sorter():
    mock_queue = MockQueueService("mock-queue")  # mock queue
    uri = "mock://github/events-quick-interval"  # create mock resource

    # create resource
    timings = ResourceTimings()
    resource = Resource(uri, timings, json=True)

    # get mock response
    session = mock_requests.create_mock_session()
    response = session.get(uri)

    resource.timings.update(response, resource.headers)

    # modify interval timing directly and make it trigger
    # in the future
    resource.timings.interval = 2000
    resource.timings.update_timestamp
    resource.timings.update_interval_timestamp()

    sorter = ResourceTimingSorter("test-sorter")
    sorter.sort(resource, ResourceStates.WaitingForInterval, mock_queue)

    def work():
        for n in range(25):
            sorter.sort(resource, ResourceStates.WaitingForInterval,
                        mock_queue)
            gevent.sleep(.10)

    work()

    # sometimes depending on the test runner or machine, things will be slow.
    # rather than assert on very specific timings, just ensure the counters
    # were hit
    assert mock_queue.f1000_calls >= 1
    assert mock_queue.f500_calls >= 1
    assert mock_queue.f250_calls >= 1
    assert mock_queue.f50_calls >= 1
    assert mock_queue.fa_calls >= 1
コード例 #2
0
def test_resource_timing_sorter():
    mock_queue = MockQueueService("mock-queue")  # mock queue
    uri = "mock://github/events-quick-interval"  # create mock resource

    # create resource
    timings = ResourceTimings()
    resource = Resource(uri, timings, json=True)

    # get mock response
    session = mock_requests.create_mock_session()
    response = session.get(uri)

    resource.timings.update(response, resource.headers)

    # modify interval timing directly and make it trigger
    # in the future
    resource.timings.interval = 2000
    resource.timings.update_timestamp
    resource.timings.update_interval_timestamp()

    sorter = ResourceTimingSorter("test-sorter")
    sorter.sort(resource, ResourceStates.WaitingForInterval, mock_queue)

    def work():
        for n in range(25):
            sorter.sort(resource, ResourceStates.WaitingForInterval, mock_queue)
            gevent.sleep(.10)

    work()

    # sometimes depending on the test runner or machine, things will be slow.
    # rather than assert on very specific timings, just ensure the counters
    # were hit
    assert mock_queue.f1000_calls >= 1
    assert mock_queue.f500_calls >= 1
    assert mock_queue.f250_calls >= 1
    assert mock_queue.f50_calls >= 1
    assert mock_queue.fa_calls >= 1
コード例 #3
0
def test_response_parser():
    """
    This test will execute a mock request with mock results.
    :return:
    """
    uri = "mock://github/events/statustest"

    session = mock_requests.create_mock_session()
    response = session.get(uri)
    timings = ResourceTimings()
    resource = Resource(uri, timings, json=True)

    # parse out timings from headers
    # don't worry about getting the body to publish,
    # that is something the service should worry about
    parser = ResponseParser("response-parser")
    parser.parse(response, resource)

    # asserts new timings
    assert timings.interval == int(mock_requests.GLOBAL_MOCK_REQUEST_INTERVAL) * 1000
    assert timings.rate_limit == int(mock_requests.GLOBAL_MOCK_REQUEST_RATELIMIT)
    assert timings.rate_limit_remaining == int(mock_requests.GLOBAL_MOCK_REQUEST_REMAINING)
    assert timings.etag == mock_requests.GLOBAL_MOCK_REQUEST_ETAG1
    assert timings.time_to_reset == int(mock_requests.GLOBAL_MOCK_REQUEST_RESET) * 1000
コード例 #4
0
 def resolve_session(self):
     return mock_requests.create_mock_session()
コード例 #5
0
 def resolve_session(self):
     return mock_requests.create_mock_session()