Skip to content

[RACY] LoggerSpec TestOutputLogger Make sure that event receive order does not matter #5015

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

Merged
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
33 changes: 25 additions & 8 deletions src/core/Akka.Tests/Loggers/LoggerSpec.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Akka.Actor;
using Akka.Configuration;
using Akka.Event;
using Akka.TestKit;
using Akka.Tests.Shared.Internals;
using Xunit;
using Xunit.Abstractions;
using FluentAssertions;
Expand All @@ -26,25 +28,40 @@ public LoggerSpec(ITestOutputHelper output) : base(Config, output)
[Fact]
public void TestOutputLogger_WithBadFormattingMustNotThrow()
{
var events = new List<LogEvent>();

// Need to wait until TestOutputLogger initializes
Thread.Sleep(200);
Sys.EventStream.Subscribe(TestActor, typeof(LogEvent));

Sys.Log.Error(new FakeException("BOOM"), Case.t, Case.p);
ExpectMsg<Error>().Cause.Should().BeOfType<FakeException>();
ExpectMsg<Error>().Cause.Should().BeOfType<AggregateException>();
events.Add(ExpectMsg<Error>());
events.Add(ExpectMsg<Error>());

events.All(e => e is Error).Should().BeTrue();
events.Select(e => e.Cause).Any(c => c is FakeException).Should().BeTrue();
events.Select(e => e.Cause).Any(c => c is AggregateException).Should().BeTrue();

events.Clear();
Sys.Log.Warning(Case.t, Case.p);
ExpectMsg<Warning>();
ExpectMsg<Error>().Cause.Should().BeOfType<FormatException>();
events.Add(ExpectMsg<LogEvent>());
events.Add(ExpectMsg<LogEvent>());
events.Any(e => e is Warning).Should().BeTrue();
events.First(e => e is Error).Cause.Should().BeOfType<FormatException>();

events.Clear();
Sys.Log.Info(Case.t, Case.p);
ExpectMsg<Info>();
ExpectMsg<Error>().Cause.Should().BeOfType<FormatException>();
events.Add(ExpectMsg<LogEvent>());
events.Add(ExpectMsg<LogEvent>());
events.Any(e => e is Info).Should().BeTrue();
events.First(e => e is Error).Cause.Should().BeOfType<FormatException>();

events.Clear();
Sys.Log.Debug(Case.t, Case.p);
ExpectMsg<Debug>();
ExpectMsg<Error>().Cause.Should().BeOfType<FormatException>();
events.Add(ExpectMsg<LogEvent>());
events.Add(ExpectMsg<LogEvent>());
events.Any(e => e is Debug).Should().BeTrue();
events.First(e => e is Error).Cause.Should().BeOfType<FormatException>();
}

[Fact]
Expand Down