Skip to content

Commit d1772a2

Browse files
committed
fix more tests
1 parent 4b41f91 commit d1772a2

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed

tests/integrations/django/asgi/test_asgi.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ async def test_async_views(sentry_init, capture_events, application):
104104
@pytest.mark.skipif(
105105
django.VERSION < (3, 1), reason="async views have been introduced in Django 3.1"
106106
)
107-
async def test_active_thread_id(sentry_init, capture_envelopes, endpoint, application):
107+
async def test_active_thread_id(
108+
sentry_init, capture_envelopes, teardown_profiling, endpoint, application
109+
):
108110
with mock.patch(
109111
"sentry_sdk.profiler.transaction_profiler.PROFILE_MINIMUM_SAMPLES", 0
110112
):
@@ -121,17 +123,18 @@ async def test_active_thread_id(sentry_init, capture_envelopes, endpoint, applic
121123
await comm.wait()
122124

123125
assert response["status"] == 200, response["body"]
124-
assert len(envelopes) == 1
125126

126-
profiles = [item for item in envelopes[0].items if item.type == "profile"]
127-
assert len(profiles) == 1
127+
assert len(envelopes) == 1
128+
129+
profiles = [item for item in envelopes[0].items if item.type == "profile"]
130+
assert len(profiles) == 1
128131

129-
data = json.loads(response["body"])
132+
data = json.loads(response["body"])
130133

131-
for item in profiles:
132-
transactions = item.payload.json["transactions"]
133-
assert len(transactions) == 1
134-
assert str(data["active"]) == transactions[0]["active_thread_id"]
134+
for item in profiles:
135+
transactions = item.payload.json["transactions"]
136+
assert len(transactions) == 1
137+
assert str(data["active"]) == transactions[0]["active_thread_id"]
135138

136139
transactions = [item for item in envelopes[0].items if item.type == "transaction"]
137140
assert len(transactions) == 1

tests/integrations/quart/test_quart.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -539,41 +539,47 @@ async def dispatch_request(self):
539539

540540

541541
@pytest.mark.parametrize("endpoint", ["/sync/thread_ids", "/async/thread_ids"])
542-
@mock.patch("sentry_sdk.profiler.transaction_profiler.PROFILE_MINIMUM_SAMPLES", 0)
543542
@pytest.mark.asyncio
544-
async def test_active_thread_id(sentry_init, capture_envelopes, endpoint):
545-
sentry_init(
546-
traces_sample_rate=1.0,
547-
profiles_sample_rate=1.0,
548-
)
549-
app = quart_app_factory()
543+
async def test_active_thread_id(
544+
sentry_init, capture_envelopes, teardown_profiling, endpoint
545+
):
546+
with mock.patch(
547+
"sentry_sdk.profiler.transaction_profiler.PROFILE_MINIMUM_SAMPLES", 0
548+
):
549+
sentry_init(
550+
traces_sample_rate=1.0,
551+
profiles_sample_rate=1.0,
552+
)
553+
app = quart_app_factory()
550554

551-
envelopes = capture_envelopes()
555+
envelopes = capture_envelopes()
552556

553-
async with app.test_client() as client:
554-
response = await client.get(endpoint)
555-
assert response.status_code == 200
557+
async with app.test_client() as client:
558+
response = await client.get(endpoint)
559+
assert response.status_code == 200
556560

557-
data = json.loads(await response.get_data(as_text=True))
561+
data = json.loads(await response.get_data(as_text=True))
558562

559-
envelopes = [envelope for envelope in envelopes]
560-
assert len(envelopes) == 1
563+
envelopes = [envelope for envelope in envelopes]
564+
assert len(envelopes) == 1
561565

562-
profiles = [item for item in envelopes[0].items if item.type == "profile"]
563-
assert len(profiles) == 1, envelopes[0].items
566+
profiles = [item for item in envelopes[0].items if item.type == "profile"]
567+
assert len(profiles) == 1, envelopes[0].items
564568

565-
for item in profiles:
566-
transactions = item.payload.json["transactions"]
567-
assert len(transactions) == 1
568-
assert str(data["active"]) == transactions[0]["active_thread_id"]
569+
for item in profiles:
570+
transactions = item.payload.json["transactions"]
571+
assert len(transactions) == 1
572+
assert str(data["active"]) == transactions[0]["active_thread_id"]
569573

570-
transactions = [item for item in envelopes[0].items if item.type == "transaction"]
571-
assert len(transactions) == 1
574+
transactions = [
575+
item for item in envelopes[0].items if item.type == "transaction"
576+
]
577+
assert len(transactions) == 1
572578

573-
for item in transactions:
574-
transaction = item.payload.json
575-
trace_context = transaction["contexts"]["trace"]
576-
assert str(data["active"]) == trace_context["data"]["thread.id"]
579+
for item in transactions:
580+
transaction = item.payload.json
581+
trace_context = transaction["contexts"]["trace"]
582+
assert str(data["active"]) == trace_context["data"]["thread.id"]
577583

578584

579585
@pytest.mark.asyncio

0 commit comments

Comments
 (0)