From 040e50ec2859c1de70cd8e9f957474321774f293 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 11 Feb 2025 13:53:50 -0800 Subject: Rewrite Prereq tests after hardening and bypassing .NET GUI errors --- .../TestData/PrereqBaTests/BundleA/BundleA.wxs | 11 +- .../PrereqBaTests/BundleA/bad.runtimeconfig.json | 10 - .../TestData/PrereqBaTests/BundleB/BundleB.wxs | 12 +- .../TestData/PrereqBaTests/BundleC/BundleC.wixproj | 2 +- .../TestData/PrereqBaTests/BundleC/BundleC.wxs | 10 +- .../PrereqBaTests/BundleC/bad.runtimeconfig.json | 10 - .../TestData/PrereqBaTests/BundleD/BundleD.wixproj | 2 +- .../TestData/PrereqBaTests/BundleD/BundleD.wxs | 11 +- .../TestData/PrereqBaTests/BundleE/BundleE.wxs | 4 +- .../PrereqBaTests/ReplaceConfig/ReplaceConfig.cpp | 20 +- .../burn/WixToolsetTest.BurnE2E/PrereqBaTests.cs | 212 ++++----------------- 11 files changed, 71 insertions(+), 233 deletions(-) delete mode 100644 src/test/burn/TestData/PrereqBaTests/BundleA/bad.runtimeconfig.json delete mode 100644 src/test/burn/TestData/PrereqBaTests/BundleC/bad.runtimeconfig.json (limited to 'src') diff --git a/src/test/burn/TestData/PrereqBaTests/BundleA/BundleA.wxs b/src/test/burn/TestData/PrereqBaTests/BundleA/BundleA.wxs index a86f498f..5f0fefe5 100644 --- a/src/test/burn/TestData/PrereqBaTests/BundleA/BundleA.wxs +++ b/src/test/burn/TestData/PrereqBaTests/BundleA/BundleA.wxs @@ -1,13 +1,11 @@  - - + - @@ -17,13 +15,12 @@ - - + + Permanent="yes" DetectCondition="TestBAConfigPresent" + InstallArguments=""[BARuntimeDirectory]\TestBA.runtimeconfig.json" "[BARuntimeDirectory]\good.runtimeconfig.json"" /> diff --git a/src/test/burn/TestData/PrereqBaTests/BundleA/bad.runtimeconfig.json b/src/test/burn/TestData/PrereqBaTests/BundleA/bad.runtimeconfig.json deleted file mode 100644 index 07a1a830..00000000 --- a/src/test/burn/TestData/PrereqBaTests/BundleA/bad.runtimeconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "runtimeOptions": { - "tfm": "net5.5", - "rollForward": "Disable", - "framework": { - "name": "Microsoft.WindowsDesktop.App", - "version": "5.5.0" - } - } -} \ No newline at end of file diff --git a/src/test/burn/TestData/PrereqBaTests/BundleB/BundleB.wxs b/src/test/burn/TestData/PrereqBaTests/BundleB/BundleB.wxs index 7a84bd5b..f5745d0f 100644 --- a/src/test/burn/TestData/PrereqBaTests/BundleB/BundleB.wxs +++ b/src/test/burn/TestData/PrereqBaTests/BundleB/BundleB.wxs @@ -1,12 +1,9 @@  - - + - @@ -16,13 +13,12 @@ - - + + Permanent="yes" DetectCondition="TestBAConfigPresent" + InstallArguments=""[BARuntimeDirectory]TestBA.exe.config" "[BARuntimeDirectory]good.config"" /> diff --git a/src/test/burn/TestData/PrereqBaTests/BundleC/BundleC.wixproj b/src/test/burn/TestData/PrereqBaTests/BundleC/BundleC.wixproj index 7ed34aa5..27b9c196 100644 --- a/src/test/burn/TestData/PrereqBaTests/BundleC/BundleC.wixproj +++ b/src/test/burn/TestData/PrereqBaTests/BundleC/BundleC.wixproj @@ -2,7 +2,7 @@ Bundle - BrokenDncAlwaysPrereq + BrokenDncSecondary {D2763AB7-979B-485C-AE52-DD03C23CCB93} diff --git a/src/test/burn/TestData/PrereqBaTests/BundleC/BundleC.wxs b/src/test/burn/TestData/PrereqBaTests/BundleC/BundleC.wxs index e03cad62..12607cf0 100644 --- a/src/test/burn/TestData/PrereqBaTests/BundleC/BundleC.wxs +++ b/src/test/burn/TestData/PrereqBaTests/BundleC/BundleC.wxs @@ -2,11 +2,10 @@ - + - @@ -16,13 +15,12 @@ - - + + Permanent="yes" DetectCondition="TestBAConfigPresent" + InstallArguments=""[BARuntimeDirectory]TestBA.runtimeconfig.json" "[BARuntimeDirectory]good.runtimeconfig.json"" /> diff --git a/src/test/burn/TestData/PrereqBaTests/BundleC/bad.runtimeconfig.json b/src/test/burn/TestData/PrereqBaTests/BundleC/bad.runtimeconfig.json deleted file mode 100644 index 07a1a830..00000000 --- a/src/test/burn/TestData/PrereqBaTests/BundleC/bad.runtimeconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "runtimeOptions": { - "tfm": "net5.5", - "rollForward": "Disable", - "framework": { - "name": "Microsoft.WindowsDesktop.App", - "version": "5.5.0" - } - } -} \ No newline at end of file diff --git a/src/test/burn/TestData/PrereqBaTests/BundleD/BundleD.wixproj b/src/test/burn/TestData/PrereqBaTests/BundleD/BundleD.wixproj index 280193df..1888bc7d 100644 --- a/src/test/burn/TestData/PrereqBaTests/BundleD/BundleD.wixproj +++ b/src/test/burn/TestData/PrereqBaTests/BundleD/BundleD.wixproj @@ -2,7 +2,7 @@ Bundle - BrokenMbaAlwaysPrereq + BrokenMbaSecondary {415CA128-60E1-4D16-ACE8-A1D43E98B997} diff --git a/src/test/burn/TestData/PrereqBaTests/BundleD/BundleD.wxs b/src/test/burn/TestData/PrereqBaTests/BundleD/BundleD.wxs index 2eed4bd1..1b414cb2 100644 --- a/src/test/burn/TestData/PrereqBaTests/BundleD/BundleD.wxs +++ b/src/test/burn/TestData/PrereqBaTests/BundleD/BundleD.wxs @@ -1,11 +1,9 @@  - - + - @@ -15,13 +13,12 @@ - - + + Permanent="yes" DetectCondition="TestBAConfigPresent" + InstallArguments=""[BARuntimeDirectory]TestBA.exe.config" "[BARuntimeDirectory]good.config"" /> diff --git a/src/test/burn/TestData/PrereqBaTests/BundleE/BundleE.wxs b/src/test/burn/TestData/PrereqBaTests/BundleE/BundleE.wxs index b6962b65..b994847e 100644 --- a/src/test/burn/TestData/PrereqBaTests/BundleE/BundleE.wxs +++ b/src/test/burn/TestData/PrereqBaTests/BundleE/BundleE.wxs @@ -14,11 +14,11 @@ - + diff --git a/src/test/burn/TestData/PrereqBaTests/ReplaceConfig/ReplaceConfig.cpp b/src/test/burn/TestData/PrereqBaTests/ReplaceConfig/ReplaceConfig.cpp index 1fa71bc2..b8172e6b 100644 --- a/src/test/burn/TestData/PrereqBaTests/ReplaceConfig/ReplaceConfig.cpp +++ b/src/test/burn/TestData/PrereqBaTests/ReplaceConfig/ReplaceConfig.cpp @@ -7,27 +7,31 @@ int __cdecl wmain( __in LPWSTR argv[] ) { + DWORD er = ERROR_SUCCESS; HRESULT hr = S_OK; - DWORD dwExitCode = 0; LPCWSTR wzDestinationFile = argc > 1 ? argv[1] : NULL; LPCWSTR wzGoodFile = argc > 2 ? argv[2] : NULL; - LPCWSTR wzBadFile = argc > 3 ? argv[3] : NULL; + LPCWSTR wzBackupFile = argc > 3 ? argv[3] : NULL; - if (argc != 4) + if (!wzDestinationFile || !*wzDestinationFile || !wzGoodFile || !*wzGoodFile) { ExitWithRootFailure(hr, E_INVALIDARG, "Invalid args"); } - if (!::MoveFileW(wzDestinationFile, wzBadFile)) + if (wzBackupFile && *wzBackupFile && !::CopyFileW(wzDestinationFile, wzBackupFile, FALSE)) { - ExitWithLastError(hr, "Failed to move bad file"); + er = ::GetLastError(); + if (ERROR_PATH_NOT_FOUND != er && ERROR_FILE_NOT_FOUND != er) + { + ExitOnWin32Error(er, hr, "Failed to copy to backup file"); + } } - if (!::MoveFileW(wzGoodFile, wzDestinationFile)) + if (!::CopyFileW(wzGoodFile, wzDestinationFile, FALSE)) { - ExitWithLastError(hr, "Failed to move good file"); + ExitWithLastError(hr, "Failed to copy in good file"); } LExit: - return FAILED(hr) ? (int)hr : (int)dwExitCode; + return FAILED(hr) ? (int)hr : (int)0; } diff --git a/src/test/burn/WixToolsetTest.BurnE2E/PrereqBaTests.cs b/src/test/burn/WixToolsetTest.BurnE2E/PrereqBaTests.cs index 4fccb0e9..bc21458d 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/PrereqBaTests.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/PrereqBaTests.cs @@ -12,22 +12,21 @@ namespace WixToolsetTest.BurnE2E { public PrereqBaTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } - const int E_PREREQBA_INFINITE_LOOP = -2_114_714_646; - /// - /// This bundle purposely provides a .runtimeconfig.json file that requires a version of .NET Core that doesn't exist, - /// with an MSI package to represent the prerequisite package. + /// This bundle purposely misnames its .runtimeconfig.json file to force the PreqBA to kick in + /// and use its EXE prereq package to swap in a good one. /// This verifies that: - /// The preqba doesn't infinitely try to install prereqs. - /// The engine automatically uninstalls the bundle since only permanent packages were installed. + /// The mangaged BA fails to load due to the missing file. + /// The preqba kicks in to copy in the file. + /// The managed BA gets loaded. /// - [RuntimeFact(Skip = ".NET displays a message box when runtime is not present on the machine which hangs on CI systems. Skip this test until we can get a different behavior from .NET")] - public void DncAlwaysPreqBaDetectsInfiniteLoop() + [RuntimeFact] + public void DncLoadsOnlyAfterInstallingPrereqs() { var packageA = this.CreatePackageInstaller("PackageA"); var packageC = this.CreatePackageInstaller("PackageC"); - var bundleC = this.CreateBundleInstaller("BundleC"); + var bundleA = this.CreateBundleInstaller("BundleA"); var packageASourceCodeInstalled = packageA.GetInstalledFilePath("Package.wxs"); @@ -35,60 +34,28 @@ namespace WixToolsetTest.BurnE2E Assert.False(File.Exists(packageASourceCodeInstalled), $"Package A payload should not be there on test start: {packageASourceCodeInstalled}"); packageC.VerifyInstalled(false); - bundleC.Install(E_PREREQBA_INFINITE_LOOP, "CAUSEINFINITELOOP=1"); - - // Part of the test is Install actually completing. + bundleA.Install(); // Source file should be installed Assert.True(File.Exists(packageASourceCodeInstalled), String.Concat("Should have found Package A payload installed at: ", packageASourceCodeInstalled)); - packageC.VerifyInstalled(false); - - // No non-permanent packages should have ended up installed or cached so it should have unregistered. - bundleC.VerifyUnregisteredAndRemovedFromPackageCache(); - } - - /// - /// This bundle purposely provides a .runtimeconfig.json file that requires a version of .NET Core that doesn't exist, - /// with an MSI package to represent the prerequisite package. - /// This verifies that: - /// The preqba doesn't infinitely reload itself after failing to load the managed BA. - /// The engine automatically uninstalls the bundle since only permanent packages were installed. - /// - [RuntimeFact(Skip = ".NET displays a message box when runtime is not present on the machine which hangs on CI systems. Skip this test until we can get a different behavior from .NET")] - public void DncPreqBaDetectsInfiniteLoop() - { - var packageA = this.CreatePackageInstaller("PackageA"); - var packageC = this.CreatePackageInstaller("PackageC"); - - var bundleA = this.CreateBundleInstaller("BundleA"); - - var packageASourceCodeInstalled = packageA.GetInstalledFilePath("Package.wxs"); - - // Source file should *not* be installed - Assert.False(File.Exists(packageASourceCodeInstalled), $"Package A payload should not be there on test start: {packageASourceCodeInstalled}"); - packageC.VerifyInstalled(false); - - bundleA.Install(E_PREREQBA_INFINITE_LOOP, "CAUSEINFINITELOOP=1"); + packageC.VerifyInstalled(true); - // Part of the test is Install actually completing. + bundleA.VerifyRegisteredAndInPackageCache(); - // Source file should be installed - Assert.True(File.Exists(packageASourceCodeInstalled), String.Concat("Should have found Package A payload installed at: ", packageASourceCodeInstalled)); - packageC.VerifyInstalled(false); + bundleA.Uninstall(); - // No non-permanent packages should have ended up installed or cached so it should have unregistered. bundleA.VerifyUnregisteredAndRemovedFromPackageCache(); } /// - /// This bundle purposely provides a .runtimeconfig.json file that requires a version of .NET Core that doesn't exist, - /// with an EXE prereq package to swap it out with a good one. + /// This bundle purposely misnames its .runtimeconfig.json file to force the PreqBA to kick in + /// and use its EXE prereq package to swap in a good one. /// This verifies that: - /// The preqba doesn't infinitely try to install prereqs. - /// The managed BA gets loaded after installing prereqs. + /// The preqba runs first to fix the file. + /// The managed BA gets loaded on first try. /// [RuntimeFact] - public void DncAlwaysPreqBaLoadsManagedBaAfterInstallingPrereqs() + public void DncPreqsFirstThenBaLoadsManagedBa() { var packageA = this.CreatePackageInstaller("PackageA"); var packageC = this.CreatePackageInstaller("PackageC"); @@ -114,64 +81,20 @@ namespace WixToolsetTest.BurnE2E bundleC.VerifyUnregisteredAndRemovedFromPackageCache(); } - /// - /// This bundle purposely provides a .runtimeconfig.json file that requires a version of .NET Core that doesn't exist, - /// with an EXE prereq package to swap it out with a good one. + /// This bundle purposely misnames its WixToolset.Mba.Host.config file to force the PreqBA to kick in + /// and use its EXE prereq package to swap in a good one. /// This verifies that: - /// The preqba doesn't infinitely reload itself after failing to load the managed BA. - /// The managed BA gets loaded after installing prereqs. + /// The mangaged BA fails to load due to the missing file. + /// The preqba kicks in to copy in the file. + /// The managed BA gets loaded. /// - [RuntimeFact] - public void DncPreqBaLoadsManagedBaAfterInstallingPrereqs() - { - var packageA = this.CreatePackageInstaller("PackageA"); - var packageC = this.CreatePackageInstaller("PackageC"); - - var bundleA = this.CreateBundleInstaller("BundleA"); - - var packageASourceCodeInstalled = packageA.GetInstalledFilePath("Package.wxs"); - - // Source file should *not* be installed - Assert.False(File.Exists(packageASourceCodeInstalled), $"Package A payload should not be there on test start: {packageASourceCodeInstalled}"); - packageC.VerifyInstalled(false); - - bundleA.Install(); - - // Source file should be installed - Assert.True(File.Exists(packageASourceCodeInstalled), String.Concat("Should have found Package A payload installed at: ", packageASourceCodeInstalled)); - packageC.VerifyInstalled(true); - - bundleA.VerifyRegisteredAndInPackageCache(); - - bundleA.Uninstall(); - - bundleA.VerifyUnregisteredAndRemovedFromPackageCache(); - } - - [RuntimeFact] - public void DncAlwaysPreqBaForwardsHelpToManagedBa() - { - var bundleE = this.CreateBundleInstaller("BundleE"); - - var bundleLog = bundleE.Help(); - - Assert.True(LogVerifier.MessageInLogFile(bundleLog, "This is a BA for automated testing")); - } - - /// - /// This bundle purposely provides a WixToolset.Mba.Host.config file that requires a version of .NET Framework that doesn't exist, - /// with an MSI package to represent the prerequisite package. - /// This verifies that: - /// The preqba doesn't infinitely try to install prereqs. - /// The engine automatically uninstalls the bundle since only permanent packages were installed. - /// - [RuntimeFact(Skip = ".NET displays a message box when runtime is not present on the machine which hangs on CI systems. Skip this test until we can get a different behavior from .NET")] - public void MbaAlwaysPreqBaDetectsInfiniteLoop() + [RuntimeFact(Skip = "It is no longer possible to replace the bad.config with a good config, these tests do not work for .NET Framework the way they can for .NET above.")] + public void MbaLoadsOnlyAfterInstallingPrereqs() { var packageB = this.CreatePackageInstaller("PackageB"); var packageC = this.CreatePackageInstaller("PackageC"); - var bundleD = this.CreateBundleInstaller("BundleD"); + var bundleB = this.CreateBundleInstaller("BundleB"); var packageBSourceCodeInstalled = packageB.GetInstalledFilePath("Package.wxs"); @@ -179,60 +102,28 @@ namespace WixToolsetTest.BurnE2E Assert.False(File.Exists(packageBSourceCodeInstalled), $"Package B payload should not be there on test start: {packageBSourceCodeInstalled}"); packageC.VerifyInstalled(false); - bundleD.Install(E_PREREQBA_INFINITE_LOOP, "CAUSEINFINITELOOP=1"); - - // Part of the test is Install actually completing. + bundleB.Install(); // Source file should be installed Assert.True(File.Exists(packageBSourceCodeInstalled), String.Concat("Should have found Package B payload installed at: ", packageBSourceCodeInstalled)); - packageC.VerifyInstalled(false); - - // No non-permanent packages should have ended up installed or cached so it should have unregistered. - bundleD.VerifyUnregisteredAndRemovedFromPackageCache(); - } - - /// - /// This bundle purposely provides a WixToolset.Mba.Host.config file that requires a version of .NET Framework that doesn't exist, - /// with an MSI package to represent the prerequisite package. - /// This verifies that: - /// The preqba doesn't infinitely reload itself after failing to load the managed BA. - /// The engine automatically uninstalls the bundle since only permanent packages were installed. - /// - [RuntimeFact(Skip = ".NET displays a message box when runtime is not present on the machine which hangs on CI systems. Skip this test until we can get a different behavior from .NET")] - public void MbaPreqBaDetectsInfiniteLoop() - { - var packageB = this.CreatePackageInstaller("PackageB"); - var packageC = this.CreatePackageInstaller("PackageC"); - - var bundleB = this.CreateBundleInstaller("BundleB"); - - var packageBSourceCodeInstalled = packageB.GetInstalledFilePath("Package.wxs"); - - // Source file should *not* be installed - Assert.False(File.Exists(packageBSourceCodeInstalled), $"Package B payload should not be there on test start: {packageBSourceCodeInstalled}"); - packageC.VerifyInstalled(false); - - bundleB.Install(E_PREREQBA_INFINITE_LOOP, "CAUSEINFINITELOOP=1"); + packageC.VerifyInstalled(true); - // Part of the test is Install actually completing. + bundleB.VerifyRegisteredAndInPackageCache(); - // Source file should be installed - Assert.True(File.Exists(packageBSourceCodeInstalled), String.Concat("Should have found Package B payload installed at: ", packageBSourceCodeInstalled)); - packageC.VerifyInstalled(false); + bundleB.Uninstall(); // No non-permanent packages should have ended up installed or cached so it should have unregistered. bundleB.VerifyUnregisteredAndRemovedFromPackageCache(); } - /// - /// This bundle purposely provides a WixToolset.Mba.Host.config file that requires a version of .NET Framework that doesn't exist, - /// with an EXE prereq package to swap it out with a good one. + /// This bundle purposely misnames its WixToolset.Mba.Host.config file to force the PreqBA to kick in + /// and use its EXE prereq package to swap in a good one. /// This verifies that: - /// The preqba doesn't infinitely try to install prereqs. - /// The managed BA gets loaded after installing prereqs. + /// The preqba runs first to fix the file. + /// The managed BA gets loaded on first try. /// - [RuntimeFact] - public void MbaAlwaysPreqBaLoadsManagedBaAfterInstallingPrereqs() + [RuntimeFact(Skip = "It is no longer possible to replace the bad.config with a good config, these tests do not work for .NET Framework the way they can for .NET above.")] + public void MbaPreqsFirstThenBaLoadsManagedBa() { var packageB = this.CreatePackageInstaller("PackageB"); var packageC = this.CreatePackageInstaller("PackageC"); @@ -258,39 +149,14 @@ namespace WixToolsetTest.BurnE2E bundleD.VerifyUnregisteredAndRemovedFromPackageCache(); } - /// - /// This bundle purposely provides a WixToolset.Mba.Host.config file that requires a version of .NET Framework that doesn't exist, - /// with an EXE prereq package to swap it out with a good one. - /// This verifies that: - /// The preqba doesn't infinitely reload itself after failing to load the managed BA. - /// The managed BA gets loaded after installing prereqs. - /// [RuntimeFact] - public void MbaPreqBaLoadsManagedBaAfterInstallingPrereqs() + public void DncAlwaysPreqBaForwardsHelpToManagedBa() { - var packageB = this.CreatePackageInstaller("PackageB"); - var packageC = this.CreatePackageInstaller("PackageC"); - - var bundleB = this.CreateBundleInstaller("BundleB"); - - var packageBSourceCodeInstalled = packageB.GetInstalledFilePath("Package.wxs"); - - // Source file should *not* be installed - Assert.False(File.Exists(packageBSourceCodeInstalled), $"Package B payload should not be there on test start: {packageBSourceCodeInstalled}"); - packageC.VerifyInstalled(false); - - bundleB.Install(); - - // Source file should be installed - Assert.True(File.Exists(packageBSourceCodeInstalled), String.Concat("Should have found Package B payload installed at: ", packageBSourceCodeInstalled)); - packageC.VerifyInstalled(true); - - bundleB.VerifyRegisteredAndInPackageCache(); + var bundleE = this.CreateBundleInstaller("BundleE"); - bundleB.Uninstall(); + var bundleLog = bundleE.Help(); - // No non-permanent packages should have ended up installed or cached so it should have unregistered. - bundleB.VerifyUnregisteredAndRemovedFromPackageCache(); + Assert.True(LogVerifier.MessageInLogFile(bundleLog, "This is a BA for automated testing")); } } } -- cgit v1.2.3-55-g6feb