Used a changing pipe name
This ensures that we can have multiple worker processes running at the same time.
This commit is contained in:
@@ -8,9 +8,6 @@ namespace xunit.runner.data
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
// TODO: In order to support multiple runs this can't be a fixed name. Needs to be a prefix that increments
|
||||
// with every run to keep it unique.
|
||||
public const string PipeName = "xunit.runners.pipe";
|
||||
public const string ActionDiscover = "discover";
|
||||
public const string ActionRun = "run";
|
||||
public static readonly Encoding Encoding = Encoding.UTF8;
|
||||
|
||||
@@ -16,26 +16,28 @@ namespace xunit.runner.worker
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Usage();
|
||||
return ExitError;
|
||||
}
|
||||
|
||||
string pipeName = args[0];
|
||||
string action = args[1];
|
||||
string argument = args[2];
|
||||
|
||||
Stream stream = null;
|
||||
try
|
||||
{
|
||||
var namedPipeServerStream = new NamedPipeServerStream(Constants.PipeName);
|
||||
namedPipeServerStream.WaitForConnection();
|
||||
stream = namedPipeServerStream;
|
||||
stream = CreateStream(pipeName);
|
||||
|
||||
switch (args[0])
|
||||
switch (action)
|
||||
{
|
||||
case Constants.ActionDiscover:
|
||||
Discover(stream, args[1]);
|
||||
Discover(stream, argument);
|
||||
break;
|
||||
case Constants.ActionRun:
|
||||
Run(stream, args[1]);
|
||||
Run(stream, argument);
|
||||
break;
|
||||
default:
|
||||
Usage();
|
||||
@@ -57,6 +59,18 @@ namespace xunit.runner.worker
|
||||
return ExitSuccess;
|
||||
}
|
||||
|
||||
private static Stream CreateStream(string pipeName)
|
||||
{
|
||||
if (pipeName == "test")
|
||||
{
|
||||
return new MemoryStream();
|
||||
}
|
||||
|
||||
var namedPipeServerStream = new NamedPipeServerStream(pipeName);
|
||||
namedPipeServerStream.WaitForConnection();
|
||||
return namedPipeServerStream;
|
||||
}
|
||||
|
||||
private static void Discover(Stream stream, string assemblyPath)
|
||||
{
|
||||
Console.WriteLine($"discover started: {assemblyPath}");
|
||||
|
||||
@@ -49,17 +49,18 @@ namespace xunit.runner.wpf.Impl
|
||||
}
|
||||
}
|
||||
|
||||
private Connection StartWorkerProcess(string action, string argument)
|
||||
private static Connection StartWorkerProcess(string action, string argument)
|
||||
{
|
||||
var pipeName = $"xunit.runner.wpf.pipe.{Guid.NewGuid()}";
|
||||
var processStartInfo = new ProcessStartInfo();
|
||||
processStartInfo.FileName = typeof(xunit.runner.worker.Program).Assembly.Location;
|
||||
processStartInfo.Arguments = $"{action} {argument}";
|
||||
processStartInfo.Arguments = $"{pipeName} {action} {argument}";
|
||||
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
|
||||
var process = Process.Start(processStartInfo);
|
||||
try
|
||||
{
|
||||
var stream = new NamedPipeClientStream(Constants.PipeName);
|
||||
var stream = new NamedPipeClientStream(pipeName);
|
||||
stream.Connect();
|
||||
return new Connection(stream, process);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user