Skip to content

Commit e7d6b84

Browse files
authored
fix: GlobalSessionManager tests (#4649)
1 parent 7645341 commit e7d6b84

File tree

1 file changed

+13
-38
lines changed

1 file changed

+13
-38
lines changed

test/Sentry.Tests/GlobalSessionManagerTests.cs

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
using System.IO.Abstractions.TestingHelpers;
2-
31
namespace Sentry.Tests;
42

5-
public class GlobalSessionManagerTests : IDisposable
3+
public class GlobalSessionManagerTests
64
{
7-
private class Fixture : IDisposable
5+
private class Fixture
86
{
9-
public TempDirectory CacheDirectory;
10-
117
public InMemoryDiagnosticLogger Logger { get; }
128

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

24-
CacheDirectory = new TempDirectory();
2520
Options = new SentryOptions
2621
{
2722
Dsn = ValidDsn,
2823
Release = "test",
2924
Debug = true,
3025
DiagnosticLogger = Logger,
31-
CacheDirectoryPath = CacheDirectory.Path,
32-
// This keeps all writing-to-file operations in memory instead of actually writing to disk
33-
FileSystem = new FakeFileSystem()
26+
CacheDirectoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()),
27+
FileSystem = new FakeFileSystem() // Keep all fileIO operations in memory
3428
};
3529

3630
configureOptions?.Invoke(Options);
@@ -41,8 +35,6 @@ public GlobalSessionManager GetSut() =>
4135
Options,
4236
Clock,
4337
PersistedSessionProvider);
44-
45-
public void Dispose() => CacheDirectory.Dispose();
4638
}
4739

4840
private readonly Fixture _fixture = new();
@@ -104,22 +96,16 @@ public void StartSession_CacheDirectoryProvidedButFileWriteDisabled_Installation
10496
[SkippableFact]
10597
public void StartSession_CacheDirectoryNotProvided_InstallationIdFileCreated()
10698
{
107-
Skip.If(TestEnvironment.IsGitHubActions, "Flaky in CI");
108-
10999
// Arrange
110100
_fixture.Options.CacheDirectoryPath = null;
111-
// Setting the test-cache directory to be properly disposed
112-
_fixture.CacheDirectory = new TempDirectory(Path.Combine(
101+
var filePath = Path.Combine(
113102
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
114103
"Sentry",
115-
_fixture.Options.Dsn!.GetHashString()));
116-
117-
var sut = _fixture.GetSut();
118-
119-
var filePath = Path.Combine(_fixture.CacheDirectory.Path, ".installation");
104+
_fixture.Options.Dsn!.GetHashString(),
105+
".installation");
120106

121107
// Act
122-
sut.StartSession();
108+
_fixture.GetSut().StartSession();
123109

124110
// Assert
125111
Assert.True(_fixture.Options.FileSystem.FileExists(filePath));
@@ -131,18 +117,15 @@ public void StartSession_CacheDirectoryNotProvidedAndFileWriteDisabled_Installat
131117
// Arrange
132118
_fixture.Options.DisableFileWrite = true;
133119
_fixture.Options.CacheDirectoryPath = null;
134-
// Setting the test-cache directory to be properly disposed
135-
_fixture.CacheDirectory = new TempDirectory(Path.Combine(
120+
121+
var filePath = Path.Combine(
136122
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
137123
"Sentry",
138-
_fixture.Options.Dsn!.GetHashString()));
139-
140-
var sut = _fixture.GetSut();
141-
142-
var filePath = Path.Combine(_fixture.CacheDirectory.Path, ".installation");
124+
_fixture.Options.Dsn!.GetHashString(),
125+
".installation");
143126

144127
// Act
145-
sut.StartSession();
128+
_fixture.GetSut().StartSession();
146129

147130
// Assert
148131
Assert.False(_fixture.Options.FileSystem.FileExists(filePath));
@@ -468,9 +451,6 @@ public void TryRecoverPersistedSession_SessionStarted_CrashDelegateReturnsTrue_E
468451
_fixture.Options.CrashedLastRun = () => true;
469452
var sut = _fixture.GetSut();
470453

471-
using var fixture = new Fixture(o =>
472-
o.CrashedLastRun = () => true);
473-
474454
sut.StartSession();
475455

476456
// Act
@@ -558,9 +538,4 @@ private static SessionUpdate AnySessionUpdate()
558538
DateTimeOffset.Now,
559539
1,
560540
null);
561-
562-
public void Dispose()
563-
{
564-
_fixture.Dispose();
565-
}
566541
}

0 commit comments

Comments
 (0)