From 3dd609a60d6f182a04bb491a4cabcc30aa2c76d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Sun, 2 Mar 2025 10:12:29 +0100 Subject: [PATCH 1/9] Wait indefinite for the setup to complete to minmize the risk for a corrupted database --- .../Setup/InstanceSetup.cs | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs index a97f456465..77160d2382 100644 --- a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs +++ b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs @@ -46,25 +46,16 @@ static void Run(string installPath, string exeName, string instanceName, bool sk processStartupInfo.EnvironmentVariables.Add("INSTANCE_NAME", instanceName); - var p = Process.Start(processStartupInfo); - if (p != null) - { - var error = p.StandardError.ReadToEnd(); - p.WaitForExit((int)TimeSpan.FromMinutes(1).TotalMilliseconds); - if (!p.HasExited) - { - p.Kill(); - throw new TimeoutException($"Timed out waiting for {exeName} to perform setup. This usually indicates a configuration error."); - } + var p = Process.Start(processStartupInfo) ?? throw new Exception($"Attempt to launch {exeName} failed."); - if (p.ExitCode != 0) - { - throw new Exception($"{exeName} threw an error when performing setup. This typically indicates a configuration error. The error output from {exeName} was:\r\n {error}"); - } - } - else + var error = p.StandardError.ReadToEnd(); + + // we will wait "forever" since killing the setup is dangerous and can lead to the database being in an invalid state + p.WaitForExit(); + + if (p.ExitCode != 0) { - throw new Exception($"Attempt to launch {exeName} failed."); + throw new Exception($"{exeName} threw an error when performing setup. This typically indicates a configuration error. The error output from {exeName} was:\r\n {error}"); } } } \ No newline at end of file From 28fe88dc20ae73f4550ed874743f0d8261d87c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Wed, 5 Mar 2025 08:18:32 +0100 Subject: [PATCH 2/9] Add setup process fake --- src/ServiceControl.sln | 15 +++++++++++++++ ...erviceControlInstaller.Engine.UnitTests.csproj | 1 + .../Setup/SetupInstanceTests.cs | 11 +++++++++++ .../Setup/InstanceSetup.cs | 2 +- src/SetupProcessFake/Program.cs | 3 +++ src/SetupProcessFake/SetupProcessFake.csproj | 10 ++++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs create mode 100644 src/SetupProcessFake/Program.cs create mode 100644 src/SetupProcessFake/SetupProcessFake.csproj diff --git a/src/ServiceControl.sln b/src/ServiceControl.sln index 04eb5829f0..7c57134866 100644 --- a/src/ServiceControl.sln +++ b/src/ServiceControl.sln @@ -183,6 +183,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceControl.Transports.P EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceControl.Transports.PostgreSql.Tests", "ServiceControl.Transports.PostgreSql.Tests\ServiceControl.Transports.PostgreSql.Tests.csproj", "{18DBEEF5-42EE-4C1D-A05B-87B21C067D53}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetupProcessFake", "SetupProcessFake\SetupProcessFake.csproj", "{36D53BA0-C1E1-4D74-81AE-C33B40C84958}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -997,6 +999,18 @@ Global {18DBEEF5-42EE-4C1D-A05B-87B21C067D53}.Release|x64.Build.0 = Release|Any CPU {18DBEEF5-42EE-4C1D-A05B-87B21C067D53}.Release|x86.ActiveCfg = Release|Any CPU {18DBEEF5-42EE-4C1D-A05B-87B21C067D53}.Release|x86.Build.0 = Release|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Debug|x64.ActiveCfg = Debug|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Debug|x64.Build.0 = Debug|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Debug|x86.ActiveCfg = Debug|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Debug|x86.Build.0 = Debug|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Release|Any CPU.Build.0 = Release|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Release|x64.ActiveCfg = Release|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Release|x64.Build.0 = Release|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Release|x86.ActiveCfg = Release|Any CPU + {36D53BA0-C1E1-4D74-81AE-C33B40C84958}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1080,6 +1094,7 @@ Global {51F5504E-E915-40EC-B96E-CA700A57982C} = {80C55E70-4B7A-4EF2-BB9E-C42F8DB0495D} {448CBDCF-718D-4BC7-8F7C-099C9A362B59} = {A21A1A89-0B07-4E87-8E3C-41D9C280DCB8} {18DBEEF5-42EE-4C1D-A05B-87B21C067D53} = {E0E45F22-35E3-4AD8-B09E-EFEA5A2F18EE} + {36D53BA0-C1E1-4D74-81AE-C33B40C84958} = {927A078A-E271-4878-A153-86D71AE510E2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3B9E5B72-F580-465A-A22C-2D2148AF4EB4} diff --git a/src/ServiceControlInstaller.Engine.UnitTests/ServiceControlInstaller.Engine.UnitTests.csproj b/src/ServiceControlInstaller.Engine.UnitTests/ServiceControlInstaller.Engine.UnitTests.csproj index e1bb0f3f47..1648f3739a 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/ServiceControlInstaller.Engine.UnitTests.csproj +++ b/src/ServiceControlInstaller.Engine.UnitTests/ServiceControlInstaller.Engine.UnitTests.csproj @@ -6,6 +6,7 @@ + diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs new file mode 100644 index 0000000000..a89687697f --- /dev/null +++ b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs @@ -0,0 +1,11 @@ +namespace ServiceControlInstaller.Engine.UnitTests.Setup; + +using Engine.Setup; +using NUnit.Framework; + +[TestFixture] +public class SetupInstanceTests +{ + [Test] + public void Should_not_throw_on_0_exit_code() => Assert.DoesNotThrow(() => InstanceSetup.Run("", "", "test", false)); +} \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs index 77160d2382..89ca0e6a01 100644 --- a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs +++ b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs @@ -25,7 +25,7 @@ public static void Run(IMonitoringInstance instance) => instance.Name, instance.SkipQueueCreation); - static void Run(string installPath, string exeName, string instanceName, bool skipQueueCreation) + internal static void Run(string installPath, string exeName, string instanceName, bool skipQueueCreation) { var args = $"--setup"; diff --git a/src/SetupProcessFake/Program.cs b/src/SetupProcessFake/Program.cs new file mode 100644 index 0000000000..139ec4e747 --- /dev/null +++ b/src/SetupProcessFake/Program.cs @@ -0,0 +1,3 @@ +// See https://aka.ms/new-console-template for more information + +Console.WriteLine("Hello, World!"); diff --git a/src/SetupProcessFake/SetupProcessFake.csproj b/src/SetupProcessFake/SetupProcessFake.csproj new file mode 100644 index 0000000000..2f4fc77656 --- /dev/null +++ b/src/SetupProcessFake/SetupProcessFake.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + From 5b3233f1d74ad9f2779e71f5a070c7847d7e57d6 Mon Sep 17 00:00:00 2001 From: Andreas Ohlund Date: Wed, 5 Mar 2025 09:14:28 +0100 Subject: [PATCH 3/9] Fix test --- .../Setup/SetupInstanceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs index a89687697f..dbc8608a0d 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs @@ -7,5 +7,5 @@ public class SetupInstanceTests { [Test] - public void Should_not_throw_on_0_exit_code() => Assert.DoesNotThrow(() => InstanceSetup.Run("", "", "test", false)); + public void Should_not_throw_on_0_exit_code() => Assert.DoesNotThrow(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", false)); } \ No newline at end of file From 2b89752b9fe593ad49116ae90560a3e9b3af94ae Mon Sep 17 00:00:00 2001 From: Andreas Ohlund Date: Wed, 5 Mar 2025 09:40:43 +0100 Subject: [PATCH 4/9] Check exceptions --- .../Setup/SetupInstanceTests.cs | 11 ++++++++++- .../Setup/InstanceSetup.cs | 7 ++++++- src/SetupProcessFake/Program.cs | 7 ++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs index dbc8608a0d..e1a0c8e086 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs @@ -1,5 +1,6 @@ namespace ServiceControlInstaller.Engine.UnitTests.Setup; +using System; using Engine.Setup; using NUnit.Framework; @@ -7,5 +8,13 @@ public class SetupInstanceTests { [Test] - public void Should_not_throw_on_0_exit_code() => Assert.DoesNotThrow(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", false)); + public void Should_not_throw_on_0_exit_code() => Assert.DoesNotThrow(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "")); + + [Test] + public void Should_capture_and_rethrow_failures() + { + var ex = Assert.Throws(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "fail")); + + Assert.That(ex.Message, Does.Contain("Fake exception")); + } } \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs index 89ca0e6a01..e7ae67db76 100644 --- a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs +++ b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs @@ -25,7 +25,7 @@ public static void Run(IMonitoringInstance instance) => instance.Name, instance.SkipQueueCreation); - internal static void Run(string installPath, string exeName, string instanceName, bool skipQueueCreation) + static void Run(string installPath, string exeName, string instanceName, bool skipQueueCreation) { var args = $"--setup"; @@ -34,6 +34,11 @@ internal static void Run(string installPath, string exeName, string instanceName args += " --skip-queue-creation"; } + Run(installPath, exeName, instanceName, args); + } + + internal static void Run(string installPath, string exeName, string instanceName, string args) + { var processStartupInfo = new ProcessStartInfo { CreateNoWindow = true, diff --git a/src/SetupProcessFake/Program.cs b/src/SetupProcessFake/Program.cs index 139ec4e747..9bbcf25dcd 100644 --- a/src/SetupProcessFake/Program.cs +++ b/src/SetupProcessFake/Program.cs @@ -1,3 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -Console.WriteLine("Hello, World!"); +if (args.Any(a => a == "fail")) +{ + throw new Exception("Fake exception"); +} \ No newline at end of file From 8a802cd23c381f169761dc6663a4886c5df56fbb Mon Sep 17 00:00:00 2001 From: Andreas Ohlund Date: Wed, 5 Mar 2025 09:57:51 +0100 Subject: [PATCH 5/9] Add test for non zero return codes --- .../Setup/SetupInstanceTests.cs | 8 ++++++++ .../Setup/InstanceSetup.cs | 2 +- src/SetupProcessFake/Program.cs | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs index e1a0c8e086..223dbfc63b 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs @@ -17,4 +17,12 @@ public void Should_capture_and_rethrow_failures() Assert.That(ex.Message, Does.Contain("Fake exception")); } + + [Test] + public void Should_capture_and_rethrow_non_zero_exit_codes() + { + var ex = Assert.Throws(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "non-zero-exit-code")); + + Assert.That(ex.Message, Does.Contain("returned a non-zero exit code: 3")); + } } \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs index e7ae67db76..823cd6a009 100644 --- a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs +++ b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs @@ -60,7 +60,7 @@ internal static void Run(string installPath, string exeName, string instanceName if (p.ExitCode != 0) { - throw new Exception($"{exeName} threw an error when performing setup. This typically indicates a configuration error. The error output from {exeName} was:\r\n {error}"); + throw new Exception($"{exeName} returned a non-zero exit code: {p.ExitCode}. This typically indicates a configuration error. The error output was:\r\n {error}"); } } } \ No newline at end of file diff --git a/src/SetupProcessFake/Program.cs b/src/SetupProcessFake/Program.cs index 9bbcf25dcd..56fea1b5fb 100644 --- a/src/SetupProcessFake/Program.cs +++ b/src/SetupProcessFake/Program.cs @@ -1,4 +1,11 @@ if (args.Any(a => a == "fail")) { throw new Exception("Fake exception"); -} \ No newline at end of file +} + +if (args.Any(a => a == "non-zero-exit-code")) +{ + return 3; +} + +return 0; From 1ca66de6f842eb8cbc0dafc2ba2a328f0e8cd7a9 Mon Sep 17 00:00:00 2001 From: Andreas Ohlund Date: Wed, 5 Mar 2025 10:36:01 +0100 Subject: [PATCH 6/9] Add test to make sure do not kill the setup --- .../Setup/SetupInstanceTests.cs | 18 +++++++++++++++--- .../Setup/InstanceSetup.cs | 18 ++++++++++-------- src/SetupProcessFake/GlobalSuppressions.cs | 8 ++++++++ src/SetupProcessFake/Program.cs | 5 +++++ 4 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 src/SetupProcessFake/GlobalSuppressions.cs diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs index 223dbfc63b..0c8c38de8c 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs @@ -1,6 +1,7 @@ namespace ServiceControlInstaller.Engine.UnitTests.Setup; using System; +using System.Threading; using Engine.Setup; using NUnit.Framework; @@ -8,12 +9,12 @@ public class SetupInstanceTests { [Test] - public void Should_not_throw_on_0_exit_code() => Assert.DoesNotThrow(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "")); + public void Should_not_throw_on_0_exit_code() => Assert.DoesNotThrow(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "", Timeout.Infinite)); [Test] public void Should_capture_and_rethrow_failures() { - var ex = Assert.Throws(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "fail")); + var ex = Assert.Throws(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "fail", Timeout.Infinite)); Assert.That(ex.Message, Does.Contain("Fake exception")); } @@ -21,8 +22,19 @@ public void Should_capture_and_rethrow_failures() [Test] public void Should_capture_and_rethrow_non_zero_exit_codes() { - var ex = Assert.Throws(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "non-zero-exit-code")); + var ex = Assert.Throws(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "non-zero-exit-code", Timeout.Infinite)); Assert.That(ex.Message, Does.Contain("returned a non-zero exit code: 3")); } + + [Test] + public void Should_not_kill_the_process_if_wait_time_is_execeeded() + { + var process = InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "delay", 10); + + Assert.That(process.HasExited, Is.False); + + process.Kill(); + process.WaitForExit(); + } } \ No newline at end of file diff --git a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs index 823cd6a009..59adf7e8be 100644 --- a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs +++ b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Threading; using Instances; static class InstanceSetup @@ -34,10 +35,10 @@ static void Run(string installPath, string exeName, string instanceName, bool sk args += " --skip-queue-creation"; } - Run(installPath, exeName, instanceName, args); + Run(installPath, exeName, instanceName, args, Timeout.Infinite); } - internal static void Run(string installPath, string exeName, string instanceName, string args) + internal static Process Run(string installPath, string exeName, string instanceName, string args, int timeout) { var processStartupInfo = new ProcessStartInfo { @@ -53,14 +54,15 @@ internal static void Run(string installPath, string exeName, string instanceName var p = Process.Start(processStartupInfo) ?? throw new Exception($"Attempt to launch {exeName} failed."); - var error = p.StandardError.ReadToEnd(); - - // we will wait "forever" since killing the setup is dangerous and can lead to the database being in an invalid state - p.WaitForExit(); + p.WaitForExit(timeout); - if (p.ExitCode != 0) + if (!p.HasExited || p.ExitCode == 0) { - throw new Exception($"{exeName} returned a non-zero exit code: {p.ExitCode}. This typically indicates a configuration error. The error output was:\r\n {error}"); + return p; } + + var error = p.StandardError.ReadToEnd(); + + throw new Exception($"{exeName} returned a non-zero exit code: {p.ExitCode}. This typically indicates a configuration error. The error output was:\r\n {error}"); } } \ No newline at end of file diff --git a/src/SetupProcessFake/GlobalSuppressions.cs b/src/SetupProcessFake/GlobalSuppressions.cs new file mode 100644 index 0000000000..f16e81bb45 --- /dev/null +++ b/src/SetupProcessFake/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "TestProject")] diff --git a/src/SetupProcessFake/Program.cs b/src/SetupProcessFake/Program.cs index 56fea1b5fb..c274a37796 100644 --- a/src/SetupProcessFake/Program.cs +++ b/src/SetupProcessFake/Program.cs @@ -8,4 +8,9 @@ return 3; } +if (args.Any(a => a == "delay")) +{ + await Task.Delay(TimeSpan.FromSeconds(5)); +} + return 0; From eaa1109e50ac2652788d40f8608f8b203dc965e4 Mon Sep 17 00:00:00 2001 From: Andreas Ohlund Date: Wed, 5 Mar 2025 10:53:09 +0100 Subject: [PATCH 7/9] Make sure we capture stderr --- .../Setup/SetupInstanceTests.cs | 2 ++ src/SetupProcessFake/Program.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs index 0c8c38de8c..7cbeff04b1 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs @@ -3,6 +3,7 @@ using System; using System.Threading; using Engine.Setup; +using Mono.Cecil.Cil; using NUnit.Framework; [TestFixture] @@ -25,6 +26,7 @@ public void Should_capture_and_rethrow_non_zero_exit_codes() var ex = Assert.Throws(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "non-zero-exit-code", Timeout.Infinite)); Assert.That(ex.Message, Does.Contain("returned a non-zero exit code: 3")); + Assert.That(ex.Message, Does.Contain("Fake non zero exit code message")); } [Test] diff --git a/src/SetupProcessFake/Program.cs b/src/SetupProcessFake/Program.cs index c274a37796..add5ed7c02 100644 --- a/src/SetupProcessFake/Program.cs +++ b/src/SetupProcessFake/Program.cs @@ -5,6 +5,8 @@ if (args.Any(a => a == "non-zero-exit-code")) { + Console.Error.WriteLine("Fake non zero exit code message"); + return 3; } From d24734fb847d144a625a8b1d9433e493b3715f0a Mon Sep 17 00:00:00 2001 From: Andreas Ohlund Date: Wed, 5 Mar 2025 11:01:26 +0100 Subject: [PATCH 8/9] Suppress --- src/SetupProcessFake/GlobalSuppressions.cs | 8 -------- src/SetupProcessFake/Program.cs | 2 ++ 2 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 src/SetupProcessFake/GlobalSuppressions.cs diff --git a/src/SetupProcessFake/GlobalSuppressions.cs b/src/SetupProcessFake/GlobalSuppressions.cs deleted file mode 100644 index f16e81bb45..0000000000 --- a/src/SetupProcessFake/GlobalSuppressions.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. - -using System.Diagnostics.CodeAnalysis; - -[assembly: SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "TestProject")] diff --git a/src/SetupProcessFake/Program.cs b/src/SetupProcessFake/Program.cs index add5ed7c02..a4232846d8 100644 --- a/src/SetupProcessFake/Program.cs +++ b/src/SetupProcessFake/Program.cs @@ -12,7 +12,9 @@ if (args.Any(a => a == "delay")) { +#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task await Task.Delay(TimeSpan.FromSeconds(5)); +#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task } return 0; From ee5ee2413907018f0251c42924a686b2ef91415d Mon Sep 17 00:00:00 2001 From: Andreas Ohlund Date: Wed, 5 Mar 2025 13:24:28 +0100 Subject: [PATCH 9/9] Explain why we wait for ever --- .../Setup/SetupInstanceTests.cs | 1 - src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs index 7cbeff04b1..fce86dab29 100644 --- a/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs +++ b/src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs @@ -3,7 +3,6 @@ using System; using System.Threading; using Engine.Setup; -using Mono.Cecil.Cil; using NUnit.Framework; [TestFixture] diff --git a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs index 59adf7e8be..6ea0fc3898 100644 --- a/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs +++ b/src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs @@ -35,6 +35,8 @@ static void Run(string installPath, string exeName, string instanceName, bool sk args += " --skip-queue-creation"; } + // we will wait "forever" since that is the most safe action right not. We will leave it up to the setup code in the instances to make sure it won't run forever. + // If/when provide better UI experience we might revisit this and potentially find a way for the installer to control the timeout. Run(installPath, exeName, instanceName, args, Timeout.Infinite); }