From 36eb3fabd3082912d79dbeafc8c406ac6755e1b9 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Tue, 1 Apr 2025 16:48:38 -0400 Subject: Sync IEngine.SetDownloadSource with native side. Fixes https://github.com/wixtoolset/issues/issues/9018 --- src/test/burn/TestBA/TestBA.cs | 30 ++++++++++++++++++++++ .../burn/WixToolsetTest.BurnE2E/FailureTests.cs | 19 +++++++++++++- .../Utilities/TestBAController.cs | 10 ++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/burn/TestBA/TestBA.cs b/src/test/burn/TestBA/TestBA.cs index 1556acd0..4f75a055 100644 --- a/src/test/burn/TestBA/TestBA.cs +++ b/src/test/burn/TestBA/TestBA.cs @@ -41,6 +41,7 @@ namespace WixToolset.Test.BA private int cancelOnProgressAtProgress; private int retryExecuteFilesInUse; private bool rollingBack; + private string forceDownloadSource; private IBootstrapperCommand Command { get; set; } @@ -375,6 +376,12 @@ namespace WixToolset.Test.BA { this.Log(" CancelCacheAtProgress: {0}", this.cancelCacheAtProgress); } + + this.forceDownloadSource = this.ReadPackageAction(args.PackageId, "ForceDownloadSource"); + if (!String.IsNullOrEmpty(this.forceDownloadSource)) + { + this.Log(" ForceDownloadSource: {0}", this.forceDownloadSource); + } } protected override void OnCachePackageNonVitalValidationFailure(CachePackageNonVitalValidationFailureEventArgs args) @@ -387,6 +394,29 @@ namespace WixToolset.Test.BA this.Log("OnCachePackageNonVitalValidationFailure() - id: {0}, default: {1}, requested: {2}", args.PackageId, args.Recommendation, args.Action); } + protected override void OnCacheAcquireResolving(CacheAcquireResolvingEventArgs args) + { + if (!String.IsNullOrEmpty(this.forceDownloadSource)) + { + args.Action = CacheResolveOperation.Download; + var url = String.Format(this.forceDownloadSource, args.PayloadId); + + this.Log("OnCacheAcquireResolving: {0} => {1}", this.forceDownloadSource, url); + + this.engine.SetDownloadSource( + String.Empty, + args.PayloadId, + url, + String.Empty, + String.Empty, + String.Empty); + } + else + { + this.Log("OnCacheAcquireResolving not forcing download"); + } + } + protected override void OnCacheAcquireProgress(CacheAcquireProgressEventArgs args) { this.Log("OnCacheAcquireProgress() - container/package: {0}, payload: {1}, progress: {2}, total: {3}, overall progress: {4}%", args.PackageOrContainerId, args.PayloadId, args.Progress, args.Total, args.OverallPercentage); diff --git a/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs b/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs index bd3762ed..4bbfc7e9 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/FailureTests.cs @@ -2,7 +2,6 @@ namespace WixToolsetTest.BurnE2E { - using System.Threading; using WixTestTools; using WixToolset.BootstrapperApplicationApi; using Xunit; @@ -12,6 +11,24 @@ namespace WixToolsetTest.BurnE2E { public FailureTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } + [RuntimeFact] + public void CanSetDownloadSourceAndForceDownload() + { + var packageA = this.CreatePackageInstaller("PackageA"); + var bundleA = this.CreateBundleInstaller("BundleA"); + var testBAController = this.CreateTestBAController(); + + testBAController.SetPackageForceDownloadSource("PackageA", "https://1e1bf2be1c384fd1a0c4c0500eef971b/downloads/payloads/{0}"); + + packageA.VerifyInstalled(false); + + bundleA.VerifyUnregisteredAndRemovedFromPackageCache(); + + bundleA.Install(0x2ee7/*ERROR_INTERNET_NAME_NOT_RESOLVED*/); + + packageA.VerifyInstalled(false); + } + [RuntimeFact] public void CanCancelExePackageAndAbandonIt() { diff --git a/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestBAController.cs b/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestBAController.cs index a378545e..ca395f56 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestBAController.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestBAController.cs @@ -107,6 +107,16 @@ namespace WixToolsetTest.BurnE2E this.SetPackageState(packageId, "CancelExecuteAtProgress", cancelPoint.HasValue ? cancelPoint.ToString() : null); } + /// + /// Forces a download action and sets the download source. + /// + /// Package identity. + /// The URL format string. + public void SetPackageForceDownloadSource(string packageId, string url) + { + this.SetPackageState(packageId, "ForceDownloadSource", url); + } + /// /// Cancels the execute of a package at the next progess after the specified MSI action start. /// -- cgit v1.2.3-55-g6feb