Skip to content

Commit

Permalink
added timestamp to node failures in MNTR (#4911)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb authored Apr 6, 2021
1 parent d3197dd commit ec3fc61
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
17 changes: 15 additions & 2 deletions src/core/Akka.MultiNodeTestRunner.Shared.Tests/ParsingSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Reflection;
using Akka.Actor;
using Akka.Configuration;
Expand Down Expand Up @@ -115,11 +116,23 @@ public void MessageSink_should_be_able_to_infer_message_type()
//format the string as it would appear when reported by multinode test runner
var nodeMessageFragment = "[NODE1:super_role_1] Only part of a message!";
var runnerMessageStr = foundMessage.ToString();
try
{
throw new ApplicationException("test");
}
catch (Exception ex)
{
specFail.FailureExceptionTypes.Add(ex.GetType().ToString());
specFail.FailureMessages.Add(ex.Message);
specFail.FailureStackTraces.Add(ex.StackTrace);
}

var specFailMsg = specFail.ToString();

MessageSink.DetermineMessageType(runnerMessageStr).ShouldBe(MessageSink.MultiNodeTestRunnerMessageType.RunnerLogMessage);
MessageSink.DetermineMessageType(specPass.ToString()).ShouldBe(MessageSink.MultiNodeTestRunnerMessageType.NodePassMessage);
MessageSink.DetermineMessageType(specFail.ToString()).ShouldBe(MessageSink.MultiNodeTestRunnerMessageType.NodeFailMessage);
MessageSink.DetermineMessageType("[Node2][FAIL-EXCEPTION] Type: Xunit.Sdk.TrueException").ShouldBe(MessageSink.MultiNodeTestRunnerMessageType.NodeFailureException);
MessageSink.DetermineMessageType(specFailMsg).ShouldBe(MessageSink.MultiNodeTestRunnerMessageType.NodeFailMessage);
MessageSink.DetermineMessageType($"[Node2][{DateTime.UtcNow}][FAIL-EXCEPTION] Type: Xunit.Sdk.TrueException").ShouldBe(MessageSink.MultiNodeTestRunnerMessageType.NodeFailureException);
MessageSink.DetermineMessageType(nodeMessageFragment).ShouldBe(MessageSink.MultiNodeTestRunnerMessageType.NodeLogFragment);
MessageSink.DetermineMessageType("foo!").ShouldBe(MessageSink.MultiNodeTestRunnerMessageType.Unknown);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka.MultiNodeTestRunner.Shared/Sinks/MessageSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public enum MultiNodeTestRunnerMessageType
};

private const string NodePassStatusRegexString =
@"\[(\w){4}(?<node>[0-9]{1,2})(?<role>:\w+)?\]\[(?<status>(PASS|FAIL))\]{1}\s(?<test>.*)";
@"\[(\w){4}(?<node>[0-9]{1,2})(?<role>:\w+)?\]\[(?<time>\d{1,4}[- /.]\d{1,4}[- /.]\d{1,4}\s\d{1,2}:\d{1,2}:\d{1,2}(\s(AM|PM)){0,1})\]\[(?<status>(PASS|FAIL))\]{1}\s(?<test>.*)";
protected static readonly Regex NodePassStatusRegex = new Regex(NodePassStatusRegexString);

private const string NodePassed = "PASS";

private const string NodeFailed = "FAIL";

private const string NodeFailureReasonRegexString =
@"\[(\w){4}(?<node>[0-9]{1,2})(?<role>:\w+)?\]\[(?<status>(FAIL-EXCEPTION))\]{1}\s(?<message>.*)";
@"\[(\w){4}(?<node>[0-9]{1,2})(?<role>:\w+)?\]\[(?<time>\d{1,4}[- /.]\d{1,4}[- /.]\d{1,4}\s\d{1,2}:\d{1,2}:\d{1,2}(\s(AM|PM)){0,1})\]\[(?<status>(FAIL-EXCEPTION))\]{1}\s(?<message>.*)";
protected static readonly Regex NodeFailureReasonRegex = new Regex(NodeFailureReasonRegexString);

/*
Expand Down
16 changes: 11 additions & 5 deletions src/core/Akka.MultiNodeTestRunner.Shared/Sinks/Spec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ public SpecPass(int nodeIndex, string nodeRole, string testDisplayName)
TestDisplayName = testDisplayName;
NodeIndex = nodeIndex;
NodeRole = nodeRole;
Timestamp = DateTime.UtcNow;
}

public int NodeIndex { get; private set; }
public string NodeRole { get; private set; }

public string TestDisplayName { get; private set; }

public DateTime Timestamp { get; }

public override string ToString()
{
return string.Format("[Node{0}:{1}][PASS] {2}", NodeIndex, NodeRole, TestDisplayName);
return $"[Node{NodeIndex}:{NodeRole}][{Timestamp}][PASS] {TestDisplayName}";
}
}

Expand All @@ -56,29 +59,32 @@ public SpecFail(int nodeIndex, string nodeRole, string testDisplayName) : base(n
FailureMessages = new List<string>();
FailureStackTraces = new List<string>();
FailureExceptionTypes = new List<string>();
Timestamp = DateTime.UtcNow;
}

public IList<string> FailureMessages { get; private set; }
public IList<string> FailureStackTraces { get; private set; }
public IList<string> FailureExceptionTypes { get; private set; }

public DateTime Timestamp { get; }

public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine(string.Format("[Node{0}:{1}][FAIL] {2}", NodeIndex, NodeRole, TestDisplayName));
sb.AppendLine($"[Node{NodeIndex}:{NodeRole}][{Timestamp}][FAIL] {TestDisplayName}");
foreach (var exception in FailureExceptionTypes)
{
sb.AppendFormat("[Node{0}:{1}][FAIL-EXCEPTION] Type: {2}", NodeIndex, NodeRole, exception);
sb.Append($"[Node{NodeIndex}:{NodeRole}][{Timestamp}][FAIL-EXCEPTION] Type: {exception}");
sb.AppendLine();
}
foreach (var exception in FailureMessages)
{
sb.AppendFormat("--> [Node{0}:{1}][FAIL-EXCEPTION] Message: {2}", NodeIndex, NodeRole, exception);
sb.Append($"--> [Node{NodeIndex}:{NodeRole}][{Timestamp}][FAIL-EXCEPTION] Message: {exception}");
sb.AppendLine();
}
foreach (var exception in FailureStackTraces)
{
sb.AppendFormat("--> [Node{0}:{1}][FAIL-EXCEPTION] StackTrace: {2}", NodeIndex, NodeRole, exception);
sb.Append($"--> [Node{NodeIndex}:{NodeRole}][{Timestamp}][FAIL-EXCEPTION] StackTrace: {exception}");
sb.AppendLine();
}
return sb.ToString();
Expand Down

0 comments on commit ec3fc61

Please sign in to comment.