static int Main(string[] args)
{
var nodeIndex = CommandLine.GetInt32("multinode.index");
var assemblyFileName = CommandLine.GetProperty("multinode.test-assembly");
var typeName = CommandLine.GetProperty("multinode.test-class");
var testName = CommandLine.GetProperty("multinode.test-method");
var displayName = testName;
var listenAddress = IPAddress.Parse(CommandLine.GetProperty("multinode.listen-address"));
var listenPort = CommandLine.GetInt32("multinode.listen-port");
var listenEndpoint = new IPEndPoint(listenAddress, listenPort);
var system = ActorSystem.Create("NoteTestRunner-" + nodeIndex);
var tcpClient = _logger = system.ActorOf<RunnerTcpClient>();
system.Tcp().Tell(new Tcp.Connect(listenEndpoint), tcpClient);
Thread.Sleep(TimeSpan.FromSeconds(10));
using (var controller = new XunitFrontController(assemblyFileName))
{
/* need to pass in just the assembly name to Discovery, not the full path
* i.e. "Akka.Cluster.Tests.MultiNode.dll"
* not "bin/Release/Akka.Cluster.Tests.MultiNode.dll" - this will cause
* the Discovery class to actually not find any indivudal specs to run
*/
var assemblyName = Path.GetFileName(assemblyFileName);
Console.WriteLine("Running specs for {0} [{1}]", assemblyName, assemblyFileName);
using (var discovery = new Discovery(assemblyName, typeName))
{
using (var sink = new Sink(nodeIndex, tcpClient))
{
try
{
controller.Find(true, discovery, TestFrameworkOptions.ForDiscovery());
discovery.Finished.WaitOne();
controller.RunTests(discovery.TestCases, sink, TestFrameworkOptions.ForExecution());
}
catch (AggregateException ex)
{
var specFail = new SpecFail(nodeIndex, displayName);
specFail.FailureExceptionTypes.Add(ex.GetType().ToString());
specFail.FailureMessages.Add(ex.Message);
specFail.FailureStackTraces.Add(ex.StackTrace);
foreach (var innerEx in ex.Flatten().InnerExceptions)
{
specFail.FailureExceptionTypes.Add(innerEx.GetType().ToString());
specFail.FailureMessages.Add(innerEx.Message);
specFail.FailureStackTraces.Add(innerEx.StackTrace);
}
_logger.Tell(specFail.ToString());
Console.WriteLine(specFail);
//make sure message is send over the wire
FlushLogMessages();
Environment.Exit(1); //signal failure
return 1;
}
catch (Exception ex)
{
var specFail = new SpecFail(nodeIndex, displayName);
specFail.FailureExceptionTypes.Add(ex.GetType().ToString());
specFail.FailureMessages.Add(ex.Message);
specFail.FailureStackTraces.Add(ex.StackTrace);
_logger.Tell(specFail.ToString());
Console.WriteLine(specFail);
//make sure message is send over the wire
FlushLogMessages();
Environment.Exit(1); //signal failure
return 1;
}
var timedOut = false;
if (!sink.Finished.WaitOne(MaxProcessWaitTimeout)) //timed out
{
var line = string.Format("Timed out while waiting for test to complete after {0} ms",
MaxProcessWaitTimeout);
_logger.Tell(line);
Console.WriteLine(line);
timedOut = true;
}
FlushLogMessages();
system.Terminate().Wait();
Environment.Exit(sink.Passed && !timedOut ? 0 : 1);
return sink.Passed ? 0 : 1;
}
}
}
}