diff --git a/test/Sentry.Testing/FakeReliableNetworkStatusListener.cs b/test/Sentry.Testing/FakeReliableNetworkStatusListener.cs
new file mode 100644
index 0000000000..b239439597
--- /dev/null
+++ b/test/Sentry.Testing/FakeReliableNetworkStatusListener.cs
@@ -0,0 +1,20 @@
+namespace Sentry.Testing;
+
+///
+/// To be used when we don't want the real network status to affect the reliability of our tests
+///
+public class FakeReliableNetworkStatusListener : INetworkStatusListener
+{
+ public static readonly FakeReliableNetworkStatusListener Instance = new();
+
+ private FakeReliableNetworkStatusListener()
+ {
+ }
+
+ public bool Online => true;
+
+ public Task WaitForNetworkOnlineAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
+ }
+}
diff --git a/test/Sentry.Tests/Internals/Http/CachingTransportTests.cs b/test/Sentry.Tests/Internals/Http/CachingTransportTests.cs
index e903b7f3ca..4eb29f4290 100644
--- a/test/Sentry.Tests/Internals/Http/CachingTransportTests.cs
+++ b/test/Sentry.Tests/Internals/Http/CachingTransportTests.cs
@@ -3,31 +3,38 @@
namespace Sentry.Tests.Internals.Http;
-public class CachingTransportTests
+public class CachingTransportTests : IDisposable
{
private readonly TestOutputDiagnosticLogger _logger;
+ private readonly TempDirectory _cacheDirectory;
+ private readonly SentryOptions _options;
public CachingTransportTests(ITestOutputHelper testOutputHelper)
{
_logger = Substitute.ForPartsOf(testOutputHelper);
- }
-
- [Fact]
- public async Task WithAttachment()
- {
- // Arrange
- using var cacheDirectory = new TempDirectory();
- var options = new SentryOptions
+ _cacheDirectory = new TempDirectory();
+ _options = new SentryOptions
{
Dsn = ValidDsn,
DiagnosticLogger = _logger,
Debug = true,
- CacheDirectoryPath = cacheDirectory.Path
+ CacheDirectoryPath = _cacheDirectory.Path,
+ NetworkStatusListener = FakeReliableNetworkStatusListener.Instance
};
+ }
+ public void Dispose()
+ {
+ _cacheDirectory.Dispose();
+ }
+
+ [Fact]
+ public async Task WithAttachment()
+ {
+ // Arrange
string httpContent = null;
Exception exception = null;
- var innerTransport = new HttpTransport(options, new HttpClient(new CallbackHttpClientHandler(async message =>
+ var innerTransport = new HttpTransport(_options, new HttpClient(new CallbackHttpClientHandler(async message =>
{
try
{
@@ -39,7 +46,7 @@ public async Task WithAttachment()
}
})));
- await using var transport = CachingTransport.Create(innerTransport, options, startWorker: false);
+ await using var transport = CachingTransport.Create(innerTransport, _options, startWorker: false);
const string attachmentContent = "test-attachment";
var tempFile = Path.GetTempFileName();
@@ -76,17 +83,8 @@ public async Task WithAttachment()
public async Task WorksInBackground()
{
// Arrange
- using var cacheDirectory = new TempDirectory();
- var options = new SentryOptions
- {
- Dsn = ValidDsn,
- DiagnosticLogger = _logger,
- Debug = true,
- CacheDirectoryPath = cacheDirectory.Path
- };
-
using var innerTransport = new FakeTransport();
- await using var transport = CachingTransport.Create(innerTransport, options);
+ await using var transport = CachingTransport.Create(innerTransport, _options);
// Attach to the EnvelopeSent event. We'll wait for that below.
// ReSharper disable once AccessToDisposedClosure
@@ -108,16 +106,6 @@ public async Task WorksInBackground()
public async Task ShouldNotLogOperationCanceledExceptionWhenIsCancellationRequested()
{
// Arrange
- using var cacheDirectory = new TempDirectory();
-
- var options = new SentryOptions
- {
- Dsn = ValidDsn,
- DiagnosticLogger = _logger,
- CacheDirectoryPath = cacheDirectory.Path,
- Debug = true
- };
-
var capturingCompletionSource = new TaskCompletionSource