From cf5c313d286f155c80497f2d9ff67210427fffa4 Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Wed, 19 Aug 2015 13:47:48 -0700 Subject: [PATCH] Used a changing pipe name This ensures that we can have multiple worker processes running at the same time. --- xunit.runner.data/Constants.cs | 3 --- xunit.runner.worker/Program.cs | 28 ++++++++++++++++++------- xunit.runner.wpf/Impl/RemoteTestUtil.cs | 7 ++++--- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/xunit.runner.data/Constants.cs b/xunit.runner.data/Constants.cs index 1cc562f..8b942cf 100644 --- a/xunit.runner.data/Constants.cs +++ b/xunit.runner.data/Constants.cs @@ -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; diff --git a/xunit.runner.worker/Program.cs b/xunit.runner.worker/Program.cs index 680f764..8056cc9 100644 --- a/xunit.runner.worker/Program.cs +++ b/xunit.runner.worker/Program.cs @@ -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}"); diff --git a/xunit.runner.wpf/Impl/RemoteTestUtil.cs b/xunit.runner.wpf/Impl/RemoteTestUtil.cs index 9275f82..6c1deb9 100644 --- a/xunit.runner.wpf/Impl/RemoteTestUtil.cs +++ b/xunit.runner.wpf/Impl/RemoteTestUtil.cs @@ -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); }