Skip to content

Commit 8037e2f

Browse files
committed
Merge branch 'dev'
2 parents e18fbc0 + 58c2706 commit 8037e2f

File tree

10 files changed

+83
-66
lines changed

10 files changed

+83
-66
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#### 1.0.0-beta2 October 05 2019 ####
2+
- Fix, [node runner should ignore runs not started by MNTR](https://github.com/akkadotnet/Akka.MultiNodeTestRunner/pull/93)
3+
14
#### 1.0.0-beta1 October 05 2019 ####
25
First beta release
36

src/Akka.MultiNode.TestAdapter.Tests/MultiNodeTestExecutorSpec.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Akka.MultiNode.TestAdapter.SampleTests;
33
using Akka.MultiNode.TestAdapter.SampleTests.Metadata;
44
using Akka.MultiNode.TestAdapter.Tests.Helpers;
5+
using Akka.Remote.TestKit;
56
using FluentAssertions;
67
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
78
using Xunit;
@@ -17,6 +18,7 @@ public MultiNodeTestExecutorSpec()
1718
{
1819
_sampleTestsAssemblyPath = Path.GetFullPath(SampleTestsMetadata.AssemblyFileName);
1920
File.Exists(_sampleTestsAssemblyPath).Should().BeTrue($"Assemblies with samples should exist at {_sampleTestsAssemblyPath}");
21+
CommandLine.Initialize(new []{"-Dmultinode.test-runner=\"multinode\""});
2022
}
2123

2224
[Fact]

src/Akka.MultiNode.TestAdapter/Akka.MultiNode.TestAdapter.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<TargetFramework>$(NetStandardLibVersion)</TargetFramework>
77
<IncludeSource>true</IncludeSource>
88
<IncludeSymbols>true</IncludeSymbols>
9+
<LangVersion>8.0</LangVersion>
910
<!-- <EnableDefaultCompileItems>false</EnableDefaultCompileItems> -->
1011
<!-- <GenerateAssemblyInfo>false</GenerateAssemblyInfo> -->
1112
<!-- <NuspecFile>Akka.MultiNode.TestAdapter.nuspec</NuspecFile> -->

src/Akka.MultiNode.TestAdapter/Internal/Environment/MultiNodeEnvironment.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class NodeTest
1313
public string Role { get; set; }
1414
public MultiNodeTest Test { get; set; }
1515

16-
public string Name => $"{Test.TestName}_node{Node}[{Role}]";
16+
public string Name => $"{Test.MethodName}_node{Node}[{Role}]";
1717
}
1818
}
1919

