Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly close tcp connection in Prometheus test #121

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,12 @@ def test_prometheus_metrics_worker_restart(self, web_container):
restart can be observed after the worker restart.
"""
web_client = web_container.http_client()
response = web_client.get('/metrics', headers={'Connection': 'close'})
response = web_client.get('/metrics')

[sample] = http_requests_total_for_view(
response.text, 'prometheus-django-metrics')
assert_that(sample.value, Equals(1.0))
response.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this, given that we already read the whole request body (with response.text above) and all it does is release the connection back to the pool for reuse.


# Signal Gunicorn so that it restarts the worker(s)
# http://docs.gunicorn.org/en/latest/signals.html
Expand All @@ -382,6 +383,8 @@ def test_prometheus_metrics_worker_restart(self, web_container):
matcher, web_container.wait_timeout)

# Now try make another request and ensure the counter was incremented
# We use a new client here to ensure the old connection isn't reused
web_client = web_container.http_client()
response = web_client.get('/metrics')
[sample] = http_requests_total_for_view(
response.text, 'prometheus-django-metrics')
Expand Down