Skip to content

Commit

Permalink
TargetWithContextNdlcSerializeTest - Investigate unstable test
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Jan 29, 2021
1 parent d6e92fa commit ca78fe8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
@@ -1,7 +1,7 @@
version: 4.7.0-{build}
image:
- Visual Studio 2017
- Ubuntu
- Previous Ubuntu
configuration: Release
build: no
test: no
Expand Down Expand Up @@ -47,7 +47,7 @@ for:
-
matrix:
only:
- image: Ubuntu
- image: Previous Ubuntu
environment:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
FrameworkPathOverride: /usr/lib/mono/4.6.1-api/
Expand Down
9 changes: 5 additions & 4 deletions tests/NLog.UnitTests/Targets/TargetWithContextTest.cs
Expand Up @@ -110,7 +110,7 @@ public void TargetWithContextAsyncTest()
ScopeContext.PushProperty("TestKey", "Hello Async World");
ScopeContext.PushProperty("AsyncKey", "Hello Async World");
logger.Debug("log message");
WaitForLastMessage(target);
Assert.True(WaitForLastMessage(target));

Assert.NotEqual(0, target.LastMessage.Length);
Assert.NotNull(target.LastCombinedProperties);
Expand All @@ -123,16 +123,17 @@ public void TargetWithContextAsyncTest()
Assert.Contains(new KeyValuePair<string, object>("threadid", System.Environment.CurrentManagedThreadId.ToString()), target.LastCombinedProperties);
}

private static void WaitForLastMessage(CustomTargetWithContext target)
private static bool WaitForLastMessage(CustomTargetWithContext target)
{
System.Threading.Thread.Sleep(1);
for (int i = 0; i < 1000; ++i)
{
if (target.LastMessage != null)
break;
return true;

System.Threading.Thread.Sleep(1);
}
return false;
}

[Fact]
Expand Down Expand Up @@ -193,7 +194,7 @@ private static void WriteAndAssertSingleKey(CustomTargetWithContext target)

logger.Debug("log message");

WaitForLastMessage(target);
Assert.True(WaitForLastMessage(target));

Assert.Equal("{ a = b }", target.LastCombinedProperties["TestKey"]);
}
Expand Down

0 comments on commit ca78fe8

Please sign in to comment.