diff --git a/src/Agent.Plugins/TFCliManager.cs b/src/Agent.Plugins/TFCliManager.cs index cd9032967f..16e3475c22 100644 --- a/src/Agent.Plugins/TFCliManager.cs +++ b/src/Agent.Plugins/TFCliManager.cs @@ -12,7 +12,6 @@ using System.Xml; using System.Security.Cryptography.X509Certificates; using Microsoft.VisualStudio.Services.Agent.Util; -using Agent.Sdk.Knob; namespace Agent.Plugins.Repository { @@ -38,15 +37,11 @@ public override TfsVCFeatures Features public static readonly int RetriesOnFailure = 3; - private string TfPath => AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean() - ? Path.Combine(ExecutionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", "tf-legacy") - : Path.Combine(ExecutionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", "tf"); + public string FilePath => Path.Combine(ExecutionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", "tf", "tf.exe"); - public string FilePath => Path.Combine(TfPath, "tf.exe"); + private string AppConfigFile => Path.Combine(ExecutionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", "tf", "tf.exe.config"); - private string AppConfigFile => Path.Combine(TfPath, "tf.exe.config"); - - private string AppConfigRestoreFile => Path.Combine(TfPath, "tf.exe.config.restore"); + private string AppConfigRestoreFile => Path.Combine(ExecutionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", "tf", "tf.exe.config.restore"); // TODO: Remove AddAsync after last-saved-checkin-metadata problem is fixed properly. public async Task AddAsync(string localPath) diff --git a/src/Agent.Plugins/TfsVCSourceProvider.cs b/src/Agent.Plugins/TfsVCSourceProvider.cs index f9ad5fc122..aee7963fbe 100644 --- a/src/Agent.Plugins/TfsVCSourceProvider.cs +++ b/src/Agent.Plugins/TfsVCSourceProvider.cs @@ -101,8 +101,7 @@ public async Task GetSourceAsync( if (PlatformUtil.RunningOnWindows) { // Set TFVC_BUILDAGENT_POLICYPATH - string tfDirectoryName = AgentKnobs.InstallLegacyTfExe.GetValue(executionContext).AsBoolean() ? "tf-legacy" : "tf"; - string policyDllPath = Path.Combine(executionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", tfDirectoryName, "Microsoft.TeamFoundation.VersionControl.Controls.dll"); + string policyDllPath = Path.Combine(executionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", "tf", "Microsoft.TeamFoundation.VersionControl.Controls.dll"); ArgUtil.File(policyDllPath, nameof(policyDllPath)); const string policyPathEnvKey = "TFVC_BUILDAGENT_POLICYPATH"; executionContext.Output(StringUtil.Loc("SetEnvVar", policyPathEnvKey)); diff --git a/src/Agent.Sdk/Knob/AgentKnobs.cs b/src/Agent.Sdk/Knob/AgentKnobs.cs index 5c711370ce..01409da5ad 100644 --- a/src/Agent.Sdk/Knob/AgentKnobs.cs +++ b/src/Agent.Sdk/Knob/AgentKnobs.cs @@ -765,12 +765,5 @@ public class AgentKnobs new RuntimeKnobSource("ADD_FORCE_CREDENTIALS_TO_GIT_CHECKOUT"), new PipelineFeatureSource(nameof(AddForceCredentialsToGitCheckout)), new BuiltInDefaultKnobSource("false")); - - public static readonly Knob InstallLegacyTfExe = new Knob( - nameof(InstallLegacyTfExe), - "If true, agent will install the previous version of TF.exe in the tf-legacy and vstsom-legacy directories", - new RuntimeKnobSource("AGENT_INSTALL_LEGACY_TF_EXE"), - new EnvironmentKnobSource("AGENT_INSTALL_LEGACY_TF_EXE"), - new BuiltInDefaultKnobSource("false")); } } diff --git a/src/Agent.Worker/Build/TFCommandManager.cs b/src/Agent.Worker/Build/TFCommandManager.cs index f44f9fdbbe..d606ee16c4 100644 --- a/src/Agent.Worker/Build/TFCommandManager.cs +++ b/src/Agent.Worker/Build/TFCommandManager.cs @@ -11,7 +11,6 @@ using System.Text; using System.Xml; using System.Security.Cryptography.X509Certificates; -using Agent.Sdk.Knob; namespace Microsoft.VisualStudio.Services.Agent.Worker.Build { @@ -35,15 +34,11 @@ public override TfsVCFeatures Features protected override string Switch => "/"; - private string TfPath => AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean() - ? HostContext.GetDirectory(WellKnownDirectory.TfLegacy) - : HostContext.GetDirectory(WellKnownDirectory.Tf); + public override string FilePath => Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Tf), "tf.exe"); - public override string FilePath => Path.Combine(TfPath, "tf.exe"); + private string AppConfigFile => Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Tf), "tf.exe.config"); - private string AppConfigFile => Path.Combine(TfPath, "tf.exe.config"); - - private string AppConfigRestoreFile => Path.Combine(TfPath, "tf.exe.config.restore"); + private string AppConfigRestoreFile => Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Tf), "tf.exe.config.restore"); // TODO: Remove AddAsync after last-saved-checkin-metadata problem is fixed properly. public async Task AddAsync(string localPath) diff --git a/src/Agent.Worker/Build/TfsVCSourceProvider.cs b/src/Agent.Worker/Build/TfsVCSourceProvider.cs index d295decb87..33309a2546 100644 --- a/src/Agent.Worker/Build/TfsVCSourceProvider.cs +++ b/src/Agent.Worker/Build/TfsVCSourceProvider.cs @@ -17,7 +17,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using Agent.Sdk.Knob; namespace Microsoft.VisualStudio.Services.Agent.Worker.Build { @@ -89,11 +88,7 @@ public async Task GetSourceAsync( if (PlatformUtil.RunningOnWindows) { // Set TFVC_BUILDAGENT_POLICYPATH - string vstsomPath = AgentKnobs.InstallLegacyTfExe.GetValue(executionContext).AsBoolean() - ? HostContext.GetDirectory(WellKnownDirectory.ServerOMLegacy) - : HostContext.GetDirectory(WellKnownDirectory.ServerOM); - - string policyDllPath = Path.Combine(vstsomPath, "Microsoft.TeamFoundation.VersionControl.Controls.dll"); + string policyDllPath = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.ServerOM), "Microsoft.TeamFoundation.VersionControl.Controls.dll"); ArgUtil.File(policyDllPath, nameof(policyDllPath)); const string policyPathEnvKey = "TFVC_BUILDAGENT_POLICYPATH"; executionContext.Output(StringUtil.Loc("SetEnvVar", policyPathEnvKey)); diff --git a/src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs b/src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs index 92bc313d06..4ffb86d2ad 100644 --- a/src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs +++ b/src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs @@ -12,7 +12,6 @@ using Microsoft.VisualStudio.Services.WebApi; using System.Xml; using Microsoft.TeamFoundation.DistributedTask.Pipelines; -using Agent.Sdk.Knob; namespace Microsoft.VisualStudio.Services.Agent.Worker.Handlers { @@ -206,13 +205,8 @@ public async Task RunAsync() // Copy the OM binaries into the legacy host folder. ExecutionContext.Output(StringUtil.Loc("PrepareTaskExecutionHandler")); - - string sourceDirectory = AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean() - ? HostContext.GetDirectory(WellKnownDirectory.ServerOMLegacy) - : HostContext.GetDirectory(WellKnownDirectory.ServerOM); - IOUtil.CopyDirectory( - source: sourceDirectory, + source: HostContext.GetDirectory(WellKnownDirectory.ServerOM), target: HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost), cancellationToken: ExecutionContext.CancellationToken); Trace.Info("Finished copying files."); diff --git a/src/Agent.Worker/JobExtension.cs b/src/Agent.Worker/JobExtension.cs index df0f7a24c9..dbca02b449 100644 --- a/src/Agent.Worker/JobExtension.cs +++ b/src/Agent.Worker/JobExtension.cs @@ -269,11 +269,6 @@ public async Task> InitializeJob(IExecutionContext jobContext, Pipel } } - if (AgentKnobs.InstallLegacyTfExe.GetValue(jobContext).AsBoolean()) - { - await TfManager.DownloadLegacyTfToolsAsync(context); - } - // build up 3 lists of steps, pre-job, job, post-job Stack postJobStepsBuilder = new Stack(); Dictionary taskVariablesMapping = new Dictionary(); diff --git a/src/Agent.Worker/JobRunner.cs b/src/Agent.Worker/JobRunner.cs index 959834bff3..0a291a146a 100644 --- a/src/Agent.Worker/JobRunner.cs +++ b/src/Agent.Worker/JobRunner.cs @@ -177,11 +177,7 @@ public async Task RunAsync(Pipelines.AgentJobRequestMessage message, jobContext.SetVariable(Constants.Variables.Agent.RootDirectory, HostContext.GetDirectory(WellKnownDirectory.Work), isFilePath: true); if (PlatformUtil.RunningOnWindows) { - string serverOMDirectoryVariable = AgentKnobs.InstallLegacyTfExe.GetValue(jobContext).AsBoolean() - ? HostContext.GetDirectory(WellKnownDirectory.ServerOMLegacy) - : HostContext.GetDirectory(WellKnownDirectory.ServerOM); - - jobContext.SetVariable(Constants.Variables.Agent.ServerOMDirectory, serverOMDirectoryVariable, isFilePath: true); + jobContext.SetVariable(Constants.Variables.Agent.ServerOMDirectory, HostContext.GetDirectory(WellKnownDirectory.ServerOM), isFilePath: true); } if (!PlatformUtil.RunningOnWindows) { diff --git a/src/Agent.Worker/Release/ReleaseJobExtension.cs b/src/Agent.Worker/Release/ReleaseJobExtension.cs index ca09854472..9bc98baef7 100644 --- a/src/Agent.Worker/Release/ReleaseJobExtension.cs +++ b/src/Agent.Worker/Release/ReleaseJobExtension.cs @@ -229,11 +229,6 @@ private async Task DownloadArtifacts(IExecutionContext executionContext, await teeUtil.DownloadTeeIfAbsent(); } - if (AgentKnobs.InstallLegacyTfExe.GetValue(executionContext).AsBoolean()) - { - await TfManager.DownloadLegacyTfToolsAsync(executionContext); - } - try { foreach (AgentArtifactDefinition agentArtifactDefinition in agentArtifactDefinitions) diff --git a/src/Agent.Worker/TfManager.cs b/src/Agent.Worker/TfManager.cs deleted file mode 100644 index fdbbffa582..0000000000 --- a/src/Agent.Worker/TfManager.cs +++ /dev/null @@ -1,130 +0,0 @@ -using Microsoft.VisualStudio.Services.Agent.Util; -using System; -using System.IO; -using System.IO.Compression; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.VisualStudio.Services.Agent.Worker -{ - public interface IRetryOptions - { - int CurrentCount { get; set; } - int Limit { get; init; } - } - - public record RetryOptions : IRetryOptions - { - public int CurrentCount { get; set; } - public int Limit { get; init; } - } - - public static class TfManager - { - public static async Task DownloadLegacyTfToolsAsync(IExecutionContext executionContext) - { - ArgUtil.NotNull(executionContext, nameof(executionContext)); - string externalsPath = Path.Combine(executionContext.GetVariableValueOrDefault("Agent.HomeDirectory"), Constants.Path.ExternalsDirectory); - ArgUtil.NotNull(externalsPath, nameof(externalsPath)); - - string tfLegacyExternalsPath = Path.Combine(externalsPath, "tf-legacy"); - var retryOptions = new RetryOptions() { CurrentCount = 0, Limit = 3 }; - - if (!Directory.Exists(tfLegacyExternalsPath)) - { - const string tfDownloadUrl = "https://vstsagenttools.blob.core.windows.net/tools/vstsom/m153_47c0856d/vstsom.zip"; - string tempTfDirectory = Path.Combine(externalsPath, "tf_download_temp"); - - await DownloadAsync(executionContext, tfDownloadUrl, tempTfDirectory, tfLegacyExternalsPath, retryOptions); - } - else - { - executionContext.Debug($"tf-legacy download already exists at {tfLegacyExternalsPath}."); - } - - string vstsomLegacyExternalsPath = Path.Combine(externalsPath, "vstsom-legacy"); - - if (!Directory.Exists(vstsomLegacyExternalsPath)) - { - const string vstsomDownloadUrl = "https://vstsagenttools.blob.core.windows.net/tools/vstsom/m122_887c6659/vstsom.zip"; - string tempVstsomDirectory = Path.Combine(externalsPath, "vstsom_download_temp"); - - await DownloadAsync(executionContext, vstsomDownloadUrl, tempVstsomDirectory, vstsomLegacyExternalsPath, retryOptions); - } - else - { - executionContext.Debug($"vstsom-legacy download already exists at {vstsomLegacyExternalsPath}."); - } - } - - public static async Task DownloadAsync(IExecutionContext executionContext, string blobUrl, string tempDirectory, string extractPath, IRetryOptions retryOptions) - { - Directory.CreateDirectory(tempDirectory); - string downloadPath = Path.ChangeExtension(Path.Combine(tempDirectory, "download"), ".completed"); - string toolName = new DirectoryInfo(extractPath).Name; - - const int timeout = 180; - const int defaultFileStreamBufferSize = 4096; - const int retryDelay = 10000; - - try - { - using CancellationTokenSource downloadCts = new(TimeSpan.FromSeconds(timeout)); - using CancellationTokenSource linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(downloadCts.Token, executionContext.CancellationToken); - CancellationToken cancellationToken = linkedTokenSource.Token; - - using HttpClient httpClient = new(); - using Stream stream = await httpClient.GetStreamAsync(blobUrl, cancellationToken); - using FileStream fs = new(downloadPath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: defaultFileStreamBufferSize, useAsync: true); - - while (retryOptions.CurrentCount < retryOptions.Limit) - { - try - { - executionContext.Debug($"Retry options: {retryOptions.ToString()}."); - await stream.CopyToAsync(fs, cancellationToken); - executionContext.Debug($"Finished downloading {toolName}."); - await fs.FlushAsync(cancellationToken); - fs.Close(); - break; - } - catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) - { - executionContext.Debug($"{toolName} download has been cancelled."); - throw; - } - catch (Exception) - { - retryOptions.CurrentCount++; - - if (retryOptions.CurrentCount == retryOptions.Limit) - { - IOUtil.DeleteDirectory(tempDirectory, CancellationToken.None); - executionContext.Error($"Retry limit for {toolName} download has been exceeded."); - return; - } - - executionContext.Debug($"Failed to download {toolName}"); - executionContext.Debug($"Retry {toolName} download in 10 seconds."); - await Task.Delay(retryDelay, cancellationToken); - } - } - - executionContext.Debug($"Extracting {toolName}..."); - ZipFile.ExtractToDirectory(downloadPath, extractPath); - File.WriteAllText(downloadPath, DateTime.UtcNow.ToString()); - executionContext.Debug($"{toolName} has been extracted and cleaned up"); - } - catch (Exception ex) - { - executionContext.Error(ex); - } - finally - { - IOUtil.DeleteDirectory(tempDirectory, CancellationToken.None); - executionContext.Debug($"{toolName} download directory has been cleaned up."); - } - } - } -} diff --git a/src/Microsoft.VisualStudio.Services.Agent/Constants.cs b/src/Microsoft.VisualStudio.Services.Agent/Constants.cs index cb9fe38891..cca2a2a2a0 100644 --- a/src/Microsoft.VisualStudio.Services.Agent/Constants.cs +++ b/src/Microsoft.VisualStudio.Services.Agent/Constants.cs @@ -22,8 +22,6 @@ public enum WellKnownDirectory Tools, Update, Work, - TfLegacy, - ServerOMLegacy } public enum WellKnownConfigFile @@ -315,11 +313,9 @@ public static class Path public static readonly string ExternalsDirectory = "externals"; public static readonly string LegacyPSHostDirectory = "vstshost"; public static readonly string ServerOMDirectory = "vstsom"; - public static readonly string ServerOMLegacyDirectory = "vstsom-legacy"; public static readonly string TempDirectory = "_temp"; public static readonly string TeeDirectory = "tee"; public static readonly string TfDirectory = "tf"; - public static readonly string TfLegacyDirectory = "tf-legacy"; public static readonly string ToolDirectory = "_tool"; public static readonly string TaskJsonFile = "task.json"; public static readonly string TasksDirectory = "_tasks"; diff --git a/src/Microsoft.VisualStudio.Services.Agent/HostContext.cs b/src/Microsoft.VisualStudio.Services.Agent/HostContext.cs index d9766822f3..2cb0cacde0 100644 --- a/src/Microsoft.VisualStudio.Services.Agent/HostContext.cs +++ b/src/Microsoft.VisualStudio.Services.Agent/HostContext.cs @@ -206,24 +206,12 @@ public virtual string GetDirectory(WellKnownDirectory directory) Constants.Path.ServerOMDirectory); break; - case WellKnownDirectory.ServerOMLegacy: - path = Path.Combine( - GetDirectory(WellKnownDirectory.Externals), - Constants.Path.ServerOMLegacyDirectory); - break; - case WellKnownDirectory.Tf: path = Path.Combine( GetDirectory(WellKnownDirectory.Externals), Constants.Path.TfDirectory); break; - case WellKnownDirectory.TfLegacy: - path = Path.Combine( - GetDirectory(WellKnownDirectory.Externals), - Constants.Path.TfLegacyDirectory); - break; - case WellKnownDirectory.Tee: path = Path.Combine( GetDirectory(WellKnownDirectory.Externals), diff --git a/src/Misc/externals.sh b/src/Misc/externals.sh index 802997681f..26339cb73a 100644 --- a/src/Misc/externals.sh +++ b/src/Misc/externals.sh @@ -164,14 +164,14 @@ if [[ "$PACKAGERUNTIME" == "win-x"* ]]; then acquireExternalTool "$CONTAINER_URL/azcopy/1/azcopy.zip" azcopy acquireExternalTool "$CONTAINER_URL/vstshost/m122_887c6659/vstshost.zip" vstshost - acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d_adhoc/vstsom.zip" vstsom + acquireExternalTool "$CONTAINER_URL/vstsom/m122_887c6659/vstsom.zip" vstsom fi acquireExternalTool "$CONTAINER_URL/mingit/${MINGIT_VERSION}/MinGit-${MINGIT_VERSION}-${BIT}-bit.zip" git acquireExternalTool "$CONTAINER_URL/git-lfs/${LFS_VERSION}/x${BIT}/git-lfs.exe" "git/mingw${BIT}/bin" acquireExternalTool "$CONTAINER_URL/pdbstr/1/pdbstr.zip" pdbstr acquireExternalTool "$CONTAINER_URL/symstore/1/symstore.zip" symstore - acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d_adhoc/vstsom.zip" tf + acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d/vstsom.zip" tf acquireExternalTool "$CONTAINER_URL/vswhere/2_8_4/vswhere.zip" vswhere acquireExternalTool "https://dist.nuget.org/win-x86-commandline/v3.4.4/nuget.exe" nuget diff --git a/src/Test/L0/ServiceInterfacesL0.cs b/src/Test/L0/ServiceInterfacesL0.cs index ba4b4f057e..f7c8162132 100644 --- a/src/Test/L0/ServiceInterfacesL0.cs +++ b/src/Test/L0/ServiceInterfacesL0.cs @@ -99,8 +99,7 @@ public void WorkerInterfacesSpecifyDefaultImplementation() typeof(IResultReader), typeof(INUnitResultsXmlReader), typeof(IWorkerCommand), - typeof(ITaskRestrictionsChecker), - typeof(IRetryOptions) + typeof(ITaskRestrictionsChecker) }; Validate( assembly: typeof(IStepsRunner).GetTypeInfo().Assembly, diff --git a/src/Test/L0/TestHostContext.cs b/src/Test/L0/TestHostContext.cs index d677add5f6..37c25cf393 100644 --- a/src/Test/L0/TestHostContext.cs +++ b/src/Test/L0/TestHostContext.cs @@ -211,24 +211,12 @@ public string GetDirectory(WellKnownDirectory directory) Constants.Path.ServerOMDirectory); break; - case WellKnownDirectory.ServerOMLegacy: - path = Path.Combine( - GetDirectory(WellKnownDirectory.Externals), - Constants.Path.ServerOMLegacyDirectory); - break; - case WellKnownDirectory.Tf: path = Path.Combine( GetDirectory(WellKnownDirectory.Externals), Constants.Path.TfDirectory); break; - case WellKnownDirectory.TfLegacy: - path = Path.Combine( - GetDirectory(WellKnownDirectory.Externals), - Constants.Path.TfLegacyDirectory); - break; - case WellKnownDirectory.Tee: path = Path.Combine( GetDirectory(WellKnownDirectory.Externals), diff --git a/src/Test/L0/Worker/TfManagerL0.cs b/src/Test/L0/Worker/TfManagerL0.cs deleted file mode 100644 index 5cb4ace3a6..0000000000 --- a/src/Test/L0/Worker/TfManagerL0.cs +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.VisualStudio.Services.Agent.Util; -using Microsoft.VisualStudio.Services.Agent.Worker; -using Moq; -using Xunit; - -namespace Microsoft.VisualStudio.Services.Agent.Tests.Worker -{ - public sealed class TfManagerL0 - { - private const string VstsomLegacy = "vstsom-legacy"; - private const string TfLegacy = "tf-legacy"; - - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Worker")] - public async Task DownloadTfLegacyToolsAsync() - { - // Arrange - using var tokenSource = new CancellationTokenSource(); - using var hostContext = new TestHostContext(this); - var executionContext = new Mock(); - - executionContext.Setup(x => x.CancellationToken).Returns(tokenSource.Token); - executionContext.Setup(x => x.GetVariableValueOrDefault(It.Is(s => s == "Agent.HomeDirectory"))) - .Returns(hostContext.GetDirectory(WellKnownDirectory.Root)); - - string externalsPath = hostContext.GetDirectory(WellKnownDirectory.Externals); - string tfPath = Path.Combine(externalsPath, TfLegacy); - string vstsomPath = Path.Combine(externalsPath, VstsomLegacy); - - // Act - await TfManager.DownloadLegacyTfToolsAsync(executionContext.Object); - - // Assert - Assert.True(Directory.Exists(tfPath)); - Assert.True(File.Exists(Path.Combine(tfPath, "TF.exe"))); - Assert.False(Directory.Exists(Path.Combine(externalsPath, "tf_download_temp"))); - - Assert.True(Directory.Exists(vstsomPath)); - Assert.True(File.Exists(Path.Combine(vstsomPath, "TF.exe"))); - Assert.False(Directory.Exists(Path.Combine(externalsPath, "vstsom_download_temp"))); - - // Cleanup - IOUtil.DeleteDirectory(tfPath, CancellationToken.None); - IOUtil.DeleteDirectory(vstsomPath, CancellationToken.None); - } - - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Worker")] - public async Task DownloadAsync_Retries() - { - // Arrange - using var tokenSource = new CancellationTokenSource(); - using var hostContext = new TestHostContext(this); - var executionContext = new Mock(); - - executionContext.Setup(x => x.CancellationToken).Returns(tokenSource.Token); - executionContext.Setup(x => x.GetVariableValueOrDefault(It.Is(s => s == "Agent.HomeDirectory"))) - .Returns(hostContext.GetDirectory(WellKnownDirectory.Root)); - - var retryOptions = new Mock(); - retryOptions.SetupProperty(opt => opt.CurrentCount); - retryOptions.Setup(opt => opt.ToString()).Throws(); - retryOptions.Setup(opt => opt.Limit).Returns(3); - - const string downloadUrl = "https://vstsagenttools.blob.core.windows.net/tools/vstsom/m122_887c6659/vstsom.zip"; - string tempDirectory = Path.Combine(hostContext.GetDirectory(WellKnownDirectory.Externals), "temp-test"); - string extractDirectory = Path.Combine(hostContext.GetDirectory(WellKnownDirectory.Externals), "test"); - - // Act - await TfManager.DownloadAsync(executionContext.Object, downloadUrl, tempDirectory, extractDirectory, retryOptions.Object); - - // Assert - Assert.False(Directory.Exists(tempDirectory)); - Assert.False(Directory.Exists(extractDirectory)); - retryOptions.VerifySet(opt => opt.CurrentCount = It.IsAny(), Times.Exactly(3)); - } - - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Worker")] - public async Task DownloadAsync_Cancellation() - { - // Arrange - using var tokenSource = new CancellationTokenSource(); - using var hostContext = new TestHostContext(this); - var executionContext = new Mock(); - - executionContext.Setup(x => x.CancellationToken).Returns(tokenSource.Token); - executionContext.Setup(x => x.GetVariableValueOrDefault(It.Is(s => s == "Agent.HomeDirectory"))) - .Returns(hostContext.GetDirectory(WellKnownDirectory.Root)); - - var retryOptions = new Mock(); - retryOptions.SetupProperty(opt => opt.CurrentCount); - retryOptions.Setup(opt => opt.ToString()).Callback(() => tokenSource.Cancel()); - retryOptions.Setup(opt => opt.Limit).Returns(3); - - const string downloadUrl = "https://vstsagenttools.blob.core.windows.net/tools/vstsom/m122_887c6659/vstsom.zip"; - string tempDirectory = Path.Combine(hostContext.GetDirectory(WellKnownDirectory.Externals), "temp-test"); - string extractDirectory = Path.Combine(hostContext.GetDirectory(WellKnownDirectory.Externals), "test"); - - // Act - await TfManager.DownloadAsync(executionContext.Object, downloadUrl, tempDirectory, extractDirectory, retryOptions.Object); - - // Assert - Assert.False(Directory.Exists(tempDirectory)); - Assert.False(Directory.Exists(extractDirectory)); - retryOptions.VerifySet(opt => opt.CurrentCount = It.IsAny(), Times.Never()); - } - } -}