Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Update SentryMauiScreenshotTests.cs
  • Loading branch information
jamescrosswell committed Nov 29, 2024
commit 3c4ea18835b61f837c74201c630c67cf80b8bbac
35 changes: 35 additions & 0 deletions test/Sentry.Maui.Tests/SentryMauiScreenshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,40 @@ public async Task CaptureException_BeforeCaptureScreenshot_DefaultAsync()
envelopeItem!.TryGetFileName().Should().Be("screenshot.jpg");
}
}

[Fact]
public async Task CaptureException_AttachScreenshot_Threadsafe()
{
// Arrange
var builder = _fixture.Builder.UseSentry(options =>
{
options.AttachScreenshot = true;
});
await using var app = builder.Build();
var client = app.Services.GetRequiredService<ISentryClient>();

// Act
var tasks = new List<Task<SentryId>>();
for (var i = 0; i < 20; i++)
{
var j = i;
tasks.Add(Task.Run(() =>
{
var exSample = new NotImplementedException("Sample Exception " + j);
var sentryId = client.CaptureException(exSample);
client.FlushAsync();
return sentryId;
}));
}

// Assert
while (tasks.Any())
{
var finishedTask = await Task.WhenAny(tasks);

finishedTask.Exception.Should().BeNull();
tasks.Remove(finishedTask);
}
}
#endif
}
Loading