diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2022-03-18 20:15:33 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2022-03-19 12:07:32 -0500 |
| commit | fb54576f1d05e82ba47cd718c4c4f8b3bad624c9 (patch) | |
| tree | b7d6b30bd3c9294b74874c1a48b20a8da8869a69 /src/test | |
| parent | 581c320e04949300d6c3bee71fb5fc1a557f9263 (diff) | |
| download | wix-fb54576f1d05e82ba47cd718c4c4f8b3bad624c9.tar.gz wix-fb54576f1d05e82ba47cd718c4c4f8b3bad624c9.tar.bz2 wix-fb54576f1d05e82ba47cd718c4c4f8b3bad624c9.zip | |
Give BA process id and option to wait for cancelled process to exit.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/burn/TestBA/TestBA.cs | 91 | ||||
| -rw-r--r-- | src/test/burn/TestData/FailureTests/BundleD/BundleD.wixproj | 19 | ||||
| -rw-r--r-- | src/test/burn/TestData/FailureTests/BundleD/BundleD.wxs | 19 | ||||
| -rw-r--r-- | src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs | 42 | ||||
| -rw-r--r-- | src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs | 15 |
5 files changed, 155 insertions, 31 deletions
diff --git a/src/test/burn/TestBA/TestBA.cs b/src/test/burn/TestBA/TestBA.cs index 3688e028..c219ce9c 100644 --- a/src/test/burn/TestBA/TestBA.cs +++ b/src/test/burn/TestBA/TestBA.cs | |||
| @@ -21,7 +21,7 @@ namespace WixToolset.Test.BA | |||
| 21 | private Form dummyWindow; | 21 | private Form dummyWindow; |
| 22 | private IntPtr windowHandle; | 22 | private IntPtr windowHandle; |
| 23 | private LaunchAction action; | 23 | private LaunchAction action; |
| 24 | private ManualResetEvent wait; | 24 | private readonly ManualResetEvent wait; |
| 25 | private int result; | 25 | private int result; |
| 26 | 26 | ||
| 27 | private string updateBundlePath; | 27 | private string updateBundlePath; |
| @@ -397,6 +397,35 @@ namespace WixToolset.Test.BA | |||
| 397 | } | 397 | } |
| 398 | } | 398 | } |
| 399 | 399 | ||
| 400 | protected override void OnExecutePackageComplete(ExecutePackageCompleteEventArgs args) | ||
| 401 | { | ||
| 402 | bool logTestRegistryValue; | ||
| 403 | string recordTestRegistryValue = this.ReadPackageAction(args.PackageId, "RecordTestRegistryValue"); | ||
| 404 | if (!String.IsNullOrEmpty(recordTestRegistryValue) && Boolean.TryParse(recordTestRegistryValue, out logTestRegistryValue) && logTestRegistryValue) | ||
| 405 | { | ||
| 406 | var value = this.ReadTestRegistryValue(args.PackageId); | ||
| 407 | this.Log("TestRegistryValue: {0}, Version, '{1}'", args.PackageId, value); | ||
| 408 | } | ||
| 409 | } | ||
| 410 | |||
| 411 | protected override void OnExecuteProcessCancel(ExecuteProcessCancelEventArgs args) | ||
| 412 | { | ||
| 413 | BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION action; | ||
| 414 | string actionValue = this.ReadPackageAction(args.PackageId, "ProcessCancelAction"); | ||
| 415 | if (actionValue != null && TryParseEnum<BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION>(actionValue, out action)) | ||
| 416 | { | ||
| 417 | args.Action = action; | ||
| 418 | } | ||
| 419 | |||
| 420 | if (args.Action == BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION.Abandon) | ||
| 421 | { | ||
| 422 | // Give time to the process to start before its files are deleted. | ||
| 423 | Thread.Sleep(2000); | ||
| 424 | } | ||
| 425 | |||
| 426 | this.Log("OnExecuteProcessCancel({0})", args.Action); | ||
| 427 | } | ||
| 428 | |||
| 400 | protected override void OnExecuteFilesInUse(ExecuteFilesInUseEventArgs args) | 429 | protected override void OnExecuteFilesInUse(ExecuteFilesInUseEventArgs args) |
| 401 | { | 430 | { |
| 402 | this.Log("OnExecuteFilesInUse() - package: {0}, source: {1}, retries remaining: {2}, data: {3}", args.PackageId, args.Source, this.retryExecuteFilesInUse, String.Join(", ", args.Files.ToArray())); | 431 | this.Log("OnExecuteFilesInUse() - package: {0}, source: {1}, retries remaining: {2}, data: {3}", args.PackageId, args.Source, this.retryExecuteFilesInUse, String.Join(", ", args.Files.ToArray())); |
| @@ -488,43 +517,34 @@ namespace WixToolset.Test.BA | |||
| 488 | private void TestVariables() | 517 | private void TestVariables() |
| 489 | { | 518 | { |
| 490 | // First make sure we can check and get standard variables of each type. | 519 | // First make sure we can check and get standard variables of each type. |
| 520 | if (this.Engine.ContainsVariable("WindowsFolder")) | ||
| 491 | { | 521 | { |
| 492 | string value = null; | 522 | string value = this.Engine.GetVariableString("WindowsFolder"); |
| 493 | if (this.Engine.ContainsVariable("WindowsFolder")) | 523 | this.Engine.Log(LogLevel.Verbose, String.Format("TEST: Successfully retrieved a string variable: WindowsFolder '{0}'", value)); |
| 494 | { | 524 | } |
| 495 | value = this.Engine.GetVariableString("WindowsFolder"); | 525 | else |
| 496 | this.Engine.Log(LogLevel.Verbose, "TEST: Successfully retrieved a string variable: WindowsFolder"); | 526 | { |
| 497 | } | 527 | throw new Exception("Engine did not define a standard variable: WindowsFolder"); |
| 498 | else | ||
| 499 | { | ||
| 500 | throw new Exception("Engine did not define a standard variable: WindowsFolder"); | ||
| 501 | } | ||
| 502 | } | 528 | } |
| 503 | 529 | ||
| 530 | if (this.Engine.ContainsVariable("NTProductType")) | ||
| 504 | { | 531 | { |
| 505 | long value = 0; | 532 | long value = this.Engine.GetVariableNumeric("NTProductType"); |
| 506 | if (this.Engine.ContainsVariable("NTProductType")) | 533 | this.Engine.Log(LogLevel.Verbose, String.Format("TEST: Successfully retrieved a numeric variable: NTProductType '{0}'", value)); |
| 507 | { | 534 | } |
| 508 | value = this.Engine.GetVariableNumeric("NTProductType"); | 535 | else |
| 509 | this.Engine.Log(LogLevel.Verbose, "TEST: Successfully retrieved a numeric variable: NTProductType"); | 536 | { |
| 510 | } | 537 | throw new Exception("Engine did not define a standard variable: NTProductType"); |
| 511 | else | ||
| 512 | { | ||
| 513 | throw new Exception("Engine did not define a standard variable: NTProductType"); | ||
| 514 | } | ||
| 515 | } | 538 | } |
| 516 | 539 | ||
| 540 | if (this.Engine.ContainsVariable("VersionMsi")) | ||
| 517 | { | 541 | { |
| 518 | string value = null; | 542 | string value = this.Engine.GetVariableVersion("VersionMsi"); |
| 519 | if (this.Engine.ContainsVariable("VersionMsi")) | 543 | this.Engine.Log(LogLevel.Verbose, String.Format("TEST: Successfully retrieved a version variable: VersionMsi '{0}'", value)); |
| 520 | { | 544 | } |
| 521 | value = this.Engine.GetVariableVersion("VersionMsi"); | 545 | else |
| 522 | this.Engine.Log(LogLevel.Verbose, "TEST: Successfully retrieved a version variable: VersionMsi"); | 546 | { |
| 523 | } | 547 | throw new Exception("Engine did not define a standard variable: VersionMsi"); |
| 524 | else | ||
| 525 | { | ||
| 526 | throw new Exception("Engine did not define a standard variable: VersionMsi"); | ||
| 527 | } | ||
| 528 | } | 548 | } |
| 529 | 549 | ||
| 530 | // Now validate that Contians returns false for non-existant variables of each type. | 550 | // Now validate that Contians returns false for non-existant variables of each type. |
| @@ -596,6 +616,15 @@ namespace WixToolset.Test.BA | |||
| 596 | } | 616 | } |
| 597 | } | 617 | } |
| 598 | 618 | ||
| 619 | private string ReadTestRegistryValue(string name) | ||
| 620 | { | ||
| 621 | string testName = this.Engine.GetVariableString("TestGroupName"); | ||
| 622 | using (RegistryKey testKey = Registry.LocalMachine.OpenSubKey(String.Format(@"Software\WiX\Tests\{0}\{1}", testName, name))) | ||
| 623 | { | ||
| 624 | return testKey == null ? null : testKey.GetValue("Version") as string; | ||
| 625 | } | ||
| 626 | } | ||
| 627 | |||
| 599 | private static bool TryParseEnum<T>(string value, out T t) | 628 | private static bool TryParseEnum<T>(string value, out T t) |
| 600 | { | 629 | { |
| 601 | try | 630 | try |
diff --git a/src/test/burn/TestData/FailureTests/BundleD/BundleD.wixproj b/src/test/burn/TestData/FailureTests/BundleD/BundleD.wixproj new file mode 100644 index 00000000..7b7408c6 --- /dev/null +++ b/src/test/burn/TestData/FailureTests/BundleD/BundleD.wixproj | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | <!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. --> | ||
| 2 | <Project Sdk="WixToolset.Sdk"> | ||
| 3 | <PropertyGroup> | ||
| 4 | <OutputType>Bundle</OutputType> | ||
| 5 | <UpgradeCode>{3C1A4842-81AC-4C90-8B35-A5E18F034C8D}</UpgradeCode> | ||
| 6 | <Version>1.0.0.0</Version> | ||
| 7 | </PropertyGroup> | ||
| 8 | <ItemGroup> | ||
| 9 | <Compile Include="..\..\Templates\Bundle.wxs" Link="Bundle.wxs" /> | ||
| 10 | </ItemGroup> | ||
| 11 | <ItemGroup> | ||
| 12 | <ProjectReference Include="..\..\TestBA\TestBAWixlib\testbawixlib.wixproj" /> | ||
| 13 | </ItemGroup> | ||
| 14 | <ItemGroup> | ||
| 15 | <PackageReference Include="WixToolset.Bal.wixext" /> | ||
| 16 | <PackageReference Include="WixToolset.NetFx.wixext" /> | ||
| 17 | <PackageReference Include="WixToolset.Util.wixext" /> | ||
| 18 | </ItemGroup> | ||
| 19 | </Project> \ No newline at end of file | ||
diff --git a/src/test/burn/TestData/FailureTests/BundleD/BundleD.wxs b/src/test/burn/TestData/FailureTests/BundleD/BundleD.wxs new file mode 100644 index 00000000..ca70236d --- /dev/null +++ b/src/test/burn/TestData/FailureTests/BundleD/BundleD.wxs | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | <!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. --> | ||
| 2 | |||
| 3 | <?define TestExeRegistryKey = Software\WiX\Tests\$(var.TestGroupName)\ExeA?> | ||
| 4 | |||
| 5 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"> | ||
| 6 | <Fragment> | ||
| 7 | <util:RegistrySearch Root="HKLM" Key="$(var.TestExeRegistryKey)" Value="Version" Variable="ExeA_Version" /> | ||
| 8 | |||
| 9 | <PackageGroup Id="BundlePackages"> | ||
| 10 | <ExePackage Id="ExeA" Cache="remove" PerMachine="yes" | ||
| 11 | DetectCondition="ExeA_Version AND ExeA_Version >= v$(var.Version)" | ||
| 12 | InstallArguments="/s 5000 /regw "HKLM\$(var.TestExeRegistryKey),Version,String,$(var.Version)"" | ||
| 13 | RepairArguments="/regw "HKLM\$(var.TestExeRegistryKey),Version,String,$(var.Version)"" | ||
| 14 | UninstallArguments="/regd "HKLM\$(var.TestExeRegistryKey),Version""> | ||
| 15 | <PayloadGroupRef Id="TestExePayloads" /> | ||
| 16 | </ExePackage> | ||
| 17 | </PackageGroup> | ||
| 18 | </Fragment> | ||
| 19 | </Wix> | ||
diff --git a/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs b/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs index d8428a54..bbc0b387 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs | |||
| @@ -2,7 +2,9 @@ | |||
| 2 | 2 | ||
| 3 | namespace WixToolsetTest.BurnE2E | 3 | namespace WixToolsetTest.BurnE2E |
| 4 | { | 4 | { |
| 5 | using System.Threading; | ||
| 5 | using WixTestTools; | 6 | using WixTestTools; |
| 7 | using WixToolset.Mba.Core; | ||
| 6 | using Xunit; | 8 | using Xunit; |
| 7 | using Xunit.Abstractions; | 9 | using Xunit.Abstractions; |
| 8 | 10 | ||
| @@ -11,6 +13,46 @@ namespace WixToolsetTest.BurnE2E | |||
| 11 | public FailureTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } | 13 | public FailureTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } |
| 12 | 14 | ||
| 13 | [Fact] | 15 | [Fact] |
| 16 | public void CanCancelExePackageAndAbandonIt() | ||
| 17 | { | ||
| 18 | var bundleD = this.CreateBundleInstaller("BundleD"); | ||
| 19 | var testBAController = this.CreateTestBAController(); | ||
| 20 | |||
| 21 | // Cancel package ExeA after it starts. | ||
| 22 | testBAController.SetPackageCancelExecuteAtProgress("ExeA", 1); | ||
| 23 | testBAController.SetPackageRecordTestRegistryValue("ExeA"); | ||
| 24 | |||
| 25 | var logPath = bundleD.Install((int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_USEREXIT); | ||
| 26 | bundleD.VerifyUnregisteredAndRemovedFromPackageCache(); | ||
| 27 | |||
| 28 | Assert.True(LogVerifier.MessageInLogFile(logPath, "TestRegistryValue: ExeA, Version, ''")); | ||
| 29 | |||
| 30 | // Make sure ExeA finishes running. | ||
| 31 | Thread.Sleep(3000); | ||
| 32 | |||
| 33 | bundleD.VerifyExeTestRegistryValue("ExeA", "1.0.0.0"); | ||
| 34 | } | ||
| 35 | |||
| 36 | [Fact] | ||
| 37 | public void CanCancelExePackageAndWaitUntilItCompletes() | ||
| 38 | { | ||
| 39 | var bundleD = this.CreateBundleInstaller("BundleD"); | ||
| 40 | var testBAController = this.CreateTestBAController(); | ||
| 41 | |||
| 42 | // Cancel package ExeA after it starts. | ||
| 43 | testBAController.SetPackageCancelExecuteAtProgress("ExeA", 1); | ||
| 44 | testBAController.SetPackageProcessCancelAction("ExeA", BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION.Wait); | ||
| 45 | testBAController.SetPackageRecordTestRegistryValue("ExeA"); | ||
| 46 | |||
| 47 | var logPath = bundleD.Install((int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_USEREXIT); | ||
| 48 | bundleD.VerifyUnregisteredAndRemovedFromPackageCache(); | ||
| 49 | |||
| 50 | Assert.True(LogVerifier.MessageInLogFile(logPath, "TestRegistryValue: ExeA, Version, '1.0.0.0'")); | ||
| 51 | |||
| 52 | bundleD.VerifyExeTestRegistryValue("ExeA", "1.0.0.0"); | ||
| 53 | } | ||
| 54 | |||
| 55 | [Fact] | ||
| 14 | public void CanCancelMsiPackageVeryEarly() | 56 | public void CanCancelMsiPackageVeryEarly() |
| 15 | { | 57 | { |
| 16 | var packageA = this.CreatePackageInstaller("PackageA"); | 58 | var packageA = this.CreatePackageInstaller("PackageA"); |
diff --git a/src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs b/src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs index d2e8a1ca..fa553919 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs | |||
| @@ -148,6 +148,21 @@ namespace WixToolsetTest.BurnE2E | |||
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | /// <summary> | 150 | /// <summary> |
| 151 | /// Requests the BA to log the test registry value for the specified package. | ||
| 152 | /// </summary> | ||
| 153 | /// <param name="packageId"></param> | ||
| 154 | /// <param name="value"></param> | ||
| 155 | public void SetPackageRecordTestRegistryValue(string packageId, string value = "true") | ||
| 156 | { | ||
| 157 | this.SetPackageState(packageId, "RecordTestRegistryValue", value); | ||
| 158 | } | ||
| 159 | |||
| 160 | public void SetPackageProcessCancelAction(string packageId, BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION action) | ||
| 161 | { | ||
| 162 | this.SetPackageState(packageId, "ProcessCancelAction", action.ToString()); | ||
| 163 | } | ||
| 164 | |||
| 165 | /// <summary> | ||
| 151 | /// Sets the number of times to re-run the Detect phase. | 166 | /// Sets the number of times to re-run the Detect phase. |
| 152 | /// </summary> | 167 | /// </summary> |
| 153 | /// <param name="state">Number of times to run Detect (after the first, normal, Detect).</param> | 168 | /// <param name="state">Number of times to run Detect (after the first, normal, Detect).</param> |
