From 772a67f340368deb40437fae9df4e57241b1d5fb Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Tue, 6 Apr 2021 15:07:35 -0500 Subject: [PATCH] cleaned up the SpecPass / SpecFail messages --- .../Sinks/Spec.cs | 3 - src/core/Akka.NodeTestRunner/Sink.cs | 72 +++++++++---------- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/core/Akka.MultiNodeTestRunner.Shared/Sinks/Spec.cs b/src/core/Akka.MultiNodeTestRunner.Shared/Sinks/Spec.cs index 68b60e094cc..f6da1d0e405 100644 --- a/src/core/Akka.MultiNodeTestRunner.Shared/Sinks/Spec.cs +++ b/src/core/Akka.MultiNodeTestRunner.Shared/Sinks/Spec.cs @@ -59,15 +59,12 @@ public SpecFail(int nodeIndex, string nodeRole, string testDisplayName) : base(n FailureMessages = new List(); FailureStackTraces = new List(); FailureExceptionTypes = new List(); - Timestamp = DateTime.UtcNow; } public IList FailureMessages { get; private set; } public IList FailureStackTraces { get; private set; } public IList FailureExceptionTypes { get; private set; } - public DateTime Timestamp { get; } - public override string ToString() { var sb = new StringBuilder(); diff --git a/src/core/Akka.NodeTestRunner/Sink.cs b/src/core/Akka.NodeTestRunner/Sink.cs index 7da52a4b9a3..ce48223dd4f 100644 --- a/src/core/Akka.NodeTestRunner/Sink.cs +++ b/src/core/Akka.NodeTestRunner/Sink.cs @@ -40,47 +40,47 @@ public Sink(int nodeIndex, string nodeRole, IActorRef logger) public bool OnMessage(IMessageSinkMessage message) { - var resultMessage = message as ITestResultMessage; - if (resultMessage != null) + if (message is ITestResultMessage resultMessage) { _logger.Tell(resultMessage.Output); Console.WriteLine(resultMessage.Output); } - var testPassed = message as ITestPassed; - if (testPassed != null) - { - //the MultiNodeTestRunner uses 1-based indexing, which is why we have to add 1 to the index. - var specPass = new SpecPass(_nodeIndex + 1, _nodeRole, testPassed.TestCase.DisplayName); - _logger.Tell(specPass.ToString()); - Console.WriteLine(specPass.ToString()); //so the message also shows up in the individual per-node build log - Passed = true; - return true; - } - var testFailed = message as ITestFailed; - if (testFailed != null) - { - //the MultiNodeTestRunner uses 1-based indexing, which is why we have to add 1 to the index. - var specFail = new SpecFail(_nodeIndex + 1, _nodeRole, testFailed.TestCase.DisplayName); - foreach (var failedMessage in testFailed.Messages) specFail.FailureMessages.Add(failedMessage); - foreach (var stackTrace in testFailed.StackTraces) specFail.FailureStackTraces.Add(stackTrace); - foreach(var exceptionType in testFailed.ExceptionTypes) specFail.FailureExceptionTypes.Add(exceptionType); - _logger.Tell(specFail.ToString()); - Console.WriteLine(specFail.ToString()); - return true; - } - var errorMessage = message as ErrorMessage; - if (errorMessage != null) - { - var specFail = new SpecFail(_nodeIndex + 1, _nodeRole, "ERRORED"); - foreach (var failedMessage in errorMessage.Messages) specFail.FailureMessages.Add(failedMessage); - foreach (var stackTrace in errorMessage.StackTraces) specFail.FailureStackTraces.Add(stackTrace); - foreach (var exceptionType in errorMessage.ExceptionTypes) specFail.FailureExceptionTypes.Add(exceptionType); - _logger.Tell(specFail.ToString()); - Console.WriteLine(specFail.ToString()); - } - if (message is ITestAssemblyFinished) + + switch (message) { - Finished.Set(); + case ITestPassed testPassed: + { + //the MultiNodeTestRunner uses 1-based indexing, which is why we have to add 1 to the index. + var specPass = new SpecPass(_nodeIndex + 1, _nodeRole, testPassed.TestCase.DisplayName); + _logger.Tell(specPass.ToString()); + Console.WriteLine(specPass.ToString()); //so the message also shows up in the individual per-node build log + Passed = true; + return true; + } + case ITestFailed testFailed: + { + //the MultiNodeTestRunner uses 1-based indexing, which is why we have to add 1 to the index. + var specFail = new SpecFail(_nodeIndex + 1, _nodeRole, testFailed.TestCase.DisplayName); + foreach (var failedMessage in testFailed.Messages) specFail.FailureMessages.Add(failedMessage); + foreach (var stackTrace in testFailed.StackTraces) specFail.FailureStackTraces.Add(stackTrace); + foreach(var exceptionType in testFailed.ExceptionTypes) specFail.FailureExceptionTypes.Add(exceptionType); + _logger.Tell(specFail.ToString()); + Console.WriteLine(specFail.ToString()); + return true; + } + case ErrorMessage errorMessage: + { + var specFail = new SpecFail(_nodeIndex + 1, _nodeRole, "ERRORED"); + foreach (var failedMessage in errorMessage.Messages) specFail.FailureMessages.Add(failedMessage); + foreach (var stackTrace in errorMessage.StackTraces) specFail.FailureStackTraces.Add(stackTrace); + foreach (var exceptionType in errorMessage.ExceptionTypes) specFail.FailureExceptionTypes.Add(exceptionType); + _logger.Tell(specFail.ToString()); + Console.WriteLine(specFail.ToString()); + break; + } + case ITestAssemblyFinished _: + Finished.Set(); + break; } return true;