Skip to content
Merged
Changes from all commits
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
51 changes: 13 additions & 38 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,22 +96,16 @@ 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(
var filePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Sentry",
_fixture.Options.Dsn!.GetHashString()));

var sut = _fixture.GetSut();

var filePath = Path.Combine(_fixture.CacheDirectory.Path, ".installation");
_fixture.Options.Dsn!.GetHashString(),
".installation");

// Act
sut.StartSession();
_fixture.GetSut().StartSession();

// Assert
Assert.True(_fixture.Options.FileSystem.FileExists(filePath));
Expand All @@ -131,18 +117,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()));

var sut = _fixture.GetSut();

var filePath = Path.Combine(_fixture.CacheDirectory.Path, ".installation");
_fixture.Options.Dsn!.GetHashString(),
".installation");

// Act
sut.StartSession();
_fixture.GetSut().StartSession();

// Assert
Assert.False(_fixture.Options.FileSystem.FileExists(filePath));
Expand Down Expand Up @@ -468,9 +451,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 +538,4 @@ private static SessionUpdate AnySessionUpdate()
DateTimeOffset.Now,
1,
null);

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