Skip to content

Commit 8f50979

Browse files
fix: Tweak FlushOnDispose_SendsEnvelope (#4175)
Attempts to fix #2156: - #2156 This code makes use of the id returned by `CaptureEvent`. My theory is that might prevent code optimisations resulting in that code running in parallel to the assertion statement. I also changed the code to call `Dispose` explicitly. I don't think that makes any difference tbh but it does make the method that is being tested more explicit. #skip-changelog
1 parent df30f77 commit 8f50979

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

test/Sentry.Tests/HubTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,18 +1753,19 @@ public async Task FlushOnDispose_SendsEnvelope(bool cachingEnabled)
17531753
options.CacheDirectoryPath = cacheDirectory.Path;
17541754
}
17551755

1756+
var hub = new Hub(options);
1757+
var id = hub.CaptureEvent(new SentryEvent());
1758+
17561759
// Act
17571760
// Disposing the hub should flush the client and send the envelope.
17581761
// If caching is enabled, it should flush the cache as well.
17591762
// Either way, the envelope should be sent.
1760-
using (var hub = new Hub(options))
1761-
{
1762-
hub.CaptureEvent(new SentryEvent());
1763-
}
1763+
hub.Dispose();
17641764

17651765
// Assert
17661766
await transport.Received(1)
1767-
.SendEnvelopeAsync(Arg.Any<Envelope>(), Arg.Any<CancellationToken>());
1767+
.SendEnvelopeAsync(Arg.Is<Envelope>(env => (string)env.Header["event_id"] == id.ToString()),
1768+
Arg.Any<CancellationToken>());
17681769
}
17691770

17701771
private static Scope GetCurrentScope(Hub hub) => hub.ScopeManager.GetCurrent().Key;

0 commit comments

Comments
 (0)