Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flakiness on test Log_WhenAsyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsIt #4394

Merged
merged 3 commits into from
Dec 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public async Task Log_WhenSyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsIt

[TestMethod]
[DynamicData(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers), DynamicDataSourceType.Method)]
public async Task Log_WhenAsyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsIt(LogLevel defaultLogLevel, LogLevel currentLogLevel)
public void Log_WhenAsyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsIt(LogLevel defaultLogLevel, LogLevel currentLogLevel)
{
_mockFileSystem.Setup(x => x.Exists(It.IsAny<string>())).Returns(false);
_mockFileStreamFactory
Expand All @@ -214,13 +214,11 @@ public async Task Log_WhenAsyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsI
_mockFileStreamFactory.Object);
fileLogger.Log(currentLogLevel, Message, null, Formatter, Category);

// Ensures that the async flush is completed before the file is read
fileLogger.Dispose();
Evangelink marked this conversation as resolved.
Show resolved Hide resolved

if (LogTestHelpers.IsLogEnabled(defaultLogLevel, currentLogLevel))
{
if (_memoryStream.Length == 0)
{
await Task.Delay(1000);
}

Assert.AreEqual($"0001-01-01T00:00:00.0000000+00:00 Test {currentLogLevel.ToString().ToUpperInvariant()} Message{Environment.NewLine}", Encoding.Default.GetString(_memoryStream.ToArray()));
}
else
Expand Down
Loading