Skip to content

Commit e2ce932

Browse files
authored
Simplified tests (#2431)
1 parent 821649a commit e2ce932

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

test/Sentry.Unity.Android.Tests/SentryJavaTests.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,18 @@ public void RunJniSafe_ActionThrowsOnMainThread_CatchesExceptionAndLogsError()
7878
public void RunJniSafe_ActionThrowsOnNonMainThread_CatchesExceptionAndLogsError()
7979
{
8080
// Arrange
81-
var exception = new InvalidOperationException("Test exception");
82-
var resetEvent = new ManualResetEvent(false);
83-
var action = new Action(() =>
84-
{
85-
try
86-
{
87-
throw exception;
88-
}
89-
finally
90-
{
91-
resetEvent.Set();
92-
}
93-
});
81+
var action = new Action(() => throw new InvalidOperationException("Test exception"));
9482

9583
// Act
9684
_sut.RunJniSafe(action, "TestAction", isMainThread: false);
9785

98-
// Assert
99-
Assert.That(resetEvent.WaitOne(TimeSpan.FromSeconds(1)), Is.True);
100-
Assert.IsTrue(_logger.Logs.Any(log =>
101-
log.logLevel == SentryLevel.Error &&
102-
log.message.Contains("Calling 'TestAction' failed.")));
86+
// Assert - wait for the error to be logged on the worker thread
87+
var logFound = SpinWait.SpinUntil(() =>
88+
_logger.Logs.Any(log =>
89+
log.logLevel == SentryLevel.Error &&
90+
log.message.Contains("Calling 'TestAction' failed.")),
91+
TimeSpan.FromSeconds(1));
92+
Assert.IsTrue(logFound);
10393
}
10494

10595
[Test]

0 commit comments

Comments
 (0)