From 4f8c069bf321d7c17783d5bfac3dcb62ff7a39b8 Mon Sep 17 00:00:00 2001 From: JoannaaKL Date: Wed, 5 Oct 2022 08:39:58 +0000 Subject: [PATCH] Do not fail service containers without the healthcheck --- .../ContainerOperationProvider.cs | 14 +++++++------- .../L0/Worker/ContainerOperationProviderL0.cs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Runner.Worker/ContainerOperationProvider.cs b/src/Runner.Worker/ContainerOperationProvider.cs index 2fc597308..0dd7aa126 100644 --- a/src/Runner.Worker/ContainerOperationProvider.cs +++ b/src/Runner.Worker/ContainerOperationProvider.cs @@ -110,7 +110,7 @@ namespace GitHub.Runner.Worker { var healthcheck = await ContainerHealthcheck(executionContext, container); - if (!string.Equals(healthcheck, "healthy", StringComparison.OrdinalIgnoreCase)) + if (!(string.Equals(healthcheck, "healthy", StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(healthcheck))) { unhealthyContainers.Add(container); } @@ -330,13 +330,13 @@ namespace GitHub.Runner.Worker { if (!container.IsJobContainer && !container.FailedInitialization) { - executionContext.Output($"Print service container logs: {container.ContainerDisplayName}"); + executionContext.Output($"Print service container logs: {container.ContainerDisplayName}"); - int logsExitCode = await _dockerManager.DockerLogs(executionContext, container.ContainerId); - if (logsExitCode != 0) - { - executionContext.Warning($"Docker logs fail with exit code {logsExitCode}"); - } + int logsExitCode = await _dockerManager.DockerLogs(executionContext, container.ContainerId); + if (logsExitCode != 0) + { + executionContext.Warning($"Docker logs fail with exit code {logsExitCode}"); + } } executionContext.Output($"Stop and remove container: {container.ContainerDisplayName}"); diff --git a/src/Test/L0/Worker/ContainerOperationProviderL0.cs b/src/Test/L0/Worker/ContainerOperationProviderL0.cs index bfc09f343..e0819511b 100644 --- a/src/Test/L0/Worker/ContainerOperationProviderL0.cs +++ b/src/Test/L0/Worker/ContainerOperationProviderL0.cs @@ -23,6 +23,7 @@ namespace GitHub.Runner.Common.Tests.Worker private Mock serverQueue; private Mock pagingLogger; private List healthyDockerStatus = new List { "healthy" }; + private List emptyDockerStatus = new List { string.Empty }; private List unhealthyDockerStatus = new List { "unhealthy" }; private List dockerLogs = new List { "log1", "log2", "log3" }; @@ -81,6 +82,23 @@ namespace GitHub.Runner.Common.Tests.Worker } + [Fact] + [Trait("Level", "L0")] + [Trait("Category", "Worker")] + public async void RunServiceContainersHealthcheck_healthyServiceContainerWithoutHealthcheck_AssertSucceededTask() + { + //Arrange + Setup(); + _dockerManager.Setup(x => x.DockerInspect(_ec.Object, It.IsAny(), It.IsAny())).Returns(Task.FromResult(emptyDockerStatus)); + + //Act + await containerOperationProvider.RunContainersHealthcheck(_ec.Object, containers); + + //Assert + Assert.Equal(TaskResult.Succeeded, _ec.Object.Result ?? TaskResult.Succeeded); + + } + private void Setup([CallerMemberName] string testName = "") { containers.Add(new ContainerInfo() { ContainerImage = "ubuntu:16.04" });