src/Akka.MultiNode.TestAdapter/MultiNodeTestAdapter.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Linq;
77
using System.Xml;
88
using Akka.MultiNode.TestAdapter.Internal;
9-
using Akka.MultiNode.TestAdapter.Internal.Environment;
109
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1110
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
1211
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
@@ -27,11 +26,6 @@ namespace Akka.MultiNode.TestAdapter
2726
[ExtensionUri(Constants.ExecutorUriString)]
2827
public class MultiNodeTestAdapter : ITestDiscoverer, ITestExecutor
2928
{
30-
public MultiNodeTestAdapter()
31-
{
32-
MultiNodeEnvironment.Initialize();
33-
}
34-
3529
/// <summary>
3630
/// Discovers the tests available from the provided container.
3731
/// </summary>

src/Akka.MultiNode.TestAdapter/MultiNodeTestResult.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ public TestStatus Status {
4242
{
4343
if (!string.IsNullOrWhiteSpace(Test.SkipReason))
4444
return TestStatus.Skipped;
45-
return NodeResults.Any(result => result.Result == TestStatus.Failed) ? TestStatus.Failed : TestStatus.Passed;
45+
46+
if(NodeResults.Any(result => result.Result == TestStatus.Failed))
47+
return TestStatus.Failed;
48+
if (NodeResults.Any(result => result.Result == TestStatus.Skipped))
49+
return TestStatus.Skipped;
50+
return TestStatus.Passed;
4651
}
4752
}
4853
/// <summary>
@@ -57,7 +62,7 @@ public TestStatus Status {
5762
/// <inheritdoc />
5863
public override string ToString()
5964
{
60-
var sb = new StringBuilder($"Test {Test.TestName}: {Status}");
65+
var sb = new StringBuilder($"Test {Test.MethodName}: {Status}");
6166
if (Test.SkipReason != null)
6267
sb.Append(" Skipped: ").Append(Test.SkipReason);
6368
foreach (var node in NodeResults)

src/Akka.MultiNode.TestAdapter/MultiNodeTestRunner.cs

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919
using System.Threading.Tasks;
2020
using Akka.Actor;
2121
using Akka.IO;
22-
using Akka.MultiNode.TestAdapter.Helpers;
2322
using Akka.MultiNode.TestAdapter.Internal;
24-
using Akka.MultiNode.TestAdapter.Internal.Environment;
2523
using Akka.MultiNode.TestAdapter.Internal.Persistence;
2624
using Akka.MultiNode.TestAdapter.Internal.Sinks;
2725
using Akka.MultiNode.TestAdapter.Internal.TrxReporter;
2826
using Akka.MultiNode.TestAdapter.NodeRunner;
2927
using Akka.Remote.TestKit;
30-
using Akka.Util;
3128
using Xunit;
3229
using ErrorMessage = Xunit.Sdk.ErrorMessage;
3330

@@ -100,7 +97,6 @@ private void Initialize(string assemblyPath, MultiNodeTestRunnerOptions options)
10097
EnableAllSinks(assemblyPath, options);
10198

10299
// Set MNTR environment for correct tests discovery
103-
MultiNodeEnvironment.Initialize();
104100
}
105101

106102
public MultiNodeTestResult ExecuteSpec(MultiNodeTest test, MultiNodeTestRunnerOptions options)
@@ -113,6 +109,7 @@ public MultiNodeTestResult ExecuteSpec(MultiNodeTest test, MultiNodeTestRunnerOp
113109
: _tcpLogger.Ask<int>(TcpLoggingServer.GetBoundPort.Instance).Result;
114110

115111
TestStarted?.Invoke(test);
112+
Environment.SetEnvironmentVariable(MultiNodeFactAttribute.MultiNodeTestEnvironmentName, "1");
116113
try
117114
{
118115
if (options.SpecNames != null &&
@@ -132,10 +129,19 @@ public MultiNodeTestResult ExecuteSpec(MultiNodeTest test, MultiNodeTestRunnerOp
132129
var nodes = test.Nodes;
133130

134131
var result = RunSpec(options, test, listenPort);
135-
if(result.Status == MultiNodeTestResult.TestStatus.Failed)
136-
TestFailed?.Invoke(result);
137-
else
138-
TestPassed?.Invoke(result);
132+
switch (result.Status)
133+
{
134+
case MultiNodeTestResult.TestStatus.Passed:
135+
TestPassed?.Invoke(result);
136+
return result;
137+
case MultiNodeTestResult.TestStatus.Failed:
138+
TestFailed?.Invoke(result);
139+
return result;
140+
case MultiNodeTestResult.TestStatus.Skipped:
141+
TestSkipped?.Invoke(test, "Must be run using Akka.MultiNode.TestAdapter");
142+
return null;
143+
}
144+
139145
return result;
140146
}
141147
catch (Exception e)
@@ -144,6 +150,10 @@ public MultiNodeTestResult ExecuteSpec(MultiNodeTest test, MultiNodeTestRunnerOp
144150
PublishRunnerMessage(e.Message);
145151
return null;
146152
}
153+
finally
154+
{
155+
Environment.SetEnvironmentVariable(MultiNodeFactAttribute.MultiNodeTestEnvironmentName, null);
156+
}
147157
}
148158

149159
/// <summary>
@@ -173,17 +183,23 @@ public void Dispose()
173183
/// </summary>
174184
public static (List<MultiNodeTest> Tests, List<ErrorMessage> Errors) DiscoverSpecs(string assemblyPath)
175185
{
176-
MultiNodeEnvironment.Initialize();
177-
178-
using (var controller = new XunitFrontController(AppDomainSupport.IfAvailable, assemblyPath))
186+
Environment.SetEnvironmentVariable(MultiNodeFactAttribute.MultiNodeTestEnvironmentName, "1");
187+
try
179188
{
180-
using (var discovery = new Discovery(assemblyPath))
189+
using (var controller = new XunitFrontController(AppDomainSupport.IfAvailable, assemblyPath))
181190
{
182-
controller.Find(false, discovery, TestFrameworkOptions.ForDiscovery());
183-
discovery.Finished.WaitOne();
184-
return (discovery.MultiNodeTests, discovery.Errors);
191+
using (var discovery = new Discovery(assemblyPath))
192+
{
193+
controller.Find(false, discovery, TestFrameworkOptions.ForDiscovery());
194+
discovery.Finished.WaitOne();
195+
return (discovery.MultiNodeTests, discovery.Errors);
196+
}
185197
}
186198
}
199+
finally
200+
{
201+
Environment.SetEnvironmentVariable(MultiNodeFactAttribute.MultiNodeTestEnvironmentName, null);
202+
}
187203
}
188204

189205
private List<MultiNodeTestResult> DiscoverAndRunSpecs(string assemblyPath, MultiNodeTestRunnerOptions options)
@@ -226,12 +242,20 @@ private List<MultiNodeTestResult> DiscoverAndRunSpecs(string assemblyPath, Multi
226242

227243
// Run test on several nodes and report results
228244
var result = RunSpec(options, test, listenPort);
229-
if(result.Status == MultiNodeTestResult.TestStatus.Failed)
230-
TestFailed?.Invoke(result);
231-
else
232-
TestPassed?.Invoke(result);
233-
234-
testResults.Add(result);
245+
switch (result.Status)
246+
{
247+
case MultiNodeTestResult.TestStatus.Failed:
248+
TestFailed?.Invoke(result);
249+
testResults.Add(result);
250+
break;
251+
case MultiNodeTestResult.TestStatus.Passed:
252+
TestPassed?.Invoke(result);
253+
testResults.Add(result);
254+
break;
255+
case MultiNodeTestResult.TestStatus.Skipped:
256+
TestSkipped?.Invoke(test, test.SkipReason);
257+
continue;
258+
}
235259
}
236260
catch (Exception e)
237261
{
@@ -250,7 +274,7 @@ private MultiNodeTestResult RunSpec(MultiNodeTestRunnerOptions options, MultiNod
250274

251275
var timelineCollector = TestRunSystem.ActorOf(Props.Create(() => new TimelineLogCollectorActor()));
252276
//TODO: might need to do some validation here to avoid the 260 character max path error on Windows
253-
var folder = Directory.CreateDirectory(Path.Combine(options.OutputDirectory, test.TestName));
277+
var folder = Directory.CreateDirectory(Path.Combine(options.OutputDirectory, test.MethodName));
254278
var testOutputDir = folder.FullName;
255279

256280
var testResult = new MultiNodeTestResult(test);
@@ -270,7 +294,8 @@ private MultiNodeTestResult RunSpec(MultiNodeTestRunnerOptions options, MultiNod
270294
$@"-Dmultinode.role=""{nodeTest.Role}""",
271295
$@"-Dmultinode.listen-address={options.ListenAddress}",
272296
$@"-Dmultinode.listen-port={listenPort}",
273-
$@"-Dmultinode.test-assembly=""{test.AssemblyPath}"""
297+
$@"-Dmultinode.test-assembly=""{test.AssemblyPath}""",
298+
"-Dmultinode.test-runner=\"multinode\""
274299
};
275300

276301
// Configure process for node
@@ -319,7 +344,7 @@ private void DumpAggregatedSpecLogs(
319344

320345
if (result.Status == MultiNodeTestResult.TestStatus.Failed)
321346
{
322-
var failedSpecPath = Path.GetFullPath(Path.Combine(options.OutputDirectory, options.FailedSpecsDirectory, $"{result.Test.TestName}.txt"));
347+
var failedSpecPath = Path.GetFullPath(Path.Combine(options.OutputDirectory, options.FailedSpecsDirectory, $"{result.Test.MethodName}.txt"));
323348
var dumpFailureArtifactTask = timelineCollector.Ask<Done>(new TimelineLogCollectorActor.DumpToFile(failedSpecPath));
324349
dumpTasks.Add(dumpFailureArtifactTask);
325350
result.Attachments.Add(new MultiNodeTestResult.Attachment{Title = "Fail log", Path = failedSpecPath});
@@ -339,9 +364,12 @@ private void WaitForNodeExit(MultiNodeTestResult result, List<(NodeTest, Process
339364
process.WaitForExit();
340365
Console.WriteLine($"Process for test {test.Name} finished with code {process.ExitCode}");
341366
var nodeResult = result.NodeResults.First(n => n.Index == test.Node);
342-
nodeResult.Result = process.ExitCode == 0
343-
? MultiNodeTestResult.TestStatus.Passed
344-
: MultiNodeTestResult.TestStatus.Failed;
367+
nodeResult.Result = process.ExitCode switch
368+
{
369+
0 => MultiNodeTestResult.TestStatus.Passed,
370+
2 => MultiNodeTestResult.TestStatus.Skipped,
371+
_ => MultiNodeTestResult.TestStatus.Failed
372+
};
345373
}
346374
}
347375
finally
@@ -366,7 +394,7 @@ private Process StartNodeProcess(
366394
var nodeIndex = nodeTest.Node;
367395
var nodeRole = nodeTest.Role;
368396
var logFilePath = Path.GetFullPath(Path.Combine(specFolder.FullName, $"node{nodeIndex}__{nodeRole}__{_platformName}.txt"));
369-
var nodeInfo = new TimelineLogCollectorActor.NodeInfo(nodeIndex, nodeRole, _platformName, nodeTest.Test.TestName);
397+
var nodeInfo = new TimelineLogCollectorActor.NodeInfo(nodeIndex, nodeRole, _platformName, nodeTest.Test.MethodName);
370398
var fileActor = TestRunSystem.ActorOf(Props.Create(() => new FileSystemAppenderActor(logFilePath)));
371399
result.Attachments.Add(new MultiNodeTestResult.Attachment{Title = $"Node {nodeIndex} [{nodeRole}]", Path = logFilePath});
372400

@@ -377,7 +405,7 @@ private Process StartNodeProcess(
377405
{
378406
if (p.ExitCode == 0)
379407
{
380-
ReportSpecPassFromExitCode(nodeIndex, nodeRole, closureTest.Test.TestName);
408+
ReportSpecPassFromExitCode(nodeIndex, nodeRole, closureTest.Test.MethodName);
381409
}
382410
};
383411
opt.OutputDataReceived = (sender, eventArgs) =>
@@ -493,12 +521,8 @@ MessageSink CreateVisualizerFileSink()
493521
return new FileSystemMessageSink(visualizerProps);
494522
}
495523

496-
var fileSystemSink = CommandLine.GetProperty("multinode.enable-filesink");
497-
if (!string.IsNullOrEmpty(fileSystemSink))
498-
{
499-
SinkCoordinator.Tell(new SinkCoordinator.EnableSink(CreateJsonFileSink()));
500-
SinkCoordinator.Tell(new SinkCoordinator.EnableSink(CreateVisualizerFileSink()));
501-
}
524+
SinkCoordinator.Tell(new SinkCoordinator.EnableSink(CreateJsonFileSink()));
525+
SinkCoordinator.Tell(new SinkCoordinator.EnableSink(CreateVisualizerFileSink()));
502526
}
503527

504528
private void AbortTcpLoggingServer()

src/Akka.MultiNode.TestAdapter/NodeRunner/Executor.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using System.Threading;
1515
using Akka.Actor;
1616
using Akka.IO;
17-
using Akka.MultiNode.TestAdapter.Internal.Environment;
1817
using Akka.MultiNode.TestAdapter.Internal.Sinks;
1918
using Akka.Remote.TestKit;
2019
using Xunit;
@@ -32,10 +31,15 @@ public int Execute(string[] args)
3231
var maxProcessWaitTimeout = TimeSpan.FromMinutes(5);
3332
IActorRef logger = null;
3433

34+
Environment.SetEnvironmentVariable(MultiNodeFactAttribute.MultiNodeTestEnvironmentName, "1");
3535
try
3636
{
3737
CommandLine.Initialize(args);
3838

39+
var runner = CommandLine.GetPropertyOrDefault("multinode.test-runner", null);
40+
if (runner != "multinode")
41+
return 2;
42+
3943
var nodeIndex = CommandLine.GetInt32("multinode.index");
4044
var nodeRole = CommandLine.GetProperty("multinode.role");
4145
var assemblyFileName = CommandLine.GetProperty("multinode.test-assembly");
@@ -53,8 +57,6 @@ public int Execute(string[] args)
5357
var tcpClient = logger = system.ActorOf<RunnerTcpClient>();
5458
system.Tcp().Tell(new Tcp.Connect(listenEndpoint), tcpClient);
5559

56-
MultiNodeEnvironment.Initialize();
57-
5860
// In NetCore, if the assembly file hasn't been touched,
5961
// XunitFrontController would fail loading external assemblies and its dependencies.
6062

@@ -182,6 +184,10 @@ public int Execute(string[] args)
182184
Environment.Exit(1); //signal failure
183185
return 1;
184186
}
187+
finally
188+
{
189+
Environment.SetEnvironmentVariable(MultiNodeFactAttribute.MultiNodeTestEnvironmentName, null);
190+
}
185191

186192
void FlushLogMessages()
187193
{

src/common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<NetStandardLibVersion>netstandard2.0</NetStandardLibVersion>
2525
<FluentAssertionsVersion>6.1.0</FluentAssertionsVersion>
2626
<FsCheckVersion>2.9.0</FsCheckVersion>
27-
<AkkaVersion>1.4.26</AkkaVersion>
27+
<AkkaVersion>1.4.27</AkkaVersion>
2828
<AkkaPackageTags>akka;actors;actor model;Akka;concurrency</AkkaPackageTags>
2929
</PropertyGroup>
3030
<PropertyGroup>

0 commit comments

Comments
 (0)