From 5cadfbe01c28fe1dd56e0c851da67e3f5a8d37af Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 13 Jun 2017 21:33:39 +1000 Subject: [PATCH 1/2] Used ServerTask Id instead of the ScriptTicket.Id as the identifier for who is aquiring the mutex. Also included the ServerTask Id in the ScriptTicket.Id. --- .../Octopus.Manager.Tentacle.csproj | 2 +- source/Octopus.Manager.Tentacle/packages.config | 2 +- .../Octopus.Tentacle.Tests.csproj | 2 +- source/Octopus.Tentacle.Tests/packages.config | 2 +- source/Octopus.Tentacle/Octopus.Tentacle.csproj | 2 +- .../Octopus.Tentacle/Services/Scripts/ScriptService.cs | 10 +++++----- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/source/Octopus.Manager.Tentacle/Octopus.Manager.Tentacle.csproj b/source/Octopus.Manager.Tentacle/Octopus.Manager.Tentacle.csproj index 254c97f63..c0cef30a3 100644 --- a/source/Octopus.Manager.Tentacle/Octopus.Manager.Tentacle.csproj +++ b/source/Octopus.Manager.Tentacle/Octopus.Manager.Tentacle.csproj @@ -124,7 +124,7 @@ ..\packages\Octopus.Manager.Core.3.14.0-ci0053\lib\Octopus.Manager.Core.dll - ..\packages\Octopus.Shared.3.14.2-scriptisolationm0003\lib\Octopus.Shared.dll + ..\packages\Octopus.Shared.3.14.2-enh-scriptcomman0006\lib\Octopus.Shared.dll ..\packages\Octopus.Time.1.0.9\lib\netstandard1.0\Octopus.Time.dll diff --git a/source/Octopus.Manager.Tentacle/packages.config b/source/Octopus.Manager.Tentacle/packages.config index 586854175..41e7cc31b 100644 --- a/source/Octopus.Manager.Tentacle/packages.config +++ b/source/Octopus.Manager.Tentacle/packages.config @@ -19,7 +19,7 @@ - + diff --git a/source/Octopus.Tentacle.Tests/Octopus.Tentacle.Tests.csproj b/source/Octopus.Tentacle.Tests/Octopus.Tentacle.Tests.csproj index 40fac0c8f..6f630d7c7 100644 --- a/source/Octopus.Tentacle.Tests/Octopus.Tentacle.Tests.csproj +++ b/source/Octopus.Tentacle.Tests/Octopus.Tentacle.Tests.csproj @@ -139,7 +139,7 @@ ..\packages\Octopus.Diagnostics.1.0.12\lib\netstandard1.0\Octopus.Diagnostics.dll - ..\packages\Octopus.Shared.3.14.2-scriptisolationm0003\lib\Octopus.Shared.dll + ..\packages\Octopus.Shared.3.14.2-enh-scriptcomman0006\lib\Octopus.Shared.dll ..\packages\Octopus.Time.1.0.9\lib\netstandard1.0\Octopus.Time.dll diff --git a/source/Octopus.Tentacle.Tests/packages.config b/source/Octopus.Tentacle.Tests/packages.config index 5c74078d5..ecb9966ab 100644 --- a/source/Octopus.Tentacle.Tests/packages.config +++ b/source/Octopus.Tentacle.Tests/packages.config @@ -42,7 +42,7 @@ - + diff --git a/source/Octopus.Tentacle/Octopus.Tentacle.csproj b/source/Octopus.Tentacle/Octopus.Tentacle.csproj index ac9bb091c..b6351b448 100644 --- a/source/Octopus.Tentacle/Octopus.Tentacle.csproj +++ b/source/Octopus.Tentacle/Octopus.Tentacle.csproj @@ -16,7 +16,7 @@ - + diff --git a/source/Octopus.Tentacle/Services/Scripts/ScriptService.cs b/source/Octopus.Tentacle/Services/Scripts/ScriptService.cs index ea67b7749..e871811a8 100644 --- a/source/Octopus.Tentacle/Services/Scripts/ScriptService.cs +++ b/source/Octopus.Tentacle/Services/Scripts/ScriptService.cs @@ -25,10 +25,10 @@ public ScriptService(IScriptWorkspaceFactory workspaceFactory, IOctopusFileSyste public ScriptTicket StartScript(StartScriptCommand command) { - var ticket = ScriptTicket.Create(); + var ticket = ScriptTicket.Create(command.TaskId); var workspace = PrepareWorkspace(command, ticket); var cancel = new CancellationTokenSource(); - var process = LaunchPowerShell(ticket, workspace, cancel); + var process = LaunchPowerShell(ticket, command.TaskId, workspace, cancel); running.TryAdd(ticket.TaskId, process); cancellationTokens.TryAdd(ticket.TaskId, cancel); return ticket; @@ -70,11 +70,11 @@ IScriptLog CreateLog(IScriptWorkspace workspace) return new ScriptLog(workspace.ResolvePath("Output.log"), fileSystem); } - RunningScript LaunchPowerShell(ScriptTicket ticket, IScriptWorkspace workspace, CancellationTokenSource cancel) + RunningScript LaunchPowerShell(ScriptTicket ticket, string serverTaskId, IScriptWorkspace workspace, CancellationTokenSource cancel) { - var runningScript = new RunningScript(workspace, CreateLog(workspace), ticket.TaskId, cancel.Token); + var runningScript = new RunningScript(workspace, CreateLog(workspace), serverTaskId, cancel.Token); var thread = new Thread(runningScript.Execute); - thread.Name = "Executing PowerShell script for " + ticket.TaskId; + thread.Name = "Executing PowerShell script for " + ticket; thread.Start(); return runningScript; } From d4c443e91beacf8c001bdf028b871ed2d6193d51 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Wed, 14 Jun 2017 08:19:49 +1000 Subject: [PATCH 2/2] Fixed test --- .../Integration/ScriptServiceFixture.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/Octopus.Tentacle.Tests/Integration/ScriptServiceFixture.cs b/source/Octopus.Tentacle.Tests/Integration/ScriptServiceFixture.cs index c529513ad..e08b87d9c 100644 --- a/source/Octopus.Tentacle.Tests/Integration/ScriptServiceFixture.cs +++ b/source/Octopus.Tentacle.Tests/Integration/ScriptServiceFixture.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Threading; +using FluentAssertions; using NSubstitute; using NUnit.Framework; using Octopus.Shared.Configuration; @@ -50,8 +51,9 @@ public void ShouldPingLocalhostSuccessfully() [Test] public void ShouldPingRandomUnsuccessfully() { + var guid = Guid.NewGuid(); var startScriptCommand = new StartScriptCommandBuilder() - .WithScriptBody("& ping.exe " + Guid.NewGuid() + " -n 1") + .WithScriptBody($"& ping.exe {guid} -n 1") .Build(); var ticket = service.StartScript(startScriptCommand); @@ -65,7 +67,7 @@ public void ShouldPingRandomUnsuccessfully() DumpLog(finalStatus); Assert.That(finalStatus.State, Is.EqualTo(ProcessState.Complete)); Assert.That(finalStatus.ExitCode, Is.Not.EqualTo(0)); - Assert.That(finalStatus.Logs[0].Text, Is.StringContaining("Ping request could not find host")); + finalStatus.Logs.Select(l => l.Text).Should().Contain($"Ping request could not find host {guid}. Please check the name and try again."); } [Test]