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
Next Next commit
Fixed tests. Keep it in memory
  • Loading branch information
bitsandfoxes committed Oct 16, 2025
commit 7266de7c28ad1b136e6a0cf72aef5b4d61d3ba7e
46 changes: 12 additions & 34 deletions test/Sentry.Tests/GlobalSessionManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System.IO.Abstractions.TestingHelpers;

namespace Sentry.Tests;

public class GlobalSessionManagerTests : IDisposable
public class GlobalSessionManagerTests
{
private class Fixture : IDisposable
private class Fixture
{
public TempDirectory CacheDirectory;

public InMemoryDiagnosticLogger Logger { get; }

public SentryOptions Options { get; }
Expand All @@ -21,16 +17,14 @@ public Fixture(Action<SentryOptions> configureOptions = null)
Clock.GetUtcNow().Returns(DateTimeOffset.Now);
Logger = new InMemoryDiagnosticLogger();

CacheDirectory = new TempDirectory();
Options = new SentryOptions
{
Dsn = ValidDsn,
Release = "test",
Debug = true,
DiagnosticLogger = Logger,
CacheDirectoryPath = CacheDirectory.Path,
// This keeps all writing-to-file operations in memory instead of actually writing to disk
FileSystem = new FakeFileSystem()
CacheDirectoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()),
FileSystem = new FakeFileSystem() // Keep all fileIO operations in memory
};

configureOptions?.Invoke(Options);
Expand All @@ -41,8 +35,6 @@ public GlobalSessionManager GetSut() =>
Options,
Clock,
PersistedSessionProvider);

public void Dispose() => CacheDirectory.Dispose();
}

private readonly Fixture _fixture = new();
Expand Down Expand Up @@ -104,19 +96,14 @@ public void StartSession_CacheDirectoryProvidedButFileWriteDisabled_Installation
[SkippableFact]
public void StartSession_CacheDirectoryNotProvided_InstallationIdFileCreated()
{
Skip.If(TestEnvironment.IsGitHubActions, "Flaky in CI");

// Arrange
_fixture.Options.CacheDirectoryPath = null;
// Setting the test-cache directory to be properly disposed
_fixture.CacheDirectory = new TempDirectory(Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Sentry",
_fixture.Options.Dsn!.GetHashString()));

var sut = _fixture.GetSut();

var filePath = Path.Combine(_fixture.CacheDirectory.Path, ".installation");
var filePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Sentry", _fixture.Options.Dsn!.GetHashString(),
".installation");

// Act
sut.StartSession();
Expand All @@ -131,16 +118,15 @@ public void StartSession_CacheDirectoryNotProvidedAndFileWriteDisabled_Installat
// Arrange
_fixture.Options.DisableFileWrite = true;
_fixture.Options.CacheDirectoryPath = null;
// Setting the test-cache directory to be properly disposed
_fixture.CacheDirectory = new TempDirectory(Path.Combine(

var filePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Sentry",
_fixture.Options.Dsn!.GetHashString()));
_fixture.Options.Dsn!.GetHashString(),
".installation");

var sut = _fixture.GetSut();

var filePath = Path.Combine(_fixture.CacheDirectory.Path, ".installation");

// Act
sut.StartSession();

Expand Down Expand Up @@ -468,9 +454,6 @@ public void TryRecoverPersistedSession_SessionStarted_CrashDelegateReturnsTrue_E
_fixture.Options.CrashedLastRun = () => true;
var sut = _fixture.GetSut();

using var fixture = new Fixture(o =>
o.CrashedLastRun = () => true);

sut.StartSession();

// Act
Expand Down Expand Up @@ -558,9 +541,4 @@ private static SessionUpdate AnySessionUpdate()
DateTimeOffset.Now,
1,
null);

public void Dispose()
{
_fixture.Dispose();
}
}