Skip to content

Commit 07c6608

Browse files
bruno-garciaclaude
andcommitted
Address PR review comments
- Fix JsonDocument leak: clone RootElement and dispose document - Make _playwright/_browser nullable, null-check in DisposeAsync - Close page after test to avoid resource leak - Use using on TcpListener Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6a3029d commit 07c6608

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests/BlazorWasmTestApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public async Task StartAsync()
7373

7474
private static int GetFreePort()
7575
{
76-
var listener = new TcpListener(IPAddress.Loopback, 0);
76+
using var listener = new TcpListener(IPAddress.Loopback, 0);
7777
listener.Start();
7878
var port = ((IPEndPoint)listener.LocalEndpoint).Port;
7979
listener.Stop();

test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests/NavigationBreadcrumbTests.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests;
66
public class NavigationBreadcrumbTests : IAsyncLifetime
77
{
88
private readonly BlazorWasmTestApp _app = new();
9-
private IPlaywright _playwright = null!;
10-
private IBrowser _browser = null!;
9+
private IPlaywright? _playwright;
10+
private IBrowser? _browser;
1111

1212
public async Task InitializeAsync()
1313
{
@@ -29,15 +29,18 @@ public async Task InitializeAsync()
2929

3030
public async Task DisposeAsync()
3131
{
32-
await _browser.DisposeAsync();
33-
_playwright.Dispose();
32+
if (_browser != null)
33+
{
34+
await _browser.DisposeAsync();
35+
}
36+
_playwright?.Dispose();
3437
await _app.DisposeAsync();
3538
}
3639

3740
[Fact]
3841
public async Task Navigation_CreatesBreadcrumbs_WithCorrectFromAndTo()
3942
{
40-
var page = await _browser.NewPageAsync();
43+
var page = await _browser!.NewPageAsync();
4144

4245
// Collect all intercepted envelopes
4346
var envelopeReceived = new TaskCompletionSource<string>();
@@ -98,5 +101,7 @@ await route.FulfillAsync(new RouteFulfillOptions
98101
var second = navBreadcrumbs[1];
99102
second.GetProperty("data").GetProperty("from").GetString().Should().Be("/second");
100103
second.GetProperty("data").GetProperty("to").GetString().Should().Be("/trigger-capture");
104+
105+
await page.CloseAsync();
101106
}
102107
}

test/Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests/SentryEnvelopeParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ internal static class SentryEnvelopeParser
2323
if (itemHeader.TryGetProperty("type", out var typeEl) &&
2424
typeEl.GetString() == "event")
2525
{
26-
return JsonDocument.Parse(lines[i + 1]).RootElement;
26+
using var eventDoc = JsonDocument.Parse(lines[i + 1]);
27+
return eventDoc.RootElement.Clone();
2728
}
2829
}
2930

0 commit comments

Comments
 (0)