diff --git a/src/Runner.Common/JobServerQueue.cs b/src/Runner.Common/JobServerQueue.cs index c1425b80721..9c27bf51d0e 100644 --- a/src/Runner.Common/JobServerQueue.cs +++ b/src/Runner.Common/JobServerQueue.cs @@ -19,7 +19,7 @@ public interface IJobServerQueue : IRunnerService, IThrottlingReporter TaskCompletionSource JobRecordUpdated { get; } event EventHandler JobServerQueueThrottling; Task ShutdownAsync(); - void Start(Pipelines.AgentJobRequestMessage jobRequest, bool resultsServiceOnly = false, bool enableTelemetry = false); + void Start(Pipelines.AgentJobRequestMessage jobRequest, bool resultsServiceOnly = false); void QueueWebConsoleLine(Guid stepRecordId, string line, long? lineNumber = null); void QueueFileUpload(Guid timelineId, Guid timelineRecordId, string type, string name, string path, bool deleteSource); void QueueResultsUpload(Guid timelineRecordId, string name, string path, string type, bool deleteSource, bool finalize, bool firstBlock, long totalLines); @@ -104,11 +104,10 @@ public override void Initialize(IHostContext hostContext) _resultsServer = hostContext.GetService(); } - public void Start(Pipelines.AgentJobRequestMessage jobRequest, bool resultsServiceOnly = false, bool enableTelemetry = false) + public void Start(Pipelines.AgentJobRequestMessage jobRequest, bool resultsServiceOnly = false) { Trace.Entering(); _resultsServiceOnly = resultsServiceOnly; - _enableTelemetry = enableTelemetry; var serviceEndPoint = jobRequest.Resources.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); @@ -139,6 +138,12 @@ public void Start(Pipelines.AgentJobRequestMessage jobRequest, bool resultsServi _resultsClientInitiated = true; } + // Enable telemetry if we have both results service and actions service + if (_resultsClientInitiated && !_resultsServiceOnly) + { + _enableTelemetry = true; + } + if (_queueInProcess) { Trace.Info("No-opt, all queue process tasks are running."); diff --git a/src/Runner.Sdk/Util/WhichUtil.cs b/src/Runner.Sdk/Util/WhichUtil.cs index fde4fa2f6a9..ef7683a2d8f 100644 --- a/src/Runner.Sdk/Util/WhichUtil.cs +++ b/src/Runner.Sdk/Util/WhichUtil.cs @@ -7,129 +7,6 @@ namespace GitHub.Runner.Sdk public static class WhichUtil { public static string Which(string command, bool require = false, ITraceWriter trace = null, string prependPath = null) - { - ArgUtil.NotNullOrEmpty(command, nameof(command)); - trace?.Info($"Which: '{command}'"); - if (Path.IsPathFullyQualified(command) && File.Exists(command)) - { - trace?.Info($"Fully qualified path: '{command}'"); - return command; - } - string path = Environment.GetEnvironmentVariable(PathUtil.PathVariable); - if (string.IsNullOrEmpty(path)) - { - trace?.Info("PATH environment variable not defined."); - path = path ?? string.Empty; - } - if (!string.IsNullOrEmpty(prependPath)) - { - path = PathUtil.PrependPath(prependPath, path); - } - - string[] pathSegments = path.Split(new Char[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries); - for (int i = 0; i < pathSegments.Length; i++) - { - pathSegments[i] = Environment.ExpandEnvironmentVariables(pathSegments[i]); - } - - foreach (string pathSegment in pathSegments) - { - if (!string.IsNullOrEmpty(pathSegment) && Directory.Exists(pathSegment)) - { - string[] matches = null; -#if OS_WINDOWS - string pathExt = Environment.GetEnvironmentVariable("PATHEXT"); - if (string.IsNullOrEmpty(pathExt)) - { - // XP's system default value for PATHEXT system variable - pathExt = ".com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh"; - } - - string[] pathExtSegments = pathExt.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); - - // if command already has an extension. - if (pathExtSegments.Any(ext => command.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) - { - try - { - matches = Directory.GetFiles(pathSegment, command); - } - catch (UnauthorizedAccessException ex) - { - trace?.Info("Ignore UnauthorizedAccess exception during Which."); - trace?.Verbose(ex.ToString()); - } - - if (matches != null && matches.Length > 0 && IsPathValid(matches.First(), trace)) - { - trace?.Info($"Location: '{matches.First()}'"); - return matches.First(); - } - } - else - { - string searchPattern; - searchPattern = StringUtil.Format($"{command}.*"); - try - { - matches = Directory.GetFiles(pathSegment, searchPattern); - } - catch (UnauthorizedAccessException ex) - { - trace?.Info("Ignore UnauthorizedAccess exception during Which."); - trace?.Verbose(ex.ToString()); - } - - if (matches != null && matches.Length > 0) - { - // add extension. - for (int i = 0; i < pathExtSegments.Length; i++) - { - string fullPath = Path.Combine(pathSegment, $"{command}{pathExtSegments[i]}"); - if (matches.Any(p => p.Equals(fullPath, StringComparison.OrdinalIgnoreCase)) && IsPathValid(fullPath, trace)) - { - trace?.Info($"Location: '{fullPath}'"); - return fullPath; - } - } - } - } -#else - try - { - matches = Directory.GetFiles(pathSegment, command); - } - catch (UnauthorizedAccessException ex) - { - trace?.Info("Ignore UnauthorizedAccess exception during Which."); - trace?.Verbose(ex.ToString()); - } - - if (matches != null && matches.Length > 0 && IsPathValid(matches.First(), trace)) - { - trace?.Info($"Location: '{matches.First()}'"); - return matches.First(); - } -#endif - } - } - -#if OS_WINDOWS - trace?.Info($"{command}: command not found. Make sure '{command}' is installed and its location included in the 'Path' environment variable."); -#else - trace?.Info($"{command}: command not found. Make sure '{command}' is installed and its location included in the 'PATH' environment variable."); -#endif - if (require) - { - throw new FileNotFoundException( - message: $"{command}: command not found", - fileName: command); - } - - return null; - } - - public static string Which2(string command, bool require = false, ITraceWriter trace = null, string prependPath = null) { ArgUtil.NotNullOrEmpty(command, nameof(command)); trace?.Info($"Which2: '{command}'"); diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 0dd891c1765..227e7f4a5e6 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -797,43 +797,40 @@ private async Task DownloadRepositoryActionAsync(IExecutionContext executionCont try { var useActionArchiveCache = false; - if (executionContext.Global.Variables.GetBoolean("DistributedTask.UseActionArchiveCache") == true) + var hasActionArchiveCache = false; + var actionArchiveCacheDir = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ActionArchiveCacheDirectory); + if (!string.IsNullOrEmpty(actionArchiveCacheDir) && + Directory.Exists(actionArchiveCacheDir)) { - var hasActionArchiveCache = false; - var actionArchiveCacheDir = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ActionArchiveCacheDirectory); - if (!string.IsNullOrEmpty(actionArchiveCacheDir) && - Directory.Exists(actionArchiveCacheDir)) - { - hasActionArchiveCache = true; - Trace.Info($"Check if action archive '{downloadInfo.ResolvedNameWithOwner}@{downloadInfo.ResolvedSha}' already exists in cache directory '{actionArchiveCacheDir}'"); + hasActionArchiveCache = true; + Trace.Info($"Check if action archive '{downloadInfo.ResolvedNameWithOwner}@{downloadInfo.ResolvedSha}' already exists in cache directory '{actionArchiveCacheDir}'"); #if OS_WINDOWS - var cacheArchiveFile = Path.Combine(actionArchiveCacheDir, downloadInfo.ResolvedNameWithOwner.Replace(Path.DirectorySeparatorChar, '_').Replace(Path.AltDirectorySeparatorChar, '_'), $"{downloadInfo.ResolvedSha}.zip"); + var cacheArchiveFile = Path.Combine(actionArchiveCacheDir, downloadInfo.ResolvedNameWithOwner.Replace(Path.DirectorySeparatorChar, '_').Replace(Path.AltDirectorySeparatorChar, '_'), $"{downloadInfo.ResolvedSha}.zip"); #else - var cacheArchiveFile = Path.Combine(actionArchiveCacheDir, downloadInfo.ResolvedNameWithOwner.Replace(Path.DirectorySeparatorChar, '_').Replace(Path.AltDirectorySeparatorChar, '_'), $"{downloadInfo.ResolvedSha}.tar.gz"); + var cacheArchiveFile = Path.Combine(actionArchiveCacheDir, downloadInfo.ResolvedNameWithOwner.Replace(Path.DirectorySeparatorChar, '_').Replace(Path.AltDirectorySeparatorChar, '_'), $"{downloadInfo.ResolvedSha}.tar.gz"); #endif - if (File.Exists(cacheArchiveFile)) + if (File.Exists(cacheArchiveFile)) + { + try { - try - { - Trace.Info($"Found action archive '{cacheArchiveFile}' in cache directory '{actionArchiveCacheDir}'"); - File.Copy(cacheArchiveFile, archiveFile); - useActionArchiveCache = true; - executionContext.Debug($"Copied action archive '{cacheArchiveFile}' to '{archiveFile}'"); - } - catch (Exception ex) - { - Trace.Error($"Failed to copy action archive '{cacheArchiveFile}' to '{archiveFile}'. Error: {ex}"); - } + Trace.Info($"Found action archive '{cacheArchiveFile}' in cache directory '{actionArchiveCacheDir}'"); + File.Copy(cacheArchiveFile, archiveFile); + useActionArchiveCache = true; + executionContext.Debug($"Copied action archive '{cacheArchiveFile}' to '{archiveFile}'"); + } + catch (Exception ex) + { + Trace.Error($"Failed to copy action archive '{cacheArchiveFile}' to '{archiveFile}'. Error: {ex}"); } } - - executionContext.Global.JobTelemetry.Add(new JobTelemetry() - { - Type = JobTelemetryType.General, - Message = $"Action archive cache usage: {downloadInfo.ResolvedNameWithOwner}@{downloadInfo.ResolvedSha} use cache {useActionArchiveCache} has cache {hasActionArchiveCache}" - }); } + executionContext.Global.JobTelemetry.Add(new JobTelemetry() + { + Type = JobTelemetryType.General, + Message = $"Action archive cache usage: {downloadInfo.ResolvedNameWithOwner}@{downloadInfo.ResolvedSha} use cache {useActionArchiveCache} has cache {hasActionArchiveCache}" + }); + if (!useActionArchiveCache) { await DownloadRepositoryArchive(executionContext, link, downloadInfo.Authentication?.Token, archiveFile); @@ -879,16 +876,9 @@ private async Task DownloadRepositoryActionAsync(IExecutionContext executionCont int exitCode = await processInvoker.ExecuteAsync(stagingDirectory, tar, $"-xzf \"{archiveFile}\"", null, executionContext.CancellationToken); if (exitCode != 0) { - if (executionContext.Global.Variables.GetBoolean("DistributedTask.DetailUntarFailure") == true) - { - var fileInfo = new FileInfo(archiveFile); - var sha256hash = await IOUtil.GetFileContentSha256HashAsync(archiveFile); - throw new InvalidActionArchiveException($"Can't use 'tar -xzf' extract archive file: {archiveFile} (SHA256 '{sha256hash}', size '{fileInfo.Length}' bytes, tar outputs '{string.Join(' ', tarOutputs)}'). Action being checked out: {downloadInfo.NameWithOwner}@{downloadInfo.Ref}. return code: {exitCode}."); - } - else - { - throw new InvalidActionArchiveException($"Can't use 'tar -xzf' extract archive file: {archiveFile}. Action being checked out: {downloadInfo.NameWithOwner}@{downloadInfo.Ref}. return code: {exitCode}."); - } + var fileInfo = new FileInfo(archiveFile); + var sha256hash = await IOUtil.GetFileContentSha256HashAsync(archiveFile); + throw new InvalidActionArchiveException($"Can't use 'tar -xzf' extract archive file: {archiveFile} (SHA256 '{sha256hash}', size '{fileInfo.Length}' bytes, tar outputs '{string.Join(' ', tarOutputs)}'). Action being checked out: {downloadInfo.NameWithOwner}@{downloadInfo.Ref}. return code: {exitCode}."); } } #endif diff --git a/src/Runner.Worker/Handlers/ScriptHandler.cs b/src/Runner.Worker/Handlers/ScriptHandler.cs index 30114f27c33..e6fa90a0a11 100644 --- a/src/Runner.Worker/Handlers/ScriptHandler.cs +++ b/src/Runner.Worker/Handlers/ScriptHandler.cs @@ -83,40 +83,19 @@ protected override void PrintActionDetails(ActionRunStage stage) shellCommand = "pwsh"; if (validateShellOnHost) { - if (ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseWhich2") == true) - { - shellCommandPath = WhichUtil.Which2(shellCommand, require: false, Trace, prependPath); - } - else - { - shellCommandPath = WhichUtil.Which(shellCommand, require: false, Trace, prependPath); - } + shellCommandPath = WhichUtil.Which(shellCommand, require: false, Trace, prependPath); if (string.IsNullOrEmpty(shellCommandPath)) { shellCommand = "powershell"; - Trace.Info($"Defaulting to {shellCommand}"); - if (ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseWhich2") == true) - { - shellCommandPath = WhichUtil.Which2(shellCommand, require: true, Trace, prependPath); - } - else - { - shellCommandPath = WhichUtil.Which(shellCommand, require: true, Trace, prependPath); - } + Trace.Info($"Defaulting to {shellCommand}"); + shellCommandPath = WhichUtil.Which(shellCommand, require: true, Trace, prependPath); } } #else shellCommand = "sh"; if (validateShellOnHost) { - if (ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseWhich2") == true) - { - shellCommandPath = WhichUtil.Which2("bash", false, Trace, prependPath) ?? WhichUtil.Which2("sh", true, Trace, prependPath); - } - else - { - shellCommandPath = WhichUtil.Which("bash", false, Trace, prependPath) ?? WhichUtil.Which("sh", true, Trace, prependPath); - } + shellCommandPath = WhichUtil.Which("bash", false, Trace, prependPath) ?? WhichUtil.Which("sh", true, Trace, prependPath); } #endif argFormat = ScriptHandlerHelpers.GetScriptArgumentsFormat(shellCommand); @@ -127,14 +106,7 @@ protected override void PrintActionDetails(ActionRunStage stage) shellCommand = parsed.shellCommand; if (validateShellOnHost) { - if (ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseWhich2") == true) - { - shellCommandPath = WhichUtil.Which2(parsed.shellCommand, true, Trace, prependPath); - } - else - { - shellCommandPath = WhichUtil.Which(parsed.shellCommand, true, Trace, prependPath); - } + shellCommandPath = WhichUtil.Which(parsed.shellCommand, true, Trace, prependPath); } argFormat = $"{parsed.shellArgs}".TrimStart(); @@ -216,38 +188,17 @@ public async Task RunAsync(ActionRunStage stage) { #if OS_WINDOWS shellCommand = "pwsh"; - if (ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseWhich2") == true) - { - commandPath = WhichUtil.Which2(shellCommand, require: false, Trace, prependPath); - } - else - { - commandPath = WhichUtil.Which(shellCommand, require: false, Trace, prependPath); - } + commandPath = WhichUtil.Which(shellCommand, require: false, Trace, prependPath); if (string.IsNullOrEmpty(commandPath)) { shellCommand = "powershell"; Trace.Info($"Defaulting to {shellCommand}"); - if (ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseWhich2") == true) - { - commandPath = WhichUtil.Which2(shellCommand, require: true, Trace, prependPath); - } - else - { - commandPath = WhichUtil.Which(shellCommand, require: true, Trace, prependPath); - } + commandPath = WhichUtil.Which(shellCommand, require: true, Trace, prependPath); } ArgUtil.NotNullOrEmpty(commandPath, "Default Shell"); #else shellCommand = "sh"; - if (ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseWhich2") == true) - { - commandPath = WhichUtil.Which2("bash", false, Trace, prependPath) ?? WhichUtil.Which2("sh", true, Trace, prependPath); - } - else - { - commandPath = WhichUtil.Which("bash", false, Trace, prependPath) ?? WhichUtil.Which("sh", true, Trace, prependPath); - } + commandPath = WhichUtil.Which("bash", false, Trace, prependPath) ?? WhichUtil.Which("sh", true, Trace, prependPath); #endif argFormat = ScriptHandlerHelpers.GetScriptArgumentsFormat(shellCommand); } @@ -258,14 +209,7 @@ public async Task RunAsync(ActionRunStage stage) if (!IsActionStep && systemShells.Contains(shell)) { shellCommand = shell; - if (ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseWhich2") == true) - { - commandPath = WhichUtil.Which2(shell, !isContainerStepHost, Trace, prependPath); - } - else - { - commandPath = WhichUtil.Which(shell, !isContainerStepHost, Trace, prependPath); - } + commandPath = WhichUtil.Which(shell, !isContainerStepHost, Trace, prependPath); if (shell == "bash") { argFormat = ScriptHandlerHelpers.GetScriptArgumentsFormat("sh"); @@ -280,14 +224,7 @@ public async Task RunAsync(ActionRunStage stage) var parsed = ScriptHandlerHelpers.ParseShellOptionString(shell); shellCommand = parsed.shellCommand; // For non-ContainerStepHost, the command must be located on the host by Which - if (ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseWhich2") == true) - { - commandPath = WhichUtil.Which2(parsed.shellCommand, !isContainerStepHost, Trace, prependPath); - } - else - { - commandPath = WhichUtil.Which(parsed.shellCommand, !isContainerStepHost, Trace, prependPath); - } + commandPath = WhichUtil.Which(parsed.shellCommand, !isContainerStepHost, Trace, prependPath); argFormat = $"{parsed.shellArgs}".TrimStart(); if (string.IsNullOrEmpty(argFormat)) { diff --git a/src/Runner.Worker/JobRunner.cs b/src/Runner.Worker/JobRunner.cs index 69ebed556c2..d6e18e8324b 100644 --- a/src/Runner.Worker/JobRunner.cs +++ b/src/Runner.Worker/JobRunner.cs @@ -54,13 +54,6 @@ public async Task RunAsync(AgentJobRequestMessage message, Cancellat VssUtil.InitializeVssClientSettings(HostContext.UserAgents, HostContext.WebProxy); } - var jobServerQueueTelemetry = false; - if (message.Variables.TryGetValue("DistributedTask.EnableJobServerQueueTelemetry", out VariableValue enableJobServerQueueTelemetry) && - !string.IsNullOrEmpty(enableJobServerQueueTelemetry?.Value)) - { - jobServerQueueTelemetry = StringUtil.ConvertToBoolean(enableJobServerQueueTelemetry.Value); - } - ServiceEndpoint systemConnection = message.Resources.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); if (MessageUtil.IsRunServiceJob(message.MessageType)) { @@ -82,7 +75,7 @@ public async Task RunAsync(AgentJobRequestMessage message, Cancellat launchServer.InitializeLaunchClient(new Uri(launchReceiverEndpoint), accessToken); } _jobServerQueue = HostContext.GetService(); - _jobServerQueue.Start(message, resultsServiceOnly: true, enableTelemetry: jobServerQueueTelemetry); + _jobServerQueue.Start(message, resultsServiceOnly: true); } else { @@ -104,7 +97,7 @@ public async Task RunAsync(AgentJobRequestMessage message, Cancellat VssConnection jobConnection = VssUtil.CreateConnection(jobServerUrl, jobServerCredential, delegatingHandlers); await jobServer.ConnectAsync(jobConnection); - _jobServerQueue.Start(message, enableTelemetry: jobServerQueueTelemetry); + _jobServerQueue.Start(message); server = jobServer; } diff --git a/src/Test/L0/Util/WhichUtilL0.cs b/src/Test/L0/Util/WhichUtilL0.cs index 90d32c466a6..9a6443d1fff 100644 --- a/src/Test/L0/Util/WhichUtilL0.cs +++ b/src/Test/L0/Util/WhichUtilL0.cs @@ -212,210 +212,5 @@ public void WhichThrowsWhenSymlinkBroken() File.Delete(brokenSymlink); Environment.SetEnvironmentVariable(PathUtil.PathVariable, oldValue); } - - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Common")] - public void UseWhich2FindGit() - { - using (TestHostContext hc = new(this)) - { - //Arrange - Tracing trace = hc.GetTrace(); - - // Act. - string gitPath = WhichUtil.Which2("git", trace: trace); - - trace.Info($"Which(\"git\") returns: {gitPath ?? string.Empty}"); - - // Assert. - Assert.True(!string.IsNullOrEmpty(gitPath) && File.Exists(gitPath), $"Unable to find Git through: {nameof(WhichUtil.Which)}"); - } - } - - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Common")] - public void Which2ReturnsNullWhenNotFound() - { - using (TestHostContext hc = new(this)) - { - //Arrange - Tracing trace = hc.GetTrace(); - - // Act. - string nosuch = WhichUtil.Which2("no-such-file-cf7e351f", trace: trace); - - trace.Info($"result: {nosuch ?? string.Empty}"); - - // Assert. - Assert.True(string.IsNullOrEmpty(nosuch), "Path should not be resolved"); - } - } - - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Common")] - public void Which2ThrowsWhenRequireAndNotFound() - { - using (TestHostContext hc = new(this)) - { - //Arrange - Tracing trace = hc.GetTrace(); - - // Act. - try - { - WhichUtil.Which2("no-such-file-cf7e351f", require: true, trace: trace); - throw new Exception("which should have thrown"); - } - catch (FileNotFoundException ex) - { - Assert.Equal("no-such-file-cf7e351f", ex.FileName); - } - } - } - - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Common")] - public void Which2HandleFullyQualifiedPath() - { - using (TestHostContext hc = new(this)) - { - //Arrange - Tracing trace = hc.GetTrace(); - - // Act. - var gitPath = WhichUtil.Which2("git", require: true, trace: trace); - var gitPath2 = WhichUtil.Which2(gitPath, require: true, trace: trace); - - // Assert. - Assert.Equal(gitPath, gitPath2); - } - } - - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Common")] - public void Which2HandlesSymlinkToTargetFullPath() - { - // Arrange - using TestHostContext hc = new TestHostContext(this); - Tracing trace = hc.GetTrace(); - string oldValue = Environment.GetEnvironmentVariable(PathUtil.PathVariable); -#if OS_WINDOWS - string newValue = oldValue + @$";{Path.GetTempPath()}"; - string symlinkName = $"symlink-{Guid.NewGuid()}"; - string symlink = Path.GetTempPath() + $"{symlinkName}.exe"; - string target = Path.GetTempPath() + $"target-{Guid.NewGuid()}.exe"; -#else - string newValue = oldValue + @$":{Path.GetTempPath()}"; - string symlinkName = $"symlink-{Guid.NewGuid()}"; - string symlink = Path.GetTempPath() + $"{symlinkName}"; - string target = Path.GetTempPath() + $"target-{Guid.NewGuid()}"; -#endif - - Environment.SetEnvironmentVariable(PathUtil.PathVariable, newValue); - - - using (File.Create(target)) - { - File.CreateSymbolicLink(symlink, target); - - // Act. - var result = WhichUtil.Which2(symlinkName, require: true, trace: trace); - - // Assert - Assert.True(!string.IsNullOrEmpty(result) && File.Exists(result), $"Unable to find symlink through: {nameof(WhichUtil.Which)}"); - - } - - - // Cleanup - File.Delete(symlink); - File.Delete(target); - Environment.SetEnvironmentVariable(PathUtil.PathVariable, oldValue); - - } - - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Common")] - public void Which2HandlesSymlinkToTargetRelativePath() - { - // Arrange - using TestHostContext hc = new TestHostContext(this); - Tracing trace = hc.GetTrace(); - string oldValue = Environment.GetEnvironmentVariable(PathUtil.PathVariable); -#if OS_WINDOWS - string newValue = oldValue + @$";{Path.GetTempPath()}"; - string symlinkName = $"symlink-{Guid.NewGuid()}"; - string symlink = Path.GetTempPath() + $"{symlinkName}.exe"; - string targetName = $"target-{Guid.NewGuid()}.exe"; - string target = Path.GetTempPath() + targetName; -#else - string newValue = oldValue + @$":{Path.GetTempPath()}"; - string symlinkName = $"symlink-{Guid.NewGuid()}"; - string symlink = Path.GetTempPath() + $"{symlinkName}"; - string targetName = $"target-{Guid.NewGuid()}"; - string target = Path.GetTempPath() + targetName; -#endif - Environment.SetEnvironmentVariable(PathUtil.PathVariable, newValue); - - - using (File.Create(target)) - { - File.CreateSymbolicLink(symlink, targetName); - - // Act. - var result = WhichUtil.Which2(symlinkName, require: true, trace: trace); - - // Assert - Assert.True(!string.IsNullOrEmpty(result) && File.Exists(result), $"Unable to find {symlinkName} through: {nameof(WhichUtil.Which)}"); - } - - // Cleanup - File.Delete(symlink); - File.Delete(target); - Environment.SetEnvironmentVariable(PathUtil.PathVariable, oldValue); - - } - [Fact] - [Trait("Level", "L0")] - [Trait("Category", "Common")] - public void Which2ThrowsWhenSymlinkBroken() - { - // Arrange - using TestHostContext hc = new TestHostContext(this); - Tracing trace = hc.GetTrace(); - string oldValue = Environment.GetEnvironmentVariable(PathUtil.PathVariable); - -#if OS_WINDOWS - string newValue = oldValue + @$";{Path.GetTempPath()}"; - string brokenSymlinkName = $"broken-symlink-{Guid.NewGuid()}"; - string brokenSymlink = Path.GetTempPath() + $"{brokenSymlinkName}.exe"; -#else - string newValue = oldValue + @$":{Path.GetTempPath()}"; - string brokenSymlinkName = $"broken-symlink-{Guid.NewGuid()}"; - string brokenSymlink = Path.GetTempPath() + $"{brokenSymlinkName}"; -#endif - - - string target = "no-such-file-cf7e351f"; - Environment.SetEnvironmentVariable(PathUtil.PathVariable, newValue); - - File.CreateSymbolicLink(brokenSymlink, target); - - // Act. - var exception = Assert.Throws(() => WhichUtil.Which2(brokenSymlinkName, require: true, trace: trace)); - - // Assert - Assert.Equal(brokenSymlinkName, exception.FileName); - - // Cleanup - File.Delete(brokenSymlink); - Environment.SetEnvironmentVariable(PathUtil.PathVariable, oldValue); - } } } diff --git a/src/Test/L0/Worker/ActionManagerL0.cs b/src/Test/L0/Worker/ActionManagerL0.cs index c487ea55ef1..d4430d91128 100644 --- a/src/Test/L0/Worker/ActionManagerL0.cs +++ b/src/Test/L0/Worker/ActionManagerL0.cs @@ -382,8 +382,6 @@ public async void PrepareActions_DownloadActionFromGraph_UseCache() } }; - _ec.Object.Global.Variables.Set("DistributedTask.UseActionArchiveCache", bool.TrueString); - //Act await _actionManager.PrepareActionsAsync(_ec.Object, actions);