Esempio n. 1
0
def test_wsgi_request_metrics(wsgi_env, context):
    wsgi_env['VIEW_NAME'] = 'view'
    request = wsgi.TaliskerWSGIRequest(wsgi_env, start_response, [])
    request.duration = 1.0
    request.metrics(request.get_metadata())
    assert context.statsd[0] == 'wsgi.requests.view.GET.timeout:1|c'
    assert context.statsd[1] == 'wsgi.latency.view.GET.timeout:1000.000000|ms'
Esempio n. 2
0
def test_wsgi_request_start_response(wsgi_env, start_response):
    wsgi_env['REQUEST_ID'] = 'ID'
    headers = {'HEADER': 'VALUE'}
    request = wsgi.TaliskerWSGIRequest(wsgi_env, start_response, headers)
    request.start_response('200 OK', [], None)
    request.call_start_response()
    assert request.status_code == 200
    assert start_response.status == request.status == '200 OK'
    assert start_response.headers == request.headers == [
        ('HEADER', 'VALUE'),
        ('X-Request-Id', 'ID'),
    ]
    assert start_response.exc_info is request.exc_info is None
Esempio n. 3
0
    def run(env=None, status='200 OK', headers=None, body=None, duration=1):
        if env:
            wsgi_env.update(env)
        if body is None:
            body = [b'0' * 1000]

        with freeze_time() as frozen:
            wsgi_env['start_time'] = time.time()
            request = wsgi.TaliskerWSGIRequest(wsgi_env, start_response, [])
            frozen.tick(duration)
            request.start_response(status, headers or [], None)
            iter = request.wrap_response(body)
            response = list(iter)
            iter.close()

        return dict(start_response.headers), response
Esempio n. 4
0
def test_wsgi_request_log_timeout(wsgi_env, context):
    request = wsgi.TaliskerWSGIRequest(wsgi_env, start_response, [])
    request.timedout = True
    request.duration = 1.0
    request.log(request.get_metadata())
    context.assert_log(
        name='talisker.wsgi',
        msg='GET /',
        extra=dict([
            ('method', 'GET'),
            ('path', '/'),
            ('duration_ms', 1000.0),
            ('ip', '127.0.0.1'),
            ('proto', 'HTTP/1.0'),
            ('timeout', True),
        ]),
    )