|
7 | 7 | from sentry_sdk.integrations.django import DjangoIntegration |
8 | 8 | from tests.integrations.django.myapp.asgi import channels_application |
9 | 9 |
|
| 10 | +try: |
| 11 | + from unittest import mock # python 3.3 and above |
| 12 | +except ImportError: |
| 13 | + import mock # python < 3.3 |
| 14 | + |
10 | 15 | APPS = [channels_application] |
11 | 16 | if django.VERSION >= (3, 0): |
12 | 17 | from tests.integrations.django.myapp.asgi import asgi_application |
@@ -81,32 +86,33 @@ async def test_async_views(sentry_init, capture_events, application): |
81 | 86 | async def test_active_thread_id( |
82 | 87 | sentry_init, capture_envelopes, teardown_profiling, endpoint, application |
83 | 88 | ): |
84 | | - sentry_init( |
85 | | - integrations=[DjangoIntegration()], |
86 | | - traces_sample_rate=1.0, |
87 | | - _experiments={"profiles_sample_rate": 1.0}, |
88 | | - ) |
| 89 | + with mock.patch("sentry_sdk.profiler.PROFILE_MINIMUM_SAMPLES", 0): |
| 90 | + sentry_init( |
| 91 | + integrations=[DjangoIntegration()], |
| 92 | + traces_sample_rate=1.0, |
| 93 | + _experiments={"profiles_sample_rate": 1.0}, |
| 94 | + ) |
89 | 95 |
|
90 | | - envelopes = capture_envelopes() |
| 96 | + envelopes = capture_envelopes() |
91 | 97 |
|
92 | | - comm = HttpCommunicator(application, "GET", endpoint) |
93 | | - response = await comm.get_response() |
94 | | - assert response["status"] == 200, response["body"] |
| 98 | + comm = HttpCommunicator(application, "GET", endpoint) |
| 99 | + response = await comm.get_response() |
| 100 | + assert response["status"] == 200, response["body"] |
95 | 101 |
|
96 | | - await comm.wait() |
| 102 | + await comm.wait() |
97 | 103 |
|
98 | | - data = json.loads(response["body"]) |
| 104 | + data = json.loads(response["body"]) |
99 | 105 |
|
100 | | - envelopes = [envelope for envelope in envelopes] |
101 | | - assert len(envelopes) == 1 |
| 106 | + envelopes = [envelope for envelope in envelopes] |
| 107 | + assert len(envelopes) == 1 |
102 | 108 |
|
103 | | - profiles = [item for item in envelopes[0].items if item.type == "profile"] |
104 | | - assert len(profiles) == 1 |
| 109 | + profiles = [item for item in envelopes[0].items if item.type == "profile"] |
| 110 | + assert len(profiles) == 1 |
105 | 111 |
|
106 | | - for profile in profiles: |
107 | | - transactions = profile.payload.json["transactions"] |
108 | | - assert len(transactions) == 1 |
109 | | - assert str(data["active"]) == transactions[0]["active_thread_id"] |
| 112 | + for profile in profiles: |
| 113 | + transactions = profile.payload.json["transactions"] |
| 114 | + assert len(transactions) == 1 |
| 115 | + assert str(data["active"]) == transactions[0]["active_thread_id"] |
110 | 116 |
|
111 | 117 |
|
112 | 118 | @pytest.mark.asyncio |
|
0 commit comments