Skip to content

Commit 2034727

Browse files
authored
Merge pull request #183 from asherf/fix-tests
Fix flaky tests by adjusting bucket values.
2 parents cc16d98 + 7d52f04 commit 2034727

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

django_prometheus/tests/end2end/testapp/test_middleware.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.test import SimpleTestCase
1+
from django.test import SimpleTestCase, override_settings
22
from django_prometheus.testutils import PrometheusTestCaseMixin
33
from testapp.views import ObjectionException
44

@@ -19,6 +19,9 @@ def T(metric_name):
1919
return "%s_total" % M(metric_name)
2020

2121

22+
@override_settings(
23+
PROMETHEUS_LATENCY_BUCKETS=(0.05, 1.0, 2.0, 4.0, 5.0, 10.0, float("inf"))
24+
)
2225
class TestMiddlewareMetrics(PrometheusTestCaseMixin, SimpleTestCase):
2326
"""Test django_prometheus.middleware.
2427
@@ -98,8 +101,8 @@ def test_request_counters(self):
98101
def test_latency_histograms(self):
99102
# Caution: this test is timing-based. This is not ideal. It
100103
# runs slowly (each request to /slow takes at least .1 seconds
101-
# to complete) and it may be flaky when run on very slow
102-
# systems.
104+
# to complete), to eliminate flakiness we adjust the buckets used
105+
# in the test suite.
103106

104107
registry = self.saveRegistry()
105108

@@ -134,7 +137,7 @@ def test_exception_latency_histograms(self):
134137
registry,
135138
2,
136139
M("requests_latency_seconds_by_view_method_bucket"),
137-
le="0.05",
140+
le="2.0",
138141
view="testapp.views.objection",
139142
method="GET",
140143
)

0 commit comments

Comments
 (0)