From b7ff5b576849ace8c24c09ecab6845ae09fd619f Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Thu, 19 Sep 2024 12:40:28 +1200 Subject: [PATCH 01/30] Messy parallellisation --- .../TentacleCommandLineTests.cs | 68 +++++++++++++------ 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index fba7ceedb..d525c35cb 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -281,40 +281,35 @@ public async Task HelpForInstanceSpecificCommandsAlwaysWorks(TentacleConfigurati stdout, new { - Commands = new[] + Commands = new TentacleCommand[] { - new + new() { Name = "", Description = "", - Aliases = new string[0] + Aliases = Array.Empty() } } }); help.Commands.Should().HaveCountGreaterThan(0); - var failed = help.Commands.Select(async c => - { - var (exitCode2, stdout2, stderr2) = await RunCommand(tc, null,$"{c.Name}", "--help"); - return new - { - Command = c, - ExitCode = exitCode2, - StdOut = stdout2, - StdErr = stderr2, - HasExpectedExitCode = exitCode2 == 0, - HasExpectedHelpMessage = stdout2.StartsWith($"Usage: Tentacle {c.Name} []") - }; - }) - .Where(r => !(r.Result.HasExpectedExitCode && r.Result.HasExpectedHelpMessage)) - .ToArray(); - - if (failed.Any()) + List> commandResults = new List>(); + + foreach (var command in help.Commands) + { + commandResults.Add(GetCommandReturnValue(tc, command)); + } + + Task.WaitAll(commandResults.ToArray()); + + Task[] failedCommands = commandResults.Where(r => !(r.Result.HasExpectedExitCode && r.Result.HasExpectedHelpMessage)).ToArray(); + + if (failedCommands.Any()) { var failureDetails = string.Empty; - foreach (var failure in failed) + foreach (var failure in failedCommands) { failureDetails += $@"{failure.Result.Command.Name} StdErr:{failure.Result.StdErr} @@ -327,6 +322,37 @@ public async Task HelpForInstanceSpecificCommandsAlwaysWorks(TentacleConfigurati The details are logged above. These commands probably need to take Lazy dependencies so they can be instantiated for showing help without requiring every dependency to be resolvable."); } } + + async Task GetCommandReturnValue(TentacleConfigurationTestCase tc, TentacleCommand c) + { + var (exitCode2, stdout2, stderr2) = await RunCommand(tc, null,$"{c.Name}", "--help"); + return new CommandReturnValue + { + Command = c, + ExitCode = exitCode2, + StdOut = stdout2, + StdErr = stderr2, + HasExpectedExitCode = exitCode2 == 0, + HasExpectedHelpMessage = stdout2.StartsWith($"Usage: Tentacle {c.Name} []") + }; + } + + class TentacleCommand + { + public string Name { get; set; } + public string Description { get; set; } + public string[] Aliases { get; set; } + } + + class CommandReturnValue + { + public TentacleCommand Command { get; set; } + public int ExitCode { get; set; } + public string StdOut { get; set; } + public string StdErr { get; set; } + public bool HasExpectedExitCode { get; set; } + public bool HasExpectedHelpMessage { get; set; } + } [Test] [TentacleConfigurations(scriptServiceToTest: ScriptServiceVersionToTest.None)] From d68cbd8bd2b13a6393ab863b578c68414437bf82 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Thu, 19 Sep 2024 15:04:00 +1200 Subject: [PATCH 02/30] Wait indefinitely to clean up workspace --- source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs b/source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs index c2c82e748..0da088adb 100644 --- a/source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs +++ b/source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs @@ -17,7 +17,7 @@ class WorkspaceCleanerTask : BackgroundTask, IWorkspaceCleanerTask public WorkspaceCleanerTask( WorkspaceCleanerConfiguration configuration, WorkspaceCleaner workspaceCleaner, - ISystemLog log) : base(log, TimeSpan.FromSeconds(30)) + ISystemLog log) : base(log, TimeSpan.FromMilliseconds(-1)) { this.configuration = configuration; this.workspaceCleaner = workspaceCleaner; From 4f6a2fb166b29d329d33f695f4436720986dba0b Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Thu, 19 Sep 2024 16:18:03 +1200 Subject: [PATCH 03/30] Revert "Wait indefinitely to clean up workspace" This reverts commit d68cbd8bd2b13a6393ab863b578c68414437bf82. --- source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs b/source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs index 0da088adb..c2c82e748 100644 --- a/source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs +++ b/source/Octopus.Tentacle/Maintenance/WorkspaceCleanerTask.cs @@ -17,7 +17,7 @@ class WorkspaceCleanerTask : BackgroundTask, IWorkspaceCleanerTask public WorkspaceCleanerTask( WorkspaceCleanerConfiguration configuration, WorkspaceCleaner workspaceCleaner, - ISystemLog log) : base(log, TimeSpan.FromMilliseconds(-1)) + ISystemLog log) : base(log, TimeSpan.FromSeconds(30)) { this.configuration = configuration; this.workspaceCleaner = workspaceCleaner; From ecac9b40da8cca4888efa21ec29ec5a956e4c52f Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Thu, 19 Sep 2024 16:23:50 +1200 Subject: [PATCH 04/30] Revert "Messy parallellisation" This reverts commit b7ff5b576849ace8c24c09ecab6845ae09fd619f. --- .../TentacleCommandLineTests.cs | 68 ++++++------------- 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index d525c35cb..fba7ceedb 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -281,35 +281,40 @@ public async Task HelpForInstanceSpecificCommandsAlwaysWorks(TentacleConfigurati stdout, new { - Commands = new TentacleCommand[] + Commands = new[] { - new() + new { Name = "", Description = "", - Aliases = Array.Empty() + Aliases = new string[0] } } }); help.Commands.Should().HaveCountGreaterThan(0); - List> commandResults = new List>(); - - foreach (var command in help.Commands) - { - commandResults.Add(GetCommandReturnValue(tc, command)); - } - - Task.WaitAll(commandResults.ToArray()); - - Task[] failedCommands = commandResults.Where(r => !(r.Result.HasExpectedExitCode && r.Result.HasExpectedHelpMessage)).ToArray(); - - if (failedCommands.Any()) + var failed = help.Commands.Select(async c => + { + var (exitCode2, stdout2, stderr2) = await RunCommand(tc, null,$"{c.Name}", "--help"); + return new + { + Command = c, + ExitCode = exitCode2, + StdOut = stdout2, + StdErr = stderr2, + HasExpectedExitCode = exitCode2 == 0, + HasExpectedHelpMessage = stdout2.StartsWith($"Usage: Tentacle {c.Name} []") + }; + }) + .Where(r => !(r.Result.HasExpectedExitCode && r.Result.HasExpectedHelpMessage)) + .ToArray(); + + if (failed.Any()) { var failureDetails = string.Empty; - foreach (var failure in failedCommands) + foreach (var failure in failed) { failureDetails += $@"{failure.Result.Command.Name} StdErr:{failure.Result.StdErr} @@ -322,37 +327,6 @@ public async Task HelpForInstanceSpecificCommandsAlwaysWorks(TentacleConfigurati The details are logged above. These commands probably need to take Lazy dependencies so they can be instantiated for showing help without requiring every dependency to be resolvable."); } } - - async Task GetCommandReturnValue(TentacleConfigurationTestCase tc, TentacleCommand c) - { - var (exitCode2, stdout2, stderr2) = await RunCommand(tc, null,$"{c.Name}", "--help"); - return new CommandReturnValue - { - Command = c, - ExitCode = exitCode2, - StdOut = stdout2, - StdErr = stderr2, - HasExpectedExitCode = exitCode2 == 0, - HasExpectedHelpMessage = stdout2.StartsWith($"Usage: Tentacle {c.Name} []") - }; - } - - class TentacleCommand - { - public string Name { get; set; } - public string Description { get; set; } - public string[] Aliases { get; set; } - } - - class CommandReturnValue - { - public TentacleCommand Command { get; set; } - public int ExitCode { get; set; } - public string StdOut { get; set; } - public string StdErr { get; set; } - public bool HasExpectedExitCode { get; set; } - public bool HasExpectedHelpMessage { get; set; } - } [Test] [TentacleConfigurations(scriptServiceToTest: ScriptServiceVersionToTest.None)] From 6012fb686e98b933e6b47a84497c925d19077821 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Thu, 19 Sep 2024 18:27:19 +1200 Subject: [PATCH 05/30] Add some logging --- .../TentacleCommandLineTests.cs | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index fba7ceedb..af6b8e9fe 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -387,17 +387,29 @@ public async Task ShowThumbprintCommandJson(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); - await clientAndTentacle.RunningTentacle.Stop(CancellationToken); - var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( - tc, - clientAndTentacle.RunningTentacle.RunTentacleEnvironmentVariables, - "list-instances", "--format=text"); - - exitCode.Should().Be(0, $"we expected the command to succeed.\r\nStdErr: '{stderr}'\r\nStdOut: '{stdout}'"); - var configPath = Path.Combine(clientAndTentacle.RunningTentacle.HomeDirectory, clientAndTentacle.RunningTentacle.InstanceName + ".cfg"); - stdout.Should().Contain($"Instance '{clientAndTentacle.RunningTentacle.InstanceName}' uses configuration '{configPath}'.", "the current instance should be listed"); - stderr.Should().BeNullOrEmpty(); + Logger.Information("Inside ListInstancesCommandText"); + + await using (var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken)) + { + Logger.Information("Opened clientAndTentacle. Going to call stop on apparently running tentacle"); + + await clientAndTentacle.RunningTentacle.Stop(CancellationToken); + + Logger.Information("Finished stopping apparently running tentacle"); + + Logger.Information("Listing instances"); + var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( + tc, + clientAndTentacle.RunningTentacle.RunTentacleEnvironmentVariables, + "list-instances", "--format=text"); + + Logger.Information("Finished Listing instances"); + + exitCode.Should().Be(0, $"we expected the command to succeed.\r\nStdErr: '{stderr}'\r\nStdOut: '{stdout}'"); + var configPath = Path.Combine(clientAndTentacle.RunningTentacle.HomeDirectory, clientAndTentacle.RunningTentacle.InstanceName + ".cfg"); + stdout.Should().Contain($"Instance '{clientAndTentacle.RunningTentacle.InstanceName}' uses configuration '{configPath}'.", "the current instance should be listed"); + stderr.Should().BeNullOrEmpty(); + } } [Test] From bc5dc280f8f8bb23492e849f964fb1be118ae455 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Thu, 19 Sep 2024 21:23:21 +1200 Subject: [PATCH 06/30] Further logging --- .../TentacleCommandLineTests.cs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index af6b8e9fe..736bdb19e 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -734,19 +734,36 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati { environmentVariablesToRunTentacleWith.Add(EnvironmentVariables.TentacleMachineConfigurationHomeDirectory, tempDirectory.DirectoryPath); } + + Logger.Information("Listing instances: going to call TentacleExeFinder.FindTentacleExe"); var tentacleExe = TentacleExeFinder.FindTentacleExe(tentacleConfigurationTestCase.TentacleRuntime); var output = new StringBuilder(); var errorOut = new StringBuilder(); + Logger.Information("Listing instances: going to call await RetryHelper.RetryAsync"); + var result = await RetryHelper.RetryAsync( - () => Cli.Wrap(tentacleExe) - .WithArguments(arguments) - .WithValidation(CommandResultValidation.None) - .WithStandardOutputPipe(PipeTarget.ToStringBuilder(output)) - .WithStandardErrorPipe(PipeTarget.ToStringBuilder(errorOut)) - .WithEnvironmentVariables(environmentVariablesToRunTentacleWith) - .ExecuteAsync(CancellationToken)); + () => + { + Logger.Information($"Listing instances: going to call Cli.Wrap with exe: {tentacleExe} ..."); + try + { + return Cli.Wrap(tentacleExe) + .WithArguments(arguments) + .WithValidation(CommandResultValidation.None) + .WithStandardOutputPipe(PipeTarget.ToStringBuilder(output)) + .WithStandardErrorPipe(PipeTarget.ToStringBuilder(errorOut)) + .WithEnvironmentVariables(environmentVariablesToRunTentacleWith) + .ExecuteAsync(CancellationToken); + } + catch (Exception e) + { + Logger.Information($"Listing instances threw an exception:{e.Message}: {e.StackTrace}"); + throw; + } + + }); return (result.ExitCode, output.ToString(), errorOut.ToString()); } From 69c6ed7624a757b5b6b2fc7fd4750e1c6a045226 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Thu, 19 Sep 2024 21:39:16 +1200 Subject: [PATCH 07/30] Add more logging --- .../TentacleCommandLineTests.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index 736bdb19e..7690ca3f9 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -734,19 +734,29 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati { environmentVariablesToRunTentacleWith.Add(EnvironmentVariables.TentacleMachineConfigurationHomeDirectory, tempDirectory.DirectoryPath); } - - Logger.Information("Listing instances: going to call TentacleExeFinder.FindTentacleExe"); + + if (arguments is not null && arguments.Length == 2 && arguments[0] == "list-instances") + { + Logger.Information("Listing instances: going to call TentacleExeFinder.FindTentacleExe"); + } var tentacleExe = TentacleExeFinder.FindTentacleExe(tentacleConfigurationTestCase.TentacleRuntime); var output = new StringBuilder(); var errorOut = new StringBuilder(); - - Logger.Information("Listing instances: going to call await RetryHelper.RetryAsync"); + + if (arguments is not null && arguments.Length == 2 && arguments[0] == "list-instances") + { + Logger.Information("Listing instances: going to call await RetryHelper.RetryAsync"); + } var result = await RetryHelper.RetryAsync( () => { - Logger.Information($"Listing instances: going to call Cli.Wrap with exe: {tentacleExe} ..."); + if (arguments is not null && arguments.Length == 2 && arguments[0] == "list-instances") + { + Logger.Information($"Listing instances: going to call Cli.Wrap with exe: {tentacleExe} ..."); + } + try { return Cli.Wrap(tentacleExe) @@ -759,7 +769,7 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati } catch (Exception e) { - Logger.Information($"Listing instances threw an exception:{e.Message}: {e.StackTrace}"); + Logger.Information($"Cli.Wrap(tentacleExe threw an exception:{e.Message}: {e.StackTrace}"); throw; } From 48dc858ad2af2eb4055bb93a66c92746f118e1ad Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Fri, 20 Sep 2024 03:06:17 +1200 Subject: [PATCH 08/30] Log out dispose --- .../Support/RunningTentacle.cs | 1 + .../TentacleCommandLineTests.cs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs b/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs index eb81ccbec..3796789ec 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs @@ -109,6 +109,7 @@ public async ValueTask DisposeAsync() logger.Information("Starting deleteInstanceFunction"); await deleteInstanceFunction(cancellationToken); + logger.Information("Just finished disposing Halibut??? with deleteInstanceFunction"); logger.Information("Starting temporaryDirectory.Dispose"); temporaryDirectory.Dispose(); diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index 7690ca3f9..0ae1a8a31 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -409,7 +409,12 @@ public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) var configPath = Path.Combine(clientAndTentacle.RunningTentacle.HomeDirectory, clientAndTentacle.RunningTentacle.InstanceName + ".cfg"); stdout.Should().Contain($"Instance '{clientAndTentacle.RunningTentacle.InstanceName}' uses configuration '{configPath}'.", "the current instance should be listed"); stderr.Should().BeNullOrEmpty(); + Logger.Information("Done with clientAndTentacle. Going to dispose soon"); + } + + Logger.Information("Finished Disposing clientAndTentacle"); + } [Test] From 51fd41a313f209a6bb421d415400305bedd5cb9b Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Fri, 20 Sep 2024 10:56:11 +1200 Subject: [PATCH 09/30] Set timeout of dispose cancellation token to 100 seconds --- .../Support/RunningTentacle.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs b/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs index 3796789ec..4f2804f16 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs @@ -96,7 +96,7 @@ public async Task Restart(CancellationToken cancellationToken) public async ValueTask DisposeAsync() { - using var disposeCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10)); + using var disposeCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(100)); var cancellationToken = disposeCancellationTokenSource.Token; logger.Information("Starting DisposeAsync"); From 3e71b301d6000790c70d8e8d577df814346be3bb Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Fri, 20 Sep 2024 12:37:56 +1200 Subject: [PATCH 10/30] Logging RunCommandOutOfProcess --- .../Support/TentacleBuilder.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs index 952ed4bcd..57f57dc10 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs @@ -489,6 +489,8 @@ async Task RunCommandOutOfProcess( ILogger logger, CancellationToken cancellationToken) { + logger.Information("Inside RunCommandOutOfProcess"); + async Task ProcessLogs(string s, CancellationToken ct) { await Task.CompletedTask; @@ -498,14 +500,19 @@ async Task ProcessLogs(string s, CancellationToken ct) try { + logger.Information("Going to try to run Cli.Wrap(targetFilePath) with retries..."); var commandResult = await RetryHelper.RetryAsync( - () => Cli.Wrap(targetFilePath) - .WithArguments(args) - .WithEnvironmentVariables(environmentVariables) - .WithWorkingDirectory(tmp.DirectoryPath) - .WithStandardOutputPipe(PipeTarget.ToDelegate(ProcessLogs)) - .WithStandardErrorPipe(PipeTarget.ToDelegate(ProcessLogs)) - .ExecuteAsync(cancellationToken)); + () => + { + logger.Information("Going to try to run Cli.Wrap(targetFilePath)"); + return Cli.Wrap(targetFilePath) + .WithArguments(args) + .WithEnvironmentVariables(environmentVariables) + .WithWorkingDirectory(tmp.DirectoryPath) + .WithStandardOutputPipe(PipeTarget.ToDelegate(ProcessLogs)) + .WithStandardErrorPipe(PipeTarget.ToDelegate(ProcessLogs)) + .ExecuteAsync(cancellationToken); + }); if (cancellationToken.IsCancellationRequested) return; @@ -516,6 +523,13 @@ async Task ProcessLogs(string s, CancellationToken ct) } catch (OperationCanceledException) { + logger.Information("We have an OperationCanceledException"); + } + catch (Exception ex) + { + logger.Information($"We have an Exception: {ex.Message}: {ex.StackTrace}"); + logger.Information($"We have an Inner Exception?: {ex.InnerException?.Message}: {ex.InnerException?.StackTrace}"); + throw; } } } From f8be7e529399febc208ce628ac59730fc45e292b Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Fri, 20 Sep 2024 14:38:13 +1200 Subject: [PATCH 11/30] Little bit more logging on exit code --- .../Support/TentacleBuilder.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs index 57f57dc10..68eb7cc51 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs @@ -493,6 +493,7 @@ async Task RunCommandOutOfProcess( async Task ProcessLogs(string s, CancellationToken ct) { + logger.Information($"In ProcessLogs(): {s}"); await Task.CompletedTask; logger.Information($"[{commandName}] " + s); commandOutput(s); @@ -505,21 +506,30 @@ async Task ProcessLogs(string s, CancellationToken ct) () => { logger.Information("Going to try to run Cli.Wrap(targetFilePath)"); - return Cli.Wrap(targetFilePath) + var res = Cli.Wrap(targetFilePath) .WithArguments(args) .WithEnvironmentVariables(environmentVariables) .WithWorkingDirectory(tmp.DirectoryPath) .WithStandardOutputPipe(PipeTarget.ToDelegate(ProcessLogs)) .WithStandardErrorPipe(PipeTarget.ToDelegate(ProcessLogs)) .ExecuteAsync(cancellationToken); + logger.Information("Cli.Wrap(targetFilePath) returned"); + logger.Information($"Exit code: {res.Task.Result.ExitCode}"); + return res; }); - if (cancellationToken.IsCancellationRequested) return; + if (cancellationToken.IsCancellationRequested) + { + logger.Information("Cancelled RunCommandOutOfProcess"); + return; + } if (commandResult.ExitCode != 0) { throw new Exception($"{commandName} returns non zero exit code: " + commandResult.ExitCode); } + + logger.Information("End of RunCommandOutOfProcess"); } catch (OperationCanceledException) { From 0584e5a188ee0869d3bc389acfa95be91a205b75 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Fri, 20 Sep 2024 15:21:05 +1200 Subject: [PATCH 12/30] Add logging into tentacle stop process --- .../Support/RunningTentacle.cs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs b/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs index 4f2804f16..85ed8f862 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/RunningTentacle.cs @@ -70,21 +70,43 @@ public async Task Start(CancellationToken cancellationToken) public async Task Stop(CancellationToken cancellationToken) { + logger.Information("Stopping Tentacle"); if (cancellationTokenSource != null) { + logger.Information("Calling Tentacle cancellation token source.cancel"); + cancellationTokenSource.Cancel(); + + logger.Information("Disposing Tentacle cancellation token source"); + cancellationTokenSource.Dispose(); + + logger.Information("Disposed Tentacle cancellation token source"); + cancellationTokenSource = null; } if (runningTentacleTask != null) { + var task = runningTentacleTask; runningTentacleTask = null; - return await task.WaitTillCompletedOrCancelled(cancellationToken); + logger.Information("Going to call task.WaitTillCompletedOrCancelled(cancellationToken)"); + + if (await task.WaitTillCompletedOrCancelled(cancellationToken)) + { + logger.Information("returning true for task.WaitTillCompletedOrCancelled(cancellationToken)"); + + return true; + } + logger.Information("returning false for task.WaitTillCompletedOrCancelled(cancellationToken)"); + + return false; } + logger.Information("Stopping Tentacle: returning true"); + return true; } From 995979e580051a1f97aff0b3d4f9cda0aa9651f5 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Fri, 20 Sep 2024 16:10:54 +1200 Subject: [PATCH 13/30] Try not disposing and see if at least that test passes --- .../TentacleCommandLineTests.cs | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index 0ae1a8a31..d9616e9b0 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -389,29 +389,27 @@ public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) { Logger.Information("Inside ListInstancesCommandText"); - await using (var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken)) - { - Logger.Information("Opened clientAndTentacle. Going to call stop on apparently running tentacle"); - - await clientAndTentacle.RunningTentacle.Stop(CancellationToken); - - Logger.Information("Finished stopping apparently running tentacle"); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + + Logger.Information("Opened clientAndTentacle. Going to call stop on apparently running tentacle"); - Logger.Information("Listing instances"); - var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( - tc, - clientAndTentacle.RunningTentacle.RunTentacleEnvironmentVariables, - "list-instances", "--format=text"); + await clientAndTentacle.RunningTentacle.Stop(CancellationToken); + + Logger.Information("Finished stopping apparently running tentacle"); - Logger.Information("Finished Listing instances"); + Logger.Information("Listing instances"); + var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( + tc, + clientAndTentacle.RunningTentacle.RunTentacleEnvironmentVariables, + "list-instances", "--format=text"); - exitCode.Should().Be(0, $"we expected the command to succeed.\r\nStdErr: '{stderr}'\r\nStdOut: '{stdout}'"); - var configPath = Path.Combine(clientAndTentacle.RunningTentacle.HomeDirectory, clientAndTentacle.RunningTentacle.InstanceName + ".cfg"); - stdout.Should().Contain($"Instance '{clientAndTentacle.RunningTentacle.InstanceName}' uses configuration '{configPath}'.", "the current instance should be listed"); - stderr.Should().BeNullOrEmpty(); - Logger.Information("Done with clientAndTentacle. Going to dispose soon"); + Logger.Information("Finished Listing instances"); - } + exitCode.Should().Be(0, $"we expected the command to succeed.\r\nStdErr: '{stderr}'\r\nStdOut: '{stdout}'"); + var configPath = Path.Combine(clientAndTentacle.RunningTentacle.HomeDirectory, clientAndTentacle.RunningTentacle.InstanceName + ".cfg"); + stdout.Should().Contain($"Instance '{clientAndTentacle.RunningTentacle.InstanceName}' uses configuration '{configPath}'.", "the current instance should be listed"); + stderr.Should().BeNullOrEmpty(); + Logger.Information("Done with clientAndTentacle. Going to dispose soon"); Logger.Information("Finished Disposing clientAndTentacle"); From d10281baf78ee898e54d78599e97e441bba25b10 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Fri, 20 Sep 2024 17:04:56 +1200 Subject: [PATCH 14/30] Introduce logging of deletion --- .../TentacleCommandLineTests.cs | 36 ++++++++++--------- .../Commands/DeleteInstanceCommand.cs | 2 ++ .../Instances/ApplicationInstanceStore.cs | 6 ++++ ...WindowsRegistryApplicationInstanceStore.cs | 14 ++++++++ 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index d9616e9b0..0ae1a8a31 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -389,27 +389,29 @@ public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) { Logger.Information("Inside ListInstancesCommandText"); - var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); - - Logger.Information("Opened clientAndTentacle. Going to call stop on apparently running tentacle"); + await using (var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken)) + { + Logger.Information("Opened clientAndTentacle. Going to call stop on apparently running tentacle"); - await clientAndTentacle.RunningTentacle.Stop(CancellationToken); - - Logger.Information("Finished stopping apparently running tentacle"); + await clientAndTentacle.RunningTentacle.Stop(CancellationToken); + + Logger.Information("Finished stopping apparently running tentacle"); - Logger.Information("Listing instances"); - var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( - tc, - clientAndTentacle.RunningTentacle.RunTentacleEnvironmentVariables, - "list-instances", "--format=text"); + Logger.Information("Listing instances"); + var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( + tc, + clientAndTentacle.RunningTentacle.RunTentacleEnvironmentVariables, + "list-instances", "--format=text"); - Logger.Information("Finished Listing instances"); + Logger.Information("Finished Listing instances"); - exitCode.Should().Be(0, $"we expected the command to succeed.\r\nStdErr: '{stderr}'\r\nStdOut: '{stdout}'"); - var configPath = Path.Combine(clientAndTentacle.RunningTentacle.HomeDirectory, clientAndTentacle.RunningTentacle.InstanceName + ".cfg"); - stdout.Should().Contain($"Instance '{clientAndTentacle.RunningTentacle.InstanceName}' uses configuration '{configPath}'.", "the current instance should be listed"); - stderr.Should().BeNullOrEmpty(); - Logger.Information("Done with clientAndTentacle. Going to dispose soon"); + exitCode.Should().Be(0, $"we expected the command to succeed.\r\nStdErr: '{stderr}'\r\nStdOut: '{stdout}'"); + var configPath = Path.Combine(clientAndTentacle.RunningTentacle.HomeDirectory, clientAndTentacle.RunningTentacle.InstanceName + ".cfg"); + stdout.Should().Contain($"Instance '{clientAndTentacle.RunningTentacle.InstanceName}' uses configuration '{configPath}'.", "the current instance should be listed"); + stderr.Should().BeNullOrEmpty(); + Logger.Information("Done with clientAndTentacle. Going to dispose soon"); + + } Logger.Information("Finished Disposing clientAndTentacle"); diff --git a/source/Octopus.Tentacle/Commands/DeleteInstanceCommand.cs b/source/Octopus.Tentacle/Commands/DeleteInstanceCommand.cs index 16e7d54ae..158035f8a 100644 --- a/source/Octopus.Tentacle/Commands/DeleteInstanceCommand.cs +++ b/source/Octopus.Tentacle/Commands/DeleteInstanceCommand.cs @@ -19,7 +19,9 @@ public DeleteInstanceCommand(IApplicationInstanceSelector instanceSelector, IApp protected override void Start() { + SystemLog.Info("Going to call instanceManager.DeleteInstance(instanceSelector.Current.InstanceName)"); if (instanceSelector.Current.InstanceName != null) instanceManager.DeleteInstance(instanceSelector.Current.InstanceName); + SystemLog.Info("Finished calling instanceManager.DeleteInstance(instanceSelector.Current.InstanceName)"); } } } \ No newline at end of file diff --git a/source/Octopus.Tentacle/Configuration/Instances/ApplicationInstanceStore.cs b/source/Octopus.Tentacle/Configuration/Instances/ApplicationInstanceStore.cs index 3e5a27b2b..db331a178 100644 --- a/source/Octopus.Tentacle/Configuration/Instances/ApplicationInstanceStore.cs +++ b/source/Octopus.Tentacle/Configuration/Instances/ApplicationInstanceStore.cs @@ -81,11 +81,15 @@ public void RegisterInstance(ApplicationInstanceRecord instanceRecord) public void DeleteInstance(string instanceName) { + log.Info($"Inside Delete instance: {instanceName}"); + var instanceConfiguration = InstanceFileName(instanceName); try { + log.Info($"Try Delete instance file: {instanceConfiguration}"); fileSystem.DeleteFile(instanceConfiguration); + log.Info($"Finished Deleting instance file: {instanceConfiguration}"); } catch (UnauthorizedAccessException ex) { @@ -93,6 +97,8 @@ public void DeleteInstance(string instanceName) throw new ControlledFailureException($"Unable to delete file '{instanceConfiguration}' as user '{Environment.UserName}'. Please check file permissions."); } + log.Info($"Deleting instance from registry: {instanceName}"); + registryApplicationInstanceStore.DeleteFromRegistry(instanceName); log.Info($"Deleted instance: {instanceName}"); diff --git a/source/Octopus.Tentacle/Configuration/Instances/WindowsRegistryApplicationInstanceStore.cs b/source/Octopus.Tentacle/Configuration/Instances/WindowsRegistryApplicationInstanceStore.cs index 74e9676a5..f66a8c06c 100644 --- a/source/Octopus.Tentacle/Configuration/Instances/WindowsRegistryApplicationInstanceStore.cs +++ b/source/Octopus.Tentacle/Configuration/Instances/WindowsRegistryApplicationInstanceStore.cs @@ -71,25 +71,39 @@ public IEnumerable GetListFromRegistry() public void DeleteFromRegistry(string instanceName) { + log.Info($"Entering DeleteFromRegistry"); + if (!PlatformDetection.IsRunningOnWindows) + { + log.Info($"Inside DeleteFromRegistry: Is running on Windows"); return; + } var registryInstance = GetInstanceFromRegistry(instanceName); if (registryInstance == null) + { + log.Info($"Inside DeleteFromRegistry: registryInstance looks like is null"); return; + } try { #pragma warning disable CA1416 + log.Info($"Inside DeleteFromRegistry: trying to delete from actual registry"); using var rootKey = RegistryKey.OpenBaseKey(Hive, View); using var subKey = rootKey.OpenSubKey(KeyName, true); using var applicationNameKey = subKey?.OpenSubKey(applicationName.ToString(), true); if (applicationNameKey == null) + { + log.Info($"Inside DeleteFromRegistry: No applicationNameKey found: {applicationNameKey}"); return; + } applicationNameKey.DeleteSubKey(instanceName); + log.Info($"Inside DeleteFromRegistry: could delete from actual registry"); applicationNameKey.Flush(); + log.Info($"Inside DeleteFromRegistry: flushed"); #pragma warning restore CA1416 } catch (UnauthorizedAccessException ex) From 54fd2c8b904649fa5cc98db9957dde512fd1a324 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Fri, 20 Sep 2024 19:48:14 +1200 Subject: [PATCH 15/30] Taking out a few using statements to test theory --- .../TentacleCommandLineTests.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index 0ae1a8a31..9e73c6596 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -351,7 +351,7 @@ public async Task InvalidInstance(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ShowThumbprintCommandText(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -369,7 +369,7 @@ public async Task ShowThumbprintCommandText(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ShowThumbprintCommandJson(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -389,8 +389,8 @@ public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) { Logger.Information("Inside ListInstancesCommandText"); - await using (var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken)) - { + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + Logger.Information("Opened clientAndTentacle. Going to call stop on apparently running tentacle"); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); @@ -410,8 +410,7 @@ public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) stdout.Should().Contain($"Instance '{clientAndTentacle.RunningTentacle.InstanceName}' uses configuration '{configPath}'.", "the current instance should be listed"); stderr.Should().BeNullOrEmpty(); Logger.Information("Done with clientAndTentacle. Going to dispose soon"); - - } + Logger.Information("Finished Disposing clientAndTentacle"); @@ -423,7 +422,7 @@ public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ListInstancesCommandJson(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (_, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -537,7 +536,7 @@ to text. [NonParallelizable] public async Task ShowConfigurationCommand(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (_, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, From 3624a782bd3238ebe34f0c9484e8df04a3e2fbf3 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Sat, 21 Sep 2024 03:01:09 +1200 Subject: [PATCH 16/30] Add back onto one test --- .../TentacleCommandLineTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index 9e73c6596..0f19fe33f 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -410,8 +410,8 @@ public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) stdout.Should().Contain($"Instance '{clientAndTentacle.RunningTentacle.InstanceName}' uses configuration '{configPath}'.", "the current instance should be listed"); stderr.Should().BeNullOrEmpty(); Logger.Information("Done with clientAndTentacle. Going to dispose soon"); - - + + await clientAndTentacle.DisposeAsync(); Logger.Information("Finished Disposing clientAndTentacle"); } From eb2a6748646341af26e72dfaf4f91648876f3755 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Sat, 21 Sep 2024 09:34:16 +1200 Subject: [PATCH 17/30] And more logging - around the disposal call --- .../Support/TentacleBuilder.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs index 68eb7cc51..c940b9324 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs @@ -160,7 +160,11 @@ protected async Task StartTentacle( instanceName, HomeDirectory.DirectoryPath, applicationDirectory, - deleteInstanceFunction: ct => DeleteInstanceIgnoringFailure(installAsService, tentacleExe, instanceName, tempDirectory, logger, ct), + deleteInstanceFunction: ct => + { + log.Information("This is the deleteInstanceFunction"); + return DeleteInstanceIgnoringFailure(installAsService, tentacleExe, instanceName, tempDirectory, logger, ct); + }, runTentacleEnvironmentVariables, logger); @@ -173,7 +177,9 @@ protected async Task StartTentacle( { try { + log.Information("disposing tentacle after tentacle failed to start."); await runningTentacle.DisposeAsync(); + log.Information("finished disposing tentacle after tentacle failed to start."); } catch (Exception e) { @@ -406,12 +412,16 @@ protected async Task CreateInstance(string tentacleExe, string configFilePath, s internal async Task DeleteInstanceIgnoringFailure(bool runningAsService, string tentacleExe, string instanceName, TemporaryDirectory tmp, ILogger logger, CancellationToken cancellationToken) { + logger.Information($"Deleting instance in DeleteInstanceIgnoringFailure: {instanceName}"); + using (await GetConfigureAndStartTentacleLockIfRequired(logger, cancellationToken)) { if (runningAsService) { try { + logger.Information($"Deleting instance in DeleteInstanceIgnoringFailure: {instanceName}, trying to stop"); + await RunCommandOutOfProcess( tentacleExe, new[] { "service", $"--instance={instanceName}", "--stop" }, @@ -424,6 +434,7 @@ await RunCommandOutOfProcess( logger, cancellationToken); + logger.Information($"Deleting instance in DeleteInstanceIgnoringFailure: {instanceName}, trying to uninstall"); await RunCommandOutOfProcess( tentacleExe, new[] { "service", "--uninstall", $"--instance={instanceName}" }, @@ -457,7 +468,9 @@ await RunCommandOutOfProcess( internal async Task DeleteInstanceAsync(string tentacleExe, string instanceName, TemporaryDirectory tmp, ILogger logger, CancellationToken cancellationToken) { + logger.Information($"Deleting instance in DeleteInstanceAsync: {instanceName}"); await RunTentacleCommand(tentacleExe, new[] {"delete-instance", $"--instance={instanceName}"}, tmp, logger, cancellationToken); + logger.Information($"Deleted instance in DeleteInstanceAsync: {instanceName}"); } internal string InstanceNameGenerator() From 83e436a2753fe77d5c2485c606c625bf086a8172 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Sat, 21 Sep 2024 15:47:18 +1200 Subject: [PATCH 18/30] log deleteInstanceFunction after it has finished --- .../Support/TentacleBuilder.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs index c940b9324..d29308cae 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs @@ -160,10 +160,11 @@ protected async Task StartTentacle( instanceName, HomeDirectory.DirectoryPath, applicationDirectory, - deleteInstanceFunction: ct => + deleteInstanceFunction: async ct => { log.Information("This is the deleteInstanceFunction"); - return DeleteInstanceIgnoringFailure(installAsService, tentacleExe, instanceName, tempDirectory, logger, ct); + await DeleteInstanceIgnoringFailure(installAsService, tentacleExe, instanceName, tempDirectory, logger, ct); + log.Information("This is the deleteInstanceFunction after it has finished"); }, runTentacleEnvironmentVariables, logger); From 336a073927e8a175e7b85870d96c69e06554c584 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Sun, 22 Sep 2024 01:22:20 +1200 Subject: [PATCH 19/30] Log start() methods --- .../Octopus.Tentacle/Commands/DeregisterMachineCommand.cs | 2 ++ source/Octopus.Tentacle/Commands/DeregisterWorkerCommand.cs | 2 ++ source/Octopus.Tentacle/Commands/PollCommand.cs | 2 ++ .../Octopus.Tentacle/Commands/RegisterMachineCommandBase.cs | 2 ++ source/Octopus.Tentacle/Commands/RunAgentCommand.cs | 1 + source/Octopus.Tentacle/Commands/ServerCommsCommand.cs | 2 ++ .../Octopus.Tentacle/Commands/ShowConfigurationCommand.cs | 2 ++ source/Octopus.Tentacle/Commands/ShowThumbprintCommand.cs | 3 +++ source/Octopus.Tentacle/Commands/UpdateTrustCommand.cs | 3 +++ source/Octopus.Tentacle/Startup/AbstractCommand.cs | 6 ++++++ .../Octopus.Tentacle/Startup/ProxyConfigurationCommand.cs | 2 ++ 11 files changed, 27 insertions(+) diff --git a/source/Octopus.Tentacle/Commands/DeregisterMachineCommand.cs b/source/Octopus.Tentacle/Commands/DeregisterMachineCommand.cs index 7140ea7cd..1b98c5d8a 100644 --- a/source/Octopus.Tentacle/Commands/DeregisterMachineCommand.cs +++ b/source/Octopus.Tentacle/Commands/DeregisterMachineCommand.cs @@ -50,7 +50,9 @@ public DeregisterMachineCommand(Lazy configuration, protected override void Start() { base.Start(); + log.Info("Inside Deregister machine command start()"); StartAsync().GetAwaiter().GetResult(); + log.Info("Finished Deregister machine command start()"); } async Task StartAsync() diff --git a/source/Octopus.Tentacle/Commands/DeregisterWorkerCommand.cs b/source/Octopus.Tentacle/Commands/DeregisterWorkerCommand.cs index 4c17b6fc2..132612e1b 100644 --- a/source/Octopus.Tentacle/Commands/DeregisterWorkerCommand.cs +++ b/source/Octopus.Tentacle/Commands/DeregisterWorkerCommand.cs @@ -50,7 +50,9 @@ public DeregisterWorkerCommand(Lazy configuration, protected override void Start() { base.Start(); + log.Info("Inside DeregisterWorkerCommand Start()."); StartAsync().GetAwaiter().GetResult(); + log.Info("Finished DeregisterWorkerCommand Start()."); } async Task StartAsync() diff --git a/source/Octopus.Tentacle/Commands/PollCommand.cs b/source/Octopus.Tentacle/Commands/PollCommand.cs index 4ae556621..b78362e97 100644 --- a/source/Octopus.Tentacle/Commands/PollCommand.cs +++ b/source/Octopus.Tentacle/Commands/PollCommand.cs @@ -59,7 +59,9 @@ public PollCommand(Lazy configuration, protected override void Start() { base.Start(); + log.Info("Inside PollCommand Start()."); StartAsync().GetAwaiter().GetResult(); + log.Info("Finished PollCommand Start()."); } async Task StartAsync() diff --git a/source/Octopus.Tentacle/Commands/RegisterMachineCommandBase.cs b/source/Octopus.Tentacle/Commands/RegisterMachineCommandBase.cs index 906818ac3..46b8eb131 100644 --- a/source/Octopus.Tentacle/Commands/RegisterMachineCommandBase.cs +++ b/source/Octopus.Tentacle/Commands/RegisterMachineCommandBase.cs @@ -83,7 +83,9 @@ public RegisterMachineCommandBase(Lazy lazyRegisterM protected override void Start() { base.Start(); + log.Info("Inside RegisterMachineCommandBase Start()."); StartAsync().GetAwaiter().GetResult(); + log.Info("Finished RegisterMachineCommandBase Start()."); } async Task StartAsync() diff --git a/source/Octopus.Tentacle/Commands/RunAgentCommand.cs b/source/Octopus.Tentacle/Commands/RunAgentCommand.cs index 79151329d..1bd53671e 100644 --- a/source/Octopus.Tentacle/Commands/RunAgentCommand.cs +++ b/source/Octopus.Tentacle/Commands/RunAgentCommand.cs @@ -78,6 +78,7 @@ public RunAgentCommand( protected override void Start() { base.Start(); + log.Info("Inside RunAgentCommand Start()."); if (wait >= 20) { diff --git a/source/Octopus.Tentacle/Commands/ServerCommsCommand.cs b/source/Octopus.Tentacle/Commands/ServerCommsCommand.cs index 3937d41c8..7ee057c6d 100644 --- a/source/Octopus.Tentacle/Commands/ServerCommsCommand.cs +++ b/source/Octopus.Tentacle/Commands/ServerCommsCommand.cs @@ -35,6 +35,8 @@ public ServerCommsCommand(Lazy tentacleConfigura protected override void Start() { + log.Info("Inside ServerCommsCommand Start()."); + var distinctTrustedThumbprints = tentacleConfiguration.Value.TrustedOctopusThumbprints.Distinct().ToArray(); if (!distinctTrustedThumbprints.Any()) throw new ControlledFailureException("Before server communications can be modified, trust must be established with the configure command"); diff --git a/source/Octopus.Tentacle/Commands/ShowConfigurationCommand.cs b/source/Octopus.Tentacle/Commands/ShowConfigurationCommand.cs index 2f99f129e..9dd7e97e9 100644 --- a/source/Octopus.Tentacle/Commands/ShowConfigurationCommand.cs +++ b/source/Octopus.Tentacle/Commands/ShowConfigurationCommand.cs @@ -66,6 +66,7 @@ protected override void Start() async Task StartAsync() { base.Start(); + log.Info("Inside ShowConfigurationCommand Start()."); DictionaryKeyValueStore outputFile; @@ -81,6 +82,7 @@ async Task StartAsync() await CollectConfigurationSettings(outputFile); outputFile.Save(); + log.Info("Finished ShowConfigurationCommand Start()."); } async Task CollectConfigurationSettings(DictionaryKeyValueStore outputStore) diff --git a/source/Octopus.Tentacle/Commands/ShowThumbprintCommand.cs b/source/Octopus.Tentacle/Commands/ShowThumbprintCommand.cs index 59aab5c34..b4d30a0f9 100644 --- a/source/Octopus.Tentacle/Commands/ShowThumbprintCommand.cs +++ b/source/Octopus.Tentacle/Commands/ShowThumbprintCommand.cs @@ -37,6 +37,8 @@ public ShowThumbprintCommand(Lazy tentacleConfiguration, protected override void Start() { + log.Info("Inside ShowThumbPrintCommand Start()."); + base.Start(); if (!SupportedFormats.Contains(Format, StringComparer.OrdinalIgnoreCase)) @@ -57,6 +59,7 @@ protected override void Start() { Console.Write(content); } + log.Info("Finished ShowThumbPrintCommand Start()."); } } } \ No newline at end of file diff --git a/source/Octopus.Tentacle/Commands/UpdateTrustCommand.cs b/source/Octopus.Tentacle/Commands/UpdateTrustCommand.cs index 18255481f..1422449ca 100644 --- a/source/Octopus.Tentacle/Commands/UpdateTrustCommand.cs +++ b/source/Octopus.Tentacle/Commands/UpdateTrustCommand.cs @@ -38,6 +38,8 @@ protected void CheckArgs() protected override void Start() { + log.Info("Inside UpdateTrustCommand Start()."); + base.Start(); CheckArgs(); @@ -45,6 +47,7 @@ protected override void Start() tentacleConfiguration.Value.UpdateTrustedServerThumbprint(oldThumbprint, newThumbprint); VoteForRestart(); + log.Info("Finished UpdateTrustCommand Start()."); } } } diff --git a/source/Octopus.Tentacle/Startup/AbstractCommand.cs b/source/Octopus.Tentacle/Startup/AbstractCommand.cs index 8411cd762..fc56220e1 100644 --- a/source/Octopus.Tentacle/Startup/AbstractCommand.cs +++ b/source/Octopus.Tentacle/Startup/AbstractCommand.cs @@ -75,9 +75,15 @@ public virtual void Start(string[] commandLineArguments, ICommandRuntime command LogFileOnlyLogger.Info($"==== {GetType().Name} ===="); LogFileOnlyLogger.Info($"CommandLine: {string.Join(" ", Environment.GetCommandLineArgs())}"); + + LogFileOnlyLogger.Info($"Inside AbstractCommand, going to call Start()."); Start(); + + LogFileOnlyLogger.Info($"Inside AbstractCommand going to call Completed()."); + Completed(); + LogFileOnlyLogger.Info($"Inside AbstractCommand finished Completed()."); } void EnsureSensitiveParametersAreNotLoggedToLogFileOnlyLogger() diff --git a/source/Octopus.Tentacle/Startup/ProxyConfigurationCommand.cs b/source/Octopus.Tentacle/Startup/ProxyConfigurationCommand.cs index 75974ebe1..35e7dadd0 100644 --- a/source/Octopus.Tentacle/Startup/ProxyConfigurationCommand.cs +++ b/source/Octopus.Tentacle/Startup/ProxyConfigurationCommand.cs @@ -62,7 +62,9 @@ public ProxyConfigurationCommand(Lazy proxyConfigur protected override void Start() { + LogFileOnlyLogger.Info($"Inside ProxyConfigurationCommand.Start()"); base.Start(); + LogFileOnlyLogger.Info($"After ProxyConfigurationCommand.Start()"); foreach (var operation in operations) operation(); From a4e4145796edca1a5f91bf232bb178e0edfe77ab Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Sun, 22 Sep 2024 10:59:28 +1200 Subject: [PATCH 20/30] Put back some using statements --- .../TentacleCommandLineTests.cs | 8 ++++---- .../Configuration/Instances/ApplicationInstanceManager.cs | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index 0f19fe33f..f132ce12a 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -351,7 +351,7 @@ public async Task InvalidInstance(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ShowThumbprintCommandText(TentacleConfigurationTestCase tc) { - var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -369,7 +369,7 @@ public async Task ShowThumbprintCommandText(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ShowThumbprintCommandJson(TentacleConfigurationTestCase tc) { - var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -422,7 +422,7 @@ public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ListInstancesCommandJson(TentacleConfigurationTestCase tc) { - var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (_, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -536,7 +536,7 @@ to text. [NonParallelizable] public async Task ShowConfigurationCommand(TentacleConfigurationTestCase tc) { - var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (_, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, diff --git a/source/Octopus.Tentacle/Configuration/Instances/ApplicationInstanceManager.cs b/source/Octopus.Tentacle/Configuration/Instances/ApplicationInstanceManager.cs index ae5482e0f..1a47c5db2 100644 --- a/source/Octopus.Tentacle/Configuration/Instances/ApplicationInstanceManager.cs +++ b/source/Octopus.Tentacle/Configuration/Instances/ApplicationInstanceManager.cs @@ -46,7 +46,9 @@ public void CreateInstance(string instanceName, string configurationFile, string public void DeleteInstance(string instanceName) { + log.Info($"Inside Delete instance of ApplicationInstanceManager: {instanceName}"); instanceStore.DeleteInstance(instanceName); + log.Info($"Finished Delete instance of ApplicationInstanceManager: {instanceName}"); } void RegisterInstanceInIndex(string instanceName, string configurationFile) From a7ba08382bd8d14cc1aff4a0ebfb596900a534fc Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Sun, 22 Sep 2024 18:54:27 +1200 Subject: [PATCH 21/30] Log out all arguments of the tentacle calls --- .../TentacleCommandLineTests.cs | 22 ++++++++++++++----- .../Startup/AbstractStandardCommand.cs | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index f132ce12a..51e4e53f5 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -739,26 +739,36 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati environmentVariablesToRunTentacleWith.Add(EnvironmentVariables.TentacleMachineConfigurationHomeDirectory, tempDirectory.DirectoryPath); } - if (arguments is not null && arguments.Length == 2 && arguments[0] == "list-instances") + if (arguments is not null) { - Logger.Information("Listing instances: going to call TentacleExeFinder.FindTentacleExe"); + Logger.Information($"Going to call Cli.Wrap ..."); } var tentacleExe = TentacleExeFinder.FindTentacleExe(tentacleConfigurationTestCase.TentacleRuntime); var output = new StringBuilder(); var errorOut = new StringBuilder(); - if (arguments is not null && arguments.Length == 2 && arguments[0] == "list-instances") + if (arguments is not null) { - Logger.Information("Listing instances: going to call await RetryHelper.RetryAsync"); + Logger.Information($"Going to call Cli.Wrap ... with exe: {tentacleExe}"); + foreach (var argument in arguments) + { + Logger.Information($" ... with argument: {argument}"); + } + Logger.Information($"----"); } var result = await RetryHelper.RetryAsync( () => { - if (arguments is not null && arguments.Length == 2 && arguments[0] == "list-instances") + if (arguments is not null) { - Logger.Information($"Listing instances: going to call Cli.Wrap with exe: {tentacleExe} ..."); + Logger.Information($"Going to call Cli.Wrap with exe: {tentacleExe}"); + foreach (var argument in arguments) + { + Logger.Information($" ... with argument: {argument}"); + } + Logger.Information($"----"); } try diff --git a/source/Octopus.Tentacle/Startup/AbstractStandardCommand.cs b/source/Octopus.Tentacle/Startup/AbstractStandardCommand.cs index 3a44c5cf9..b905a2c3a 100644 --- a/source/Octopus.Tentacle/Startup/AbstractStandardCommand.cs +++ b/source/Octopus.Tentacle/Startup/AbstractStandardCommand.cs @@ -33,10 +33,12 @@ protected AbstractStandardCommand(IApplicationInstanceSelector instanceSelector, protected override void Start() { + SystemLog.Info("Inside AbstractStandardCommand Start()"); // These kinds of commands depend on being able to load the correct instance // We need to assert the current instance can be loaded otherwise the rest of the command won't work as expected // NOTE: This method should throw a ControlledFailureException with the most appropriate message inside it var unused = instanceSelector.Current.InstanceName; + SystemLog.Info("Finished AbstractStandardCommand Start()"); } protected override void Completed() From 8064978fe3e1d88a833b7662b16ce3cd850a4391 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Sun, 22 Sep 2024 21:33:29 +1200 Subject: [PATCH 22/30] await the async call --- .../Support/TentacleBuilder.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs index d29308cae..7ce185062 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/TentacleBuilder.cs @@ -516,19 +516,26 @@ async Task ProcessLogs(string s, CancellationToken ct) try { logger.Information("Going to try to run Cli.Wrap(targetFilePath) with retries..."); - var commandResult = await RetryHelper.RetryAsync( - () => + var commandResult = await RetryHelper.RetryAsync(async () => { logger.Information("Going to try to run Cli.Wrap(targetFilePath)"); - var res = Cli.Wrap(targetFilePath) + foreach (var a in args) + { + logger.Information($"with arg: {a}"); + } + + var command = Cli.Wrap(targetFilePath) .WithArguments(args) .WithEnvironmentVariables(environmentVariables) .WithWorkingDirectory(tmp.DirectoryPath) .WithStandardOutputPipe(PipeTarget.ToDelegate(ProcessLogs)) - .WithStandardErrorPipe(PipeTarget.ToDelegate(ProcessLogs)) - .ExecuteAsync(cancellationToken); + .WithStandardErrorPipe(PipeTarget.ToDelegate(ProcessLogs)); + + logger.Information("ok, calling now)"); + var res = await command.ExecuteAsync(cancellationToken); logger.Information("Cli.Wrap(targetFilePath) returned"); - logger.Information($"Exit code: {res.Task.Result.ExitCode}"); + + logger.Information($"Exit code: {res.ExitCode}"); return res; }); From f9bb94c47e4c15301738b49ce977689606fad6aa Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Mon, 23 Sep 2024 03:08:00 +1200 Subject: [PATCH 23/30] Separate dispose calls - await each call --- .../Support/ClientAndTentacle.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs b/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs index 9d4e9a523..8fe0e880b 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs @@ -69,10 +69,18 @@ public async ValueTask DisposeAsync() logger.Information("Starting DisposeAsync"); logger.Information("Starting RunningTentacle.DisposeAsync and Server.Dispose and PortForwarder.Dispose"); + + logger.Information("Starting PortForwarder?.Dispose()"); var portForwarderTask = Task.Run(() => PortForwarder?.Dispose()); + await Task.WhenAll(portForwarderTask); + + logger.Information("Starting RunningTentacle.DisposeAsync()"); var runningTentacleTask = RunningTentacle.DisposeAsync(); + await Task.WhenAll(runningTentacleTask.AsTask()); + + logger.Information("Starting Server.DisposeAsync()"); var serverTask = Server.DisposeAsync(); - await Task.WhenAll(runningTentacleTask.AsTask(), serverTask.AsTask(), portForwarderTask); + await Task.WhenAll(serverTask.AsTask()); logger.Information("Starting TentacleClient.Dispose"); TentacleClient.Dispose(); From 93cd0d197cb67e53cfef36036e2fe2a131cbde82 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Mon, 23 Sep 2024 08:36:51 +1200 Subject: [PATCH 24/30] Swap, to make sure that tentacle dispose is the last thing that happens when failing --- .../Support/ClientAndTentacle.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs b/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs index 8fe0e880b..27c46da1d 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs @@ -74,13 +74,13 @@ public async ValueTask DisposeAsync() var portForwarderTask = Task.Run(() => PortForwarder?.Dispose()); await Task.WhenAll(portForwarderTask); - logger.Information("Starting RunningTentacle.DisposeAsync()"); - var runningTentacleTask = RunningTentacle.DisposeAsync(); - await Task.WhenAll(runningTentacleTask.AsTask()); - logger.Information("Starting Server.DisposeAsync()"); var serverTask = Server.DisposeAsync(); await Task.WhenAll(serverTask.AsTask()); + + logger.Information("Starting RunningTentacle.DisposeAsync()"); + var runningTentacleTask = RunningTentacle.DisposeAsync(); + await Task.WhenAll(runningTentacleTask.AsTask()); logger.Information("Starting TentacleClient.Dispose"); TentacleClient.Dispose(); From 1c6bfbfddc15b7b4892e4e3bdae315afe78b3586 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Mon, 23 Sep 2024 09:07:25 +1200 Subject: [PATCH 25/30] Comment out RunningTentacle.DisposeAsync during client and tentacle dispose --- .../Support/ClientAndTentacle.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs b/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs index 27c46da1d..2094bf005 100644 --- a/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs +++ b/source/Octopus.Tentacle.Tests.Integration/Support/ClientAndTentacle.cs @@ -79,8 +79,8 @@ public async ValueTask DisposeAsync() await Task.WhenAll(serverTask.AsTask()); logger.Information("Starting RunningTentacle.DisposeAsync()"); - var runningTentacleTask = RunningTentacle.DisposeAsync(); - await Task.WhenAll(runningTentacleTask.AsTask()); + // var runningTentacleTask = RunningTentacle.DisposeAsync(); + // await Task.WhenAll(runningTentacleTask.AsTask()); logger.Information("Starting TentacleClient.Dispose"); TentacleClient.Dispose(); From cb73f5da026b765197925332c5321e89e2af7898 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Mon, 23 Sep 2024 15:15:34 +1200 Subject: [PATCH 26/30] Await and log --- .../TentacleCommandLineTests.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index 51e4e53f5..ea560838e 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -758,8 +758,7 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati Logger.Information($"----"); } - var result = await RetryHelper.RetryAsync( - () => + var result = await RetryHelper.RetryAsync(async () => { if (arguments is not null) { @@ -773,13 +772,17 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati try { - return Cli.Wrap(tentacleExe) + var command = Cli.Wrap(tentacleExe) .WithArguments(arguments) .WithValidation(CommandResultValidation.None) .WithStandardOutputPipe(PipeTarget.ToStringBuilder(output)) .WithStandardErrorPipe(PipeTarget.ToStringBuilder(errorOut)) - .WithEnvironmentVariables(environmentVariablesToRunTentacleWith) - .ExecuteAsync(CancellationToken); + .WithEnvironmentVariables(environmentVariablesToRunTentacleWith); + + Logger.Information($"Going to call Cli.Wrap with exe - in try"); + var result = await command.ExecuteAsync(CancellationToken); + Logger.Information($"Finished calling Cli.Wrap with exe - in try"); + return result; } catch (Exception e) { From c702502547b91e008ee089a117a3cee0391b7802 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Mon, 23 Sep 2024 15:38:28 +1200 Subject: [PATCH 27/30] Remove all await using statements from TentacleCommandLineTests.cs --- .../TentacleCommandLineTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index ea560838e..b069431c5 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -351,7 +351,7 @@ public async Task InvalidInstance(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ShowThumbprintCommandText(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -369,7 +369,7 @@ public async Task ShowThumbprintCommandText(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ShowThumbprintCommandJson(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -422,7 +422,7 @@ public async Task ListInstancesCommandText(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ListInstancesCommandJson(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (_, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -442,7 +442,7 @@ public async Task ListInstancesCommandJson(TentacleConfigurationTestCase tc) [NonParallelizable] public async Task ShouldLogStartupDiagnosticsToInstanceLogFileOnly(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var startingLogText = clientAndTentacle.RunningTentacle.ReadAllLogFileText(); @@ -536,7 +536,7 @@ to text. [NonParallelizable] public async Task ShowConfigurationCommand(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (_, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -587,7 +587,7 @@ await RunCommandAndAssertExitsWithSuccessExitCode( [NonParallelizable] public async Task ShowConfigurationCommandLooksSensibleToHumans(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var (_, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode( tc, @@ -679,7 +679,7 @@ public async Task ShowConfigurationCommandLooksSensibleToHumans(TentacleConfigur [NonParallelizable] public async Task WatchdogCreateAndDeleteCommand(TentacleConfigurationTestCase tc) { - await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); + var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken); await clientAndTentacle.RunningTentacle.Stop(CancellationToken); var create = await RunCommandAndAssertExitsWithSuccessExitCode( tc, From 7c658792c8ca837c48d4bc0c9061fe559035594f Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Mon, 23 Sep 2024 15:42:46 +1200 Subject: [PATCH 28/30] Remove all using statements from previously failing tests --- .../ClientScriptExecutionRetriesTimeout.cs | 16 ++++++++-------- .../FileTransferServiceTests.cs | 4 ++-- .../ScriptServiceTests.cs | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionRetriesTimeout.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionRetriesTimeout.cs index edfb8893e..941c2d7b6 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionRetriesTimeout.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionRetriesTimeout.cs @@ -29,7 +29,7 @@ public class ClientScriptExecutionRetriesTimeout : IntegrationTest [TentacleConfigurations(additionalParameterTypes: new object[] {typeof(RpcCallStage)})] public async Task WhenRpcRetriesTimeOut_DuringGetCapabilities_TheRpcCallIsCancelled(TentacleConfigurationTestCase tentacleConfigurationTestCase, RpcCallStage rpcCallStage) { - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(TimeSpan.FromSeconds(15)) .WithPortForwarderDataLogging() @@ -101,7 +101,7 @@ public async Task WhenGetCapabilitiesFails_AndTakesLongerThanTheRetryDuration_Th { var retryDuration = TimeSpan.FromSeconds(15); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(retryDuration) .WithPortForwarderDataLogging() @@ -146,7 +146,7 @@ public async Task WhenGetCapabilitiesFails_AndTakesLongerThanTheRetryDuration_Th [TentacleConfigurations(additionalParameterTypes: new object[] { typeof(RpcCallStage)})] public async Task WhenRpcRetriesTimeOut_DuringStartScript_TheRpcCallIsCancelled(TentacleConfigurationTestCase tentacleConfigurationTestCase, RpcCallStage rpcCallStage) { - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(TimeSpan.FromSeconds(15)) .WithPortForwarderDataLogging() @@ -221,7 +221,7 @@ public async Task WhenStartScriptFails_AndTakesLongerThanTheRetryDuration_TheCal { var retryDuration = TimeSpan.FromSeconds(15); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(retryDuration) .WithPortForwarderDataLogging() @@ -266,7 +266,7 @@ public async Task WhenStartScriptFails_AndTakesLongerThanTheRetryDuration_TheCal [TentacleConfigurations(additionalParameterTypes: new object[] { typeof(RpcCallStage)})] public async Task WhenRpcRetriesTimeOut_DuringGetStatus_TheRpcCallIsCancelled(TentacleConfigurationTestCase tentacleConfigurationTestCase, RpcCallStage rpcCallStage) { - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(TimeSpan.FromSeconds(15)) .WithPortForwarderDataLogging() @@ -344,7 +344,7 @@ public async Task WhenGetStatusFails_AndTakesLongerThanTheRetryDuration_TheCallI { var retryDuration = TimeSpan.FromSeconds(15); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(retryDuration) .WithPortForwarderDataLogging() @@ -391,7 +391,7 @@ public async Task WhenGetStatusFails_AndTakesLongerThanTheRetryDuration_TheCallI [TentacleConfigurations(additionalParameterTypes: new object[] {typeof(RpcCallStage)})] public async Task WhenRpcRetriesTimeOut_DuringCancelScript_TheRpcCallIsCancelled(TentacleConfigurationTestCase tentacleConfigurationTestCase, RpcCallStage rpcCallStage) { - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(TimeSpan.FromSeconds(15)) .WithPortForwarderDataLogging() @@ -483,7 +483,7 @@ public async Task WhenCancelScriptFails_AndTakesLongerThanTheRetryDuration_TheCa { var retryDuration = TimeSpan.FromSeconds(15); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(retryDuration) .WithPortForwarderDataLogging() diff --git a/source/Octopus.Tentacle.Tests.Integration/FileTransferServiceTests.cs b/source/Octopus.Tentacle.Tests.Integration/FileTransferServiceTests.cs index bce59c8cc..794428619 100644 --- a/source/Octopus.Tentacle.Tests.Integration/FileTransferServiceTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/FileTransferServiceTests.cs @@ -19,7 +19,7 @@ public async Task UploadFileSuccessfully(TentacleConfigurationTestCase tentacleC { using var fileToUpload = new RandomTemporaryFileBuilder().Build(); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); + var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); var dataStream = new DataStream( fileToUpload.File.Length, @@ -46,7 +46,7 @@ public async Task DownloadFileSuccessfully(TentacleConfigurationTestCase tentacl { using var fileToDownload = new RandomTemporaryFileBuilder().Build(); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); + var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); var downloadedData = await clientAndTentacle.TentacleClient.FileTransferService.DownloadFileAsync( fileToDownload.File.FullName, diff --git a/source/Octopus.Tentacle.Tests.Integration/ScriptServiceTests.cs b/source/Octopus.Tentacle.Tests.Integration/ScriptServiceTests.cs index b855caeb9..42c8e2213 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ScriptServiceTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ScriptServiceTests.cs @@ -32,7 +32,7 @@ echo The answer is $theAnswer sleep 3 echo This is the end of the script"; - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); + var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); var scriptStatusResponse = await new ScriptExecutionOrchestrator(clientAndTentacle.TentacleClient, Logger) .ExecuteScript(windowsScript, nixScript, CancellationToken); @@ -61,7 +61,7 @@ sleep 3 exit 1 echo This is the end of the script"; - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); + var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); var scriptStatusResponse = await new ScriptExecutionOrchestrator(clientAndTentacle.TentacleClient, Logger) .ExecuteScript(windowsScript, nixScript, CancellationToken); @@ -86,7 +86,7 @@ public async Task CancelScript(TentacleConfigurationTestCase tentacleConfigurati ping 127.0.0.1 -c 100 echo This is the end of the script"; - await using var clientAndTentacle = await tentacleConfigurationTestCase + var clientAndTentacle = await tentacleConfigurationTestCase .CreateLegacyBuilder() .WithHalibutLoggingLevel(LogLevel.Trace) .Build(CancellationToken); From 032dae97257782b7686e6babc09ad75421585333 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Mon, 23 Sep 2024 17:55:50 +1200 Subject: [PATCH 29/30] Remove more using statements --- .../CapabilitiesServiceV2Test.cs | 6 +++--- .../ClientFileTransferRetriesTimeout.cs | 8 ++++---- ...sfersAreNotRetriedWhenRetriesAreDisabled.cs | 4 ++-- ...TransfersAreRetriedWhenRetriesAreEnabled.cs | 4 ++-- .../ClientGathersRpcCallMetrics.cs | 12 ++++++------ .../ClientScriptExecutionAdditionalScripts.cs | 2 +- ...tionCanBeCancelledWhenRetriesAreDisabled.cs | 8 ++++---- ...utionCanBeCancelledWhenRetriesAreEnabled.cs | 12 ++++++------ ...riptExecutionCanRecoverFromNetworkIssues.cs | 10 +++++----- .../ClientScriptExecutionIsolationMutex.cs | 4 ++-- ...ClientScriptExecutionScriptArgumentsWork.cs | 2 +- .../ClientScriptExecutionScriptFilesAreSent.cs | 2 +- ...eNonV1IsNotRetriedWhenRetriesAreDisabled.cs | 10 +++++----- ...riptExecutionScriptServiceV1IsNotRetried.cs | 8 ++++---- ...ScriptExecutionWorksWithMultipleVersions.cs | 2 +- ...torObservesScriptObserverBackoffStrategy.cs | 2 +- .../MachineConfigurationHomeDirectoryTests.cs | 2 +- .../ScriptServiceV2IntegrationTest.cs | 10 +++++----- .../TentacleClientObserver.cs | 8 ++++---- .../TentacleCommandLineTests.cs | 18 +++++++++--------- .../WorkspaceCleanerTests.cs | 12 ++++++------ 21 files changed, 73 insertions(+), 73 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/CapabilitiesServiceV2Test.cs b/source/Octopus.Tentacle.Tests.Integration/CapabilitiesServiceV2Test.cs index 6f9b7300a..6ad3a0218 100644 --- a/source/Octopus.Tentacle.Tests.Integration/CapabilitiesServiceV2Test.cs +++ b/source/Octopus.Tentacle.Tests.Integration/CapabilitiesServiceV2Test.cs @@ -24,7 +24,7 @@ public async Task CapabilitiesFromAnOlderTentacleWhichHasNoCapabilitiesService_W { Version? version = tentacleConfigurationTestCase.Version; - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); + var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); var capabilities = (await clientAndTentacle.TentacleClient.CapabilitiesServiceV2.GetCapabilitiesAsync(new(CancellationToken))).SupportedCapabilities; @@ -48,7 +48,7 @@ public async Task CapabilitiesServiceDoesNotReturnKubernetesScriptServiceForNonK { var version = tentacleConfigurationTestCase.Version; - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); + var clientAndTentacle = await tentacleConfigurationTestCase.CreateLegacyBuilder().Build(CancellationToken); var capabilities = (await clientAndTentacle.TentacleClient.CapabilitiesServiceV2.GetCapabilitiesAsync(new(CancellationToken))).SupportedCapabilities; @@ -75,7 +75,7 @@ public async Task CapabilitiesResponseShouldBeCached(TentacleConfigurationTestCa var capabilitiesResponses = new List(); var resumePortForwarder = false; - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarder(out var portForwarder) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .DecorateCapabilitiesServiceV2With(d => d diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientFileTransferRetriesTimeout.cs b/source/Octopus.Tentacle.Tests.Integration/ClientFileTransferRetriesTimeout.cs index d2e5784d1..f86a47ca7 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientFileTransferRetriesTimeout.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientFileTransferRetriesTimeout.cs @@ -34,7 +34,7 @@ public class ClientFileTransferRetriesTimeout : IntegrationTest public async Task WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled(TentacleConfigurationTestCase tentacleConfigurationTestCase, bool stopPortForwarderAfterFirstCall) { PortForwarder portForwarder = null!; - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(TimeSpan.FromSeconds(15)) .WithPortForwarderDataLogging() @@ -103,7 +103,7 @@ public async Task WhenUploadFileFails_AndTakesLongerThanTheRetryDuration_TheCall { var retryDuration = TimeSpan.FromSeconds(15); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(retryDuration) .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) @@ -145,7 +145,7 @@ public async Task WhenUploadFileFails_AndTakesLongerThanTheRetryDuration_TheCall public async Task WhenRpcRetriesTimeOut_DuringDownloadFile_TheRpcCallIsCancelled(TentacleConfigurationTestCase tentacleConfigurationTestCase, bool stopPortForwarderAfterFirstCall) { PortForwarder portForwarder = null!; - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(TimeSpan.FromSeconds(15)) .WithPortForwarderDataLogging() @@ -215,7 +215,7 @@ public async Task WhenDownloadFileFails_AndTakesLongerThanTheRetryDuration_TheCa { var retryDuration = TimeSpan.FromSeconds(15); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() // Set a short retry duration so we cancel fairly quickly .WithRetryDuration(retryDuration) .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientFileTransfersAreNotRetriedWhenRetriesAreDisabled.cs b/source/Octopus.Tentacle.Tests.Integration/ClientFileTransfersAreNotRetriedWhenRetriesAreDisabled.cs index b8ebd1261..27345681d 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientFileTransfersAreNotRetriedWhenRetriesAreDisabled.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientFileTransfersAreNotRetriedWhenRetriesAreDisabled.cs @@ -20,7 +20,7 @@ public class ClientFileTransfersAreNotRetriedWhenRetriesAreDisabled : Integratio [TentacleConfigurations(testCommonVersions: true, scriptServiceToTest: ScriptServiceVersionToTest.None)] public async Task FailedUploadsAreNotRetriedAndFail(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithRetriesDisabled() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) @@ -58,7 +58,7 @@ public async Task FailedUploadsAreNotRetriedAndFail(TentacleConfigurationTestCas [TentacleConfigurations(testCommonVersions: true, scriptServiceToTest: ScriptServiceVersionToTest.None)] public async Task FailedDownloadsAreNotRetriedAndFail(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithRetriesDisabled() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientFileTransfersAreRetriedWhenRetriesAreEnabled.cs b/source/Octopus.Tentacle.Tests.Integration/ClientFileTransfersAreRetriedWhenRetriesAreEnabled.cs index df282f0fd..d47525fc9 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientFileTransfersAreRetriedWhenRetriesAreEnabled.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientFileTransfersAreRetriedWhenRetriesAreEnabled.cs @@ -22,7 +22,7 @@ public class ClientFileTransfersAreRetriedWhenRetriesAreEnabled : IntegrationTes [TentacleConfigurations(testCommonVersions: true, scriptServiceToTest: ScriptServiceVersionToTest.None)] public async Task FailedUploadsAreRetriedAndIsEventuallySuccessful(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) .WithTcpConnectionUtilities(Logger, out var tcpConnectionUtilities) @@ -65,7 +65,7 @@ public async Task FailedUploadsAreRetriedAndIsEventuallySuccessful(TentacleConfi [TentacleConfigurations(testCommonVersions: true, scriptServiceToTest: ScriptServiceVersionToTest.None)] public async Task FailedDownloadsAreRetriedAndIsEventuallySuccessful(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) .WithTcpConnectionUtilities(Logger, out var tcpConnectionUtilities) diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientGathersRpcCallMetrics.cs b/source/Octopus.Tentacle.Tests.Integration/ClientGathersRpcCallMetrics.cs index 5975f8ded..4da6327f0 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientGathersRpcCallMetrics.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientGathersRpcCallMetrics.cs @@ -26,7 +26,7 @@ public async Task ExecuteScriptShouldGatherMetrics_WhenSucceeds(TentacleConfigur { // Arrange var tentacleClientObserver = new TestTentacleClientObserver(); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .Build(CancellationToken); @@ -62,7 +62,7 @@ public async Task ExecuteScriptShouldGatherMetrics_WhenFails(TentacleConfigurati // Arrange var tentacleClientObserver = new TestTentacleClientObserver(); var exception = new HalibutClientException("Error"); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .WithRetryDuration(TimeSpan.FromSeconds(1)) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() @@ -94,7 +94,7 @@ public async Task UploadFileShouldGatherMetrics_WhenSucceeds(TentacleConfigurati { // Arrange var tentacleClientObserver = new TestTentacleClientObserver(); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .Build(CancellationToken); @@ -121,7 +121,7 @@ public async Task UploadFileShouldGatherMetrics_WhenFails(TentacleConfigurationT // Arrange var tentacleClientObserver = new TestTentacleClientObserver(); var exception = new HalibutClientException("Error"); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .WithRetryDuration(TimeSpan.FromSeconds(1)) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() @@ -151,7 +151,7 @@ public async Task DownloadFileShouldGatherMetrics_WhenSucceeds(TentacleConfigura { // Arrange var tentacleClientObserver = new TestTentacleClientObserver(); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .Build(CancellationToken); @@ -179,7 +179,7 @@ public async Task DownloadFileShouldGatherMetrics_WhenFails(TentacleConfiguratio // Arrange var tentacleClientObserver = new TestTentacleClientObserver(); var exception = new HalibutClientException("Error"); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .WithRetryDuration(TimeSpan.FromSeconds(1)) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionAdditionalScripts.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionAdditionalScripts.cs index 24e6ea8ca..e8613f73b 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionAdditionalScripts.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionAdditionalScripts.cs @@ -21,7 +21,7 @@ public async Task AdditionalScriptsWork(TentacleConfigurationTestCase tentacleCo using var tmp = new TemporaryDirectory(); var path = Path.Combine(tmp.DirectoryPath, "file"); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .Build(CancellationToken); var scriptBuilder = new ScriptBuilder() diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanBeCancelledWhenRetriesAreDisabled.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanBeCancelledWhenRetriesAreDisabled.cs index 91aedbf7e..115498f93 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanBeCancelledWhenRetriesAreDisabled.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanBeCancelledWhenRetriesAreDisabled.cs @@ -41,7 +41,7 @@ public async Task DuringGetCapabilities_ScriptExecutionCanBeCancelled(TentacleCo var hasPausedOrStoppedPortForwarder = false; var ensureCancellationOccursDuringAnRpcCall = new SemaphoreSlim(0, 1); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPendingRequestQueueFactory(new CancellationObservingPendingRequestQueueFactory()) // Partially works around disconnected polling tentacles take work from the queue .WithServiceEndpointModifier(point => point.TryAndConnectForALongTime()) .WithRetriesDisabled() @@ -112,7 +112,7 @@ public async Task DuringStartScript_ScriptExecutionCanBeCancelled(TentacleConfig var hasPausedOrStoppedPortForwarder = false; var ensureCancellationOccursDuringAnRpcCall = new SemaphoreSlim(0, 1); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPendingRequestQueueFactory(new CancellationObservingPendingRequestQueueFactory()) // Partially works around disconnected polling tentacles take work from the queue .WithServiceEndpointModifier(point => point.TryAndConnectForALongTime()) .WithRetriesDisabled() @@ -208,7 +208,7 @@ public async Task DuringGetStatus_ScriptExecutionCanBeCancelled(TentacleConfigur var hasPausedOrStoppedPortForwarder = false; var ensureCancellationOccursDuringAnRpcCall = new SemaphoreSlim(0, 1); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPendingRequestQueueFactory(new CancellationObservingPendingRequestQueueFactory()) // Partially works around disconnected polling tentacles take work from the queue .WithServiceEndpointModifier(point => point.TryAndConnectForALongTime()) .WithRetriesDisabled() @@ -292,7 +292,7 @@ public async Task DuringCompleteScript_ScriptExecutionCanBeCancelled(TentacleCon var rpcCallHasStarted = new Reference(false); var hasPausedOrStoppedPortForwarder = false; - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPendingRequestQueueFactory(new CancellationObservingPendingRequestQueueFactory()) // Partially works around disconnected polling tentacles take work from the queue .WithServiceEndpointModifier(point => point.TryAndConnectForALongTime()) .WithRetriesDisabled() diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanBeCancelledWhenRetriesAreEnabled.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanBeCancelledWhenRetriesAreEnabled.cs index 693adbd07..ef033ea37 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanBeCancelledWhenRetriesAreEnabled.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanBeCancelledWhenRetriesAreEnabled.cs @@ -43,7 +43,7 @@ public async Task DuringGetCapabilities_ScriptExecutionCanBeCancelled(TentacleCo var hasPausedOrStoppedPortForwarder = false; var ensureCancellationOccursDuringAnRpcCall = new SemaphoreSlim(0, 1); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPendingRequestQueueFactory(new CancellationObservingPendingRequestQueueFactory()) // Partially works around disconnected polling tentacles take work from the queue .WithServiceEndpointModifier(point => { @@ -142,7 +142,7 @@ public async Task DuringStartScript_ScriptExecutionCanBeCancelled(TentacleConfig var hasPausedOrStoppedPortForwarder = false; var ensureCancellationOccursDuringAnRpcCall = new SemaphoreSlim(0, 1); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPendingRequestQueueFactory(new CancellationObservingPendingRequestQueueFactory()) // Partially works around disconnected polling tentacles take work from the queue .WithServiceEndpointModifier(point => { @@ -274,7 +274,7 @@ public async Task DuringStartScript_ForPollingTentacle_ThatIsRetryingTheRpc_AndC var started = false; var cancelExecutionCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithRetryDuration(TimeSpan.FromHours(1)) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder().RecordMethodUsages(tentacleConfigurationTestCase, out var scriptServiceRecordedUsages).Build()) .WithPendingRequestQueueFactory(new CancelWhenRequestQueuedPendingRequestQueueFactory( @@ -342,7 +342,7 @@ public async Task DuringStartScript_ForListeningTentacle_ThatIsRetryingTheRpc_An var cancelExecutionCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithRetryDuration(TimeSpan.FromHours(1)) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder().RecordMethodUsages(tentacleConfigurationTestCase, out var scriptServiceRecordedUsages).Build()) .WithHalibutTimeoutsAndLimits(halibutTimeoutsAndLimits) @@ -409,7 +409,7 @@ public async Task DuringGetStatus_ScriptExecutionCanBeCancelled(TentacleConfigur var hasPausedOrStoppedPortForwarder = false; var ensureCancellationOccursDuringAnRpcCall = new SemaphoreSlim(0, 1); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPendingRequestQueueFactory(new CancellationObservingPendingRequestQueueFactory()) // Partially works around disconnected polling tentacles take work from the queue .WithServiceEndpointModifier(point => { @@ -520,7 +520,7 @@ public async Task DuringCompleteScript_ScriptExecutionCanBeCancelled(TentacleCon var rpcCallHasStarted = new Reference(false); var hasPausedOrStoppedPortForwarder = false; - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPendingRequestQueueFactory(new CancellationObservingPendingRequestQueueFactory()) // Partially works around disconnected polling tentacles take work from the queue .WithRetryDuration(TimeSpan.FromHours(1)) .WithPortForwarderDataLogging() diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanRecoverFromNetworkIssues.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanRecoverFromNetworkIssues.cs index 4f0afb1b6..4f886322c 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanRecoverFromNetworkIssues.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionCanRecoverFromNetworkIssues.cs @@ -28,7 +28,7 @@ public class ClientScriptExecutionCanRecoverFromNetworkIssues : IntegrationTest [TentacleConfigurations] public async Task WhenANetworkFailureOccurs_DuringStartScript_TheClientIsAbleToSuccessfullyCompleteTheScript(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarder() .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(tentacleConfigurationTestCase, out var recordedUsages) @@ -82,7 +82,7 @@ await Wait.For(() => File.Exists(scriptHasStartFile), [TentacleConfigurations] public async Task WhenANetworkFailureOccurs_DuringGetStatus_TheClientIsAbleToSuccessfullyCompleteTheScript(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() @@ -142,7 +142,7 @@ public async Task WhenANetworkFailureOccurs_DuringCompleteScript_TheClientIsAble { bool completeScriptWasCalled = false; PortForwarder? portForwarder = null; - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarderDataLogging() .WithServiceEndpointModifier(serviceEndpoint => { @@ -192,7 +192,7 @@ public async Task WhenANetworkFailureOccurs_DuringCancelScript_TheClientIsAbleTo using var tmp = new TemporaryDirectory(); var scriptIsRunningFlag = Path.Combine(tmp.DirectoryPath, "scriptisrunning"); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() @@ -265,7 +265,7 @@ await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, [TentacleConfigurations] public async Task WhenANetworkFailureOccurs_DuringGetCapabilities_TheClientIsAbleToSuccessfullyCompleteTheScript(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) .WithTcpConnectionUtilities(Logger, out var tcpConnectionUtilities) diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionIsolationMutex.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionIsolationMutex.cs index baf50164c..5378ac94e 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionIsolationMutex.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionIsolationMutex.cs @@ -21,7 +21,7 @@ public class ClientScriptExecutionIsolationMutex : IntegrationTest [TentacleConfigurations(testScriptIsolationLevelVersions: true, additionalParameterTypes: new object[] { typeof(ScriptIsolationLevel)})] public async Task ScriptIsolationMutexFull_EnsuresTwoDifferentScriptsDontRunAtTheSameTime(TentacleConfigurationTestCase tentacleConfigurationTestCase, ScriptIsolationLevel levelOfSecondScript) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(tentacleConfigurationTestCase, out var recordedUsages) .Build()) @@ -85,7 +85,7 @@ await Wait.For(() => recordedUsages.For(nameof(IAsyncClientScriptServiceV2.Start [TentacleConfigurations(testScriptIsolationLevelVersions: true, additionalParameterTypes: new object[] {typeof(ScriptsInParallelTestCases)})] public async Task ScriptIsolationMutexFull_IsOnlyExclusiveWhenFullAndWhenTheMutexNameIsTheSame(TentacleConfigurationTestCase tentacleConfigurationTestCase, ScriptsInParallelTestCase scriptsInParallelTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder().Build(CancellationToken); + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder().Build(CancellationToken); var firstScriptStartFile = Path.Combine(clientTentacle.TemporaryDirectory.DirectoryPath, "firstScriptStartFile"); var firstScriptWaitFile = Path.Combine(clientTentacle.TemporaryDirectory.DirectoryPath, "firstScriptWaitFile"); diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptArgumentsWork.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptArgumentsWork.cs index cdce531e7..c5e1524a1 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptArgumentsWork.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptArgumentsWork.cs @@ -19,7 +19,7 @@ public class ClientScriptExecutionScriptArgumentsWork : IntegrationTest [TentacleConfigurations(testCommonVersions: true)] public async Task ArgumentsArePassedToTheScript(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder().Build(CancellationToken); + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder().Build(CancellationToken); var startScriptCommand = new TestExecuteShellScriptCommandBuilder() .SetScriptBody(new ScriptBuilder().PrintArguments()) diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptFilesAreSent.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptFilesAreSent.cs index 181ceeef0..9d0b72947 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptFilesAreSent.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptFilesAreSent.cs @@ -18,7 +18,7 @@ public class ClientScriptExecutionScriptFilesAreSent : IntegrationTest [TentacleConfigurations(testCommonVersions: true)] public async Task ScriptFilesAreSent(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder().Build(CancellationToken); + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder().Build(CancellationToken); var startScriptCommand = new TestExecuteShellScriptCommandBuilder() .SetScriptBody(new ScriptBuilder().PrintFileContents("foo.txt")) diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptServiceNonV1IsNotRetriedWhenRetriesAreDisabled.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptServiceNonV1IsNotRetriedWhenRetriesAreDisabled.cs index 2986460e6..c78f1c30c 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptServiceNonV1IsNotRetriedWhenRetriesAreDisabled.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptServiceNonV1IsNotRetriedWhenRetriesAreDisabled.cs @@ -24,7 +24,7 @@ public class ClientScriptExecutionScriptServiceNonV1IsNotRetriedWhenRetriesAreDi [TentacleConfigurations] public async Task WhenNetworkFailureOccurs_DuringGetCapabilities_TheCallIsNotRetried(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithRetriesDisabled() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) @@ -80,7 +80,7 @@ public async Task WhenNetworkFailureOccurs_DuringGetCapabilities_TheCallIsNotRet [TentacleConfigurations] public async Task WhenANetworkFailureOccurs_DuringStartScript_TheCallIsNotRetried(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithRetriesDisabled() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) @@ -132,7 +132,7 @@ public async Task WhenANetworkFailureOccurs_DuringStartScript_TheCallIsNotRetrie [TentacleConfigurations] public async Task WhenANetworkFailureOccurs_DuringGetStatus_TheCallIsNotRetried(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithRetriesDisabled() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) @@ -189,7 +189,7 @@ public async Task WhenANetworkFailureOccurs_DuringGetStatus_TheCallIsNotRetried( public async Task WhenANetworkFailureOccurs_DuringCancelScript_TheCallIsNotRetried(TentacleConfigurationTestCase tentacleConfigurationTestCase) { CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithRetriesDisabled() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) @@ -251,7 +251,7 @@ public async Task WhenANetworkFailureOccurs_DuringCancelScript_TheCallIsNotRetri [TentacleConfigurations] public async Task WhenANetworkFailureOccurs_DuringCompleteScript_TheCallIsNotRetried(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithRetriesDisabled() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptServiceV1IsNotRetried.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptServiceV1IsNotRetried.cs index 4d117c972..944774bd1 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptServiceV1IsNotRetried.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionScriptServiceV1IsNotRetried.cs @@ -23,7 +23,7 @@ public class ClientScriptExecutionScriptServiceV1IsNotRetried : IntegrationTest [TentacleConfigurations(testNoCapabilitiesServiceVersions: true)] public async Task WhenANetworkFailureOccurs_DuringStartScript_WithATentacleThatOnlySupportsV1ScriptService_TheCallIsNotRetried(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) .WithRetryDuration(TimeSpan.FromMinutes(4)) @@ -82,7 +82,7 @@ public async Task WhenANetworkFailureOccurs_DuringStartScript_WithATentacleThatO public async Task WhenANetworkFailureOccurs_DuringGetStatus_WithATentacleThatOnlySupportsV1ScriptService_TheCallIsNotRetried(TentacleConfigurationTestCase tentacleConfigurationTestCase) { ScriptStatusRequest? scriptStatusRequest = null; - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) .WithRetryDuration(TimeSpan.FromMinutes(4)) @@ -144,7 +144,7 @@ public async Task WhenANetworkFailureOccurs_DuringCancelScript_WithATentacleThat { ScriptStatusRequest? scriptStatusRequest = null; CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) .WithRetryDuration(TimeSpan.FromMinutes(4)) .WithPortForwarderDataLogging() @@ -212,7 +212,7 @@ await Wait.For( [TentacleConfigurations(testNoCapabilitiesServiceVersions: true)] public async Task WhenANetworkFailureOccurs_DuringCompleteScript_WithATentacleThatOnlySupportsV1ScriptService_TheCallIsNotRetried(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithPortForwarderDataLogging() .WithResponseMessageTcpKiller(out var responseMessageTcpKiller) .WithRetryDuration(TimeSpan.FromMinutes(4)) diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionWorksWithMultipleVersions.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionWorksWithMultipleVersions.cs index a28ed3bde..1d4b27e2e 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionWorksWithMultipleVersions.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionWorksWithMultipleVersions.cs @@ -17,7 +17,7 @@ public class ClientScriptExecutionWorksWithMultipleVersions : IntegrationTest [TentacleConfigurations(testCommonVersions: true)] public async Task CanRunScript(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder().Build(CancellationToken); + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder().Build(CancellationToken); var startScriptCommand = new TestExecuteShellScriptCommandBuilder() .SetScriptBody(new ScriptBuilder() diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutorObservesScriptObserverBackoffStrategy.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutorObservesScriptObserverBackoffStrategy.cs index b61e5aeb0..15d0d9b8d 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutorObservesScriptObserverBackoffStrategy.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutorObservesScriptObserverBackoffStrategy.cs @@ -19,7 +19,7 @@ public class ClientScriptExecutorObservesScriptObserverBackoffStrategy : Integra [TentacleConfigurations(testCommonVersions: true)] public async Task TheScriptObserverBackoffShouldBeRespected(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithScriptObserverBackoffStrategy(new FuncScriptObserverBackoffStrategy(iters => TimeSpan.FromSeconds(20))) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(tentacleConfigurationTestCase, out var recordedUsages) diff --git a/source/Octopus.Tentacle.Tests.Integration/MachineConfigurationHomeDirectoryTests.cs b/source/Octopus.Tentacle.Tests.Integration/MachineConfigurationHomeDirectoryTests.cs index aabcde625..1bd8381b6 100644 --- a/source/Octopus.Tentacle.Tests.Integration/MachineConfigurationHomeDirectoryTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/MachineConfigurationHomeDirectoryTests.cs @@ -37,7 +37,7 @@ public async Task ShouldUseTheDefaultMachineConfigurationHomeDirectoryWhenACusto public async Task ShouldUseTheCustomMachineConfigurationHomeDirectoryWhenACustomLocationIsProvided(TentacleConfigurationTestCase tentacleConfigurationTestCase) { using var tempDirectory = new TemporaryDirectory(); - await using var clientAndTentacle = await tentacleConfigurationTestCase + var clientAndTentacle = await tentacleConfigurationTestCase .CreateBuilder() .UseDefaultMachineConfigurationHomeDirectory() .WithTentacle(x => diff --git a/source/Octopus.Tentacle.Tests.Integration/ScriptServiceV2IntegrationTest.cs b/source/Octopus.Tentacle.Tests.Integration/ScriptServiceV2IntegrationTest.cs index 4fb62eb72..6bd7b5334 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ScriptServiceV2IntegrationTest.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ScriptServiceV2IntegrationTest.cs @@ -22,7 +22,7 @@ public class ScriptServiceV2IntegrationTest : IntegrationTest [TentacleConfigurations] public async Task CanRunScript(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(out var methodUsages) .Build()) @@ -54,7 +54,7 @@ public async Task CanRunScript(TentacleConfigurationTestCase tentacleConfigurati [TentacleConfigurations] public async Task DelayInStartScriptSavesNetworkCalls(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(out var recordedUsages) .Build()) @@ -87,7 +87,7 @@ public async Task DelayInStartScriptSavesNetworkCalls(TentacleConfigurationTestC [TentacleConfigurations] public async Task WhenTentacleRestartsWhileRunningAScript_TheExitCodeShouldBe_UnknownResultExitCode(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(out var recordedUsages) .Build()) @@ -134,7 +134,7 @@ await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, Cancellati [TentacleConfigurations] public async Task WhenALongRunningScriptIsCancelled_TheScriptShouldStop(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(out var recordedUsages) .Build()) @@ -184,7 +184,7 @@ public async Task WhenOnCompleteTakesLongerThan_OnCancellationAbandonCompleteScr { bool calledWithNonCancelledCT = false; - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(tentacleConfigurationTestCase, out var recordedUsages) .DecorateScriptServiceV2With(b => b diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleClientObserver.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleClientObserver.cs index bbc2955a9..b02584d43 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleClientObserver.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleClientObserver.cs @@ -25,7 +25,7 @@ public async Task AnErrorDuringTheCallbackTo_ExecuteScriptCompleted_ShouldNotThr // Arrange var tentacleClientObserver = new BrokenTentacleClientObserver(errorOnExecuteScriptCompleted: true); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(tentacleConfigurationTestCase, out var recordedUsages) @@ -51,7 +51,7 @@ public async Task AnErrorDuringTheCallbackTo_RpcCallComplete_ShouldNotThrowOrSto // Arrange var tentacleClientObserver = new BrokenTentacleClientObserver(errorOnRpcCallCompleted: true); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() .RecordMethodUsages(tentacleConfigurationTestCase, out var recordedUsages) @@ -77,7 +77,7 @@ public async Task AnErrorDuringTheCallbackTo_UploadFileCompleted_ShouldNotThrowA // Arrange var tentacleClientObserver = new BrokenTentacleClientObserver(errorOnUploadFileCompleted: true); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .Build(CancellationToken); @@ -94,7 +94,7 @@ public async Task AnErrorDuringTheCallbackTo_DownloadFileCompleted_ShouldNotThro // Arrange var tentacleClientObserver = new BrokenTentacleClientObserver(errorOnDownloadFileCompleted: true); - await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacleClientObserver(tentacleClientObserver) .Build(CancellationToken); diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs index b069431c5..24dd48692 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs @@ -748,15 +748,15 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati var output = new StringBuilder(); var errorOut = new StringBuilder(); - if (arguments is not null) - { - Logger.Information($"Going to call Cli.Wrap ... with exe: {tentacleExe}"); - foreach (var argument in arguments) - { - Logger.Information($" ... with argument: {argument}"); - } - Logger.Information($"----"); - } + // if (arguments is not null) + // { + // Logger.Information($"Going to call Cli.Wrap ... with exe: {tentacleExe}"); + // foreach (var argument in arguments) + // { + // Logger.Information($" ... with argument: {argument}"); + // } + // Logger.Information($"----"); + // } var result = await RetryHelper.RetryAsync(async () => { diff --git a/source/Octopus.Tentacle.Tests.Integration/WorkspaceCleanerTests.cs b/source/Octopus.Tentacle.Tests.Integration/WorkspaceCleanerTests.cs index 8eb83f876..9d61b8d72 100644 --- a/source/Octopus.Tentacle.Tests.Integration/WorkspaceCleanerTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/WorkspaceCleanerTests.cs @@ -30,7 +30,7 @@ public async Task WhenScriptServiceIsRunningAndWritesLogFile_ThenWorkspaceIsNotD var startScriptCommand = new TestExecuteShellScriptCommandBuilder().SetScriptBody(b => b.WaitForFileToExist(waitBeforeCompletingScriptFile)).Build(); var startScriptWorkspaceDirectory = GetWorkspaceDirectoryPath(existingHomeDirectory.DirectoryPath, startScriptCommand.ScriptTicket.TaskId); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacle(b => { b.WithHomeDirectory(existingHomeDirectory) @@ -72,7 +72,7 @@ public async Task WhenScriptServiceIsRunningAndWritesBootstrapScript_ThenWorkspa var startScriptCommand = new TestExecuteShellScriptCommandBuilder().SetScriptBody(b => b.WaitForFileToExist(waitBeforeCompletingScriptFile)).Build(); var startScriptWorkspaceDirectory = GetWorkspaceDirectoryPath(existingHomeDirectory.DirectoryPath, startScriptCommand.ScriptTicket.TaskId); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacle(b => { b.WithHomeDirectory(existingHomeDirectory) @@ -110,7 +110,7 @@ public async Task WhenCompleteScriptIsNotCalled_ThenWorkspaceShouldGetDeletedWhe var startScriptCommand = new TestExecuteShellScriptCommandBuilder().SetScriptBody(b => b.Print("Hello")).Build(); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacle(b => { b.WithWorkspaceCleaningSettings(cleanerDelay, deleteWorkspacesOlderThan); @@ -163,7 +163,7 @@ public async Task WhenTentacleStarts_WithWorkspacesOlderThanThreshold_ThenWorksp var existingWorkspaceDirectoryWithLogFile = GivenExistingWorkspaceExists(existingHomeDirectory); await File.WriteAllTextAsync(ScriptWorkspace.GetLogFilePath(existingWorkspaceDirectoryWithLogFile), "Existing log file"); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacle(b => { b.WithHomeDirectory(existingHomeDirectory) @@ -191,7 +191,7 @@ public async Task WhenTentacleStarts_WithWorkspacesOlderThanThreshold_ThenWorksp var existingWorkspaceDirectoryWithLogFile = GivenExistingWorkspaceExists(existingHomeDirectory); await File.WriteAllTextAsync(GetBootstrapScriptFilePath(existingWorkspaceDirectoryWithLogFile), "Existing bootstrap file"); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacle(b => { b.WithHomeDirectory(existingHomeDirectory) @@ -218,7 +218,7 @@ public async Task WhenTentacleStarts_WithWorkspaceYoungerThanThreshold_ThenWorks var existingWorkspaceDirectory = GivenExistingWorkspaceExists(existingHomeDirectory); await File.WriteAllTextAsync(ScriptWorkspace.GetLogFilePath(existingWorkspaceDirectory), "Existing log file"); - await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() + var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder() .WithTentacle(b => { b.WithHomeDirectory(existingHomeDirectory) From 530798410f875f5606dd903d159a629825c4d129 Mon Sep 17 00:00:00 2001 From: Samdanae Imran Date: Mon, 23 Sep 2024 17:58:33 +1200 Subject: [PATCH 30/30] A few more removals --- .../MachineConfigurationHomeDirectoryTests.cs | 21 +++--- .../TentacleStartupAndShutdownTests.cs | 65 +++++++++---------- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/source/Octopus.Tentacle.Tests.Integration/MachineConfigurationHomeDirectoryTests.cs b/source/Octopus.Tentacle.Tests.Integration/MachineConfigurationHomeDirectoryTests.cs index 1bd8381b6..01577ab2f 100644 --- a/source/Octopus.Tentacle.Tests.Integration/MachineConfigurationHomeDirectoryTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/MachineConfigurationHomeDirectoryTests.cs @@ -16,20 +16,17 @@ public class MachineConfigurationHomeDirectoryTests : IntegrationTest [TentacleConfigurations(scriptServiceToTest: ScriptServiceVersionToTest.None)] public async Task ShouldUseTheDefaultMachineConfigurationHomeDirectoryWhenACustomLocationIsNotProvided(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using (var clientAndTentacle = await tentacleConfigurationTestCase - .CreateBuilder() - .UseDefaultMachineConfigurationHomeDirectory() - .Build(CancellationToken)) - { - - var defaultMachineConfigurationHomeDirectory = PlatformDetection.IsRunningOnWindows ? - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Octopus", "Tentacle", "Instances") : - "/etc/octopus/Tentacle/Instances"; + var clientAndTentacle = await tentacleConfigurationTestCase + .CreateBuilder() + .UseDefaultMachineConfigurationHomeDirectory() + .Build(CancellationToken); + var defaultMachineConfigurationHomeDirectory = PlatformDetection.IsRunningOnWindows ? + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Octopus", "Tentacle", "Instances") : + "/etc/octopus/Tentacle/Instances"; - var expectedInstanceConfigurationFilePath = new FileInfo(Path.Combine(defaultMachineConfigurationHomeDirectory, $"{clientAndTentacle.RunningTentacle.InstanceName}.config")); + var expectedInstanceConfigurationFilePath = new FileInfo(Path.Combine(defaultMachineConfigurationHomeDirectory, $"{clientAndTentacle.RunningTentacle.InstanceName}.config")); - expectedInstanceConfigurationFilePath.Exists.Should().BeTrue($"Instance configuration file should exist {expectedInstanceConfigurationFilePath.FullName}"); - } + expectedInstanceConfigurationFilePath.Exists.Should().BeTrue($"Instance configuration file should exist {expectedInstanceConfigurationFilePath.FullName}"); } [Test] diff --git a/source/Octopus.Tentacle.Tests.Integration/TentacleStartupAndShutdownTests.cs b/source/Octopus.Tentacle.Tests.Integration/TentacleStartupAndShutdownTests.cs index 7cd833c4f..0b7777725 100644 --- a/source/Octopus.Tentacle.Tests.Integration/TentacleStartupAndShutdownTests.cs +++ b/source/Octopus.Tentacle.Tests.Integration/TentacleStartupAndShutdownTests.cs @@ -23,50 +23,47 @@ public class TentacleStartupAndShutdownTests : IntegrationTest [RequiresSudoOnLinux] public async Task WhenRunningTentacleAsAServiceItShouldBeAbleToRestartItself(TentacleConfigurationTestCase tentacleConfigurationTestCase) { - await using (var clientAndTentacle = await tentacleConfigurationTestCase - .CreateBuilder() - .InstallAsAService() - .Build(CancellationToken)) - { - - var startScriptCommand = new TestExecuteShellScriptCommandBuilder() - .SetScriptBodyForCurrentOs( -$@"cd ""{clientAndTentacle.RunningTentacle.TentacleExe.DirectoryName}"" + var clientAndTentacle = await tentacleConfigurationTestCase + .CreateBuilder() + .InstallAsAService() + .Build(CancellationToken); + var startScriptCommand = new TestExecuteShellScriptCommandBuilder() + .SetScriptBodyForCurrentOs( + $@"cd ""{clientAndTentacle.RunningTentacle.TentacleExe.DirectoryName}"" .\Tentacle.exe service --instance {clientAndTentacle.RunningTentacle.InstanceName} --stop --start", -$@"#!/bin/sh + $@"#!/bin/sh cd ""{clientAndTentacle.RunningTentacle.TentacleExe.DirectoryName}"" ./Tentacle service --instance {clientAndTentacle.RunningTentacle.InstanceName} --stop --start") - .Build(); + .Build(); - (Client.Scripts.Models.ScriptExecutionResult ScriptExecutionResult, List ProcessOutput) result; + (Client.Scripts.Models.ScriptExecutionResult ScriptExecutionResult, List ProcessOutput) result; - try - { - result = await clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken); - } - catch (ServiceInvocationHalibutClientException ex) - { - Logger.Information(ex, "ServiceInvocationHalibutClientException thrown while Tentacle was restarting itself. This can be ignored for the purpose of this test."); + try + { + result = await clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken); + } + catch (ServiceInvocationHalibutClientException ex) + { + Logger.Information(ex, "ServiceInvocationHalibutClientException thrown while Tentacle was restarting itself. This can be ignored for the purpose of this test."); - // Making Tentacle restart itself can cause internal errors with Script Service - // Execute the script again to get the final result and logs. This will not rerun the script. - result = await clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken); - } + // Making Tentacle restart itself can cause internal errors with Script Service + // Execute the script again to get the final result and logs. This will not rerun the script. + result = await clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken); + } - result.LogExecuteScriptOutput(Logger); + result.LogExecuteScriptOutput(Logger); - result.ProcessOutput.Any(x => x.Text.Contains("Stopping service")).Should().BeTrue("Stopping service should be logged"); - result.ScriptExecutionResult.State.Should().Be(ProcessState.Complete); + result.ProcessOutput.Any(x => x.Text.Contains("Stopping service")).Should().BeTrue("Stopping service should be logged"); + result.ScriptExecutionResult.State.Should().Be(ProcessState.Complete); - startScriptCommand = new TestExecuteShellScriptCommandBuilder() - .SetScriptBody(new ScriptBuilder().Print("Running...")) - .Build(); + startScriptCommand = new TestExecuteShellScriptCommandBuilder() + .SetScriptBody(new ScriptBuilder().Print("Running...")) + .Build(); - result = await clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken); - result.ProcessOutput.Any(x => x.Text.Contains("Running...")).Should().BeTrue("Running... should be logged"); - result.ScriptExecutionResult.ExitCode.Should().Be(0); - result.ScriptExecutionResult.State.Should().Be(ProcessState.Complete); - } + result = await clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken); + result.ProcessOutput.Any(x => x.Text.Contains("Running...")).Should().BeTrue("Running... should be logged"); + result.ScriptExecutionResult.ExitCode.Should().Be(0); + result.ScriptExecutionResult.State.Should().Be(ProcessState.Complete); } } }