Skip to content

Commit ff2d528

Browse files
authored
Enable the built in TRX reporter for proper error reporting in AzDo (#134)
1 parent 0d1c66b commit ff2d528

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

src/Akka.MultiNode.TestAdapter/Configuration/MultiNodeTestRunnerOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ public string ListenAddress
6060
public bool AppendLogOutput { get; set; } = true;
6161

6262
public string? Platform { get; set; }
63+
64+
public bool UseBuiltInTrxReporter { get; set; }
6365
}
6466
}

src/Akka.MultiNode.TestAdapter/Configuration/OptionsReader.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ private static MultiNodeTestRunnerOptions Load(Stream configStream)
5555
case JsonBoolean booleanValue:
5656
if (string.Equals(propertyName, Configuration.AppendLogOutput, StringComparison.OrdinalIgnoreCase))
5757
result.AppendLogOutput = booleanValue.Value;
58+
if (string.Equals(propertyName, Configuration.UseBuiltInTrxReporter, StringComparison.OrdinalIgnoreCase))
59+
result.UseBuiltInTrxReporter = booleanValue.Value;
5860
break;
5961

6062
case JsonString stringValue:
@@ -87,6 +89,7 @@ static class Configuration
8789
public const string ListenAddress = "listenAddress";
8890
public const string ListenPort = "listenPort";
8991
public const string AppendLogOutput = "appendLogOutput";
92+
public const string UseBuiltInTrxReporter = "useBuiltInTrxReporter";
9093
}
9194
}
9295
}

src/Akka.MultiNode.TestAdapter/Internal/MultiNodeTestCaseRunner.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,15 @@ protected override async Task<RunSummary> RunTestAsync()
133133
");
134134
TestRunSystem = ActorSystem.Create("TestRunnerLogging", config);
135135

136+
var sinks = new List<MessageSink>
137+
{
138+
new DiagnosticMessageSink(_diagnosticSink)
139+
};
140+
if(Options.UseBuiltInTrxReporter)
141+
sinks.Add(new TrxMessageSink(DisplayName, Options));
142+
136143
SinkCoordinator = TestRunSystem.ActorOf(Props.Create(()
137-
=> new SinkCoordinator(new[] { new DiagnosticMessageSink(_diagnosticSink) })), "sinkCoordinator");
144+
=> new SinkCoordinator(sinks)), "sinkCoordinator");
138145

139146
var tcpLogger = TestRunSystem.ActorOf(Props.Create(() => new TcpLoggingServer(SinkCoordinator)), "TcpLogger");
140147
var listenEndpoint = new IPEndPoint(IPAddress.Parse(Options.ListenAddress), Options.ListenPort);

src/Akka.MultiNode.TestAdapter/Internal/TrxReporter/TrxMessageSink.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88
using System;
99
using Akka.Actor;
10+
using Akka.MultiNode.TestAdapter.Configuration;
1011
using Akka.MultiNode.TestAdapter.Internal.Sinks;
1112

1213
namespace Akka.MultiNode.TestAdapter.Internal.TrxReporter
1314
{
1415
internal class TrxMessageSink : MessageSink
1516
{
16-
public TrxMessageSink(string suiteName)
17-
: base(Props.Create(() => new TrxSinkActor(suiteName, System.Environment.UserName, System.Environment.MachineName, true)))
17+
public TrxMessageSink(string suiteName, MultiNodeTestRunnerOptions options)
18+
: base(Props.Create(() =>
19+
new TrxSinkActor(suiteName, Environment.UserName, Environment.MachineName, true, options)))
1820
{
1921
}
2022

src/Akka.MultiNode.TestAdapter/Internal/TrxReporter/TrxSinkActor.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.IO;
1111
using System.Linq;
1212
using System.Xml.Linq;
13+
using Akka.MultiNode.TestAdapter.Configuration;
1314
using Akka.MultiNode.TestAdapter.Internal.Reporting;
1415
using Akka.MultiNode.TestAdapter.Internal.Sinks;
1516
using Akka.MultiNode.TestAdapter.Internal.TrxReporter.Models;
@@ -18,19 +19,26 @@ namespace Akka.MultiNode.TestAdapter.Internal.TrxReporter
1819
{
1920
internal class TrxSinkActor : TestCoordinatorEnabledMessageSink
2021
{
21-
public TrxSinkActor(string suiteName, string userName, string computerName, bool useTestCoordinator)
22+
public TrxSinkActor(
23+
string suiteName,
24+
string userName,
25+
string computerName,
26+
bool useTestCoordinator,
27+
MultiNodeTestRunnerOptions options)
2228
: base(useTestCoordinator)
2329
{
2430
_computerName = computerName;
2531
_testRun = new TestRun(suiteName)
2632
{
2733
RunUser = userName
2834
};
35+
_options = options;
2936
}
3037

3138
private readonly string _computerName;
3239
private readonly TestRun _testRun;
3340
private SpecSession _session;
41+
private MultiNodeTestRunnerOptions _options;
3442

3543
protected override void AdditionalReceives()
3644
{
@@ -99,7 +107,7 @@ protected override void HandleTestRunEnd(EndTestRun endTestRun)
99107
_testRun.Serialize()
100108
);
101109

102-
doc.Save(Path.Combine(Directory.GetCurrentDirectory(), $@"mntr-{DateTime.UtcNow:yyyy'-'MM'-'dd'T'HH'-'mm'-'ss'-'fffffffK}.trx"));
110+
doc.Save(Path.Combine(Path.GetFullPath(_options.OutputDirectory), $@"mntr-{DateTime.UtcNow:yyyy'-'MM'-'dd'T'HH'-'mm'-'ss'-'fffffffK}.trx"));
103111
}
104112

105113
private static void ReportSpec(SpecSession session, TestRun testRun, string computerName, SpecLog log)

0 commit comments

Comments
 (0)