From 0db908da8de2de9a52d280b0ec0d8b4ee8ba30b8 Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Wed, 5 Feb 2020 16:56:38 -0500 Subject: [PATCH] Use authenticate endpoint for testing runner connection. (#311) * use authenticate endpoint for testing runner connection. * PR feedback. --- src/Runner.Listener/Configuration/ConfigurationManager.cs | 5 ++++- src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Runner.Listener/Configuration/ConfigurationManager.cs b/src/Runner.Listener/Configuration/ConfigurationManager.cs index 15440b911..8195aecbf 100644 --- a/src/Runner.Listener/Configuration/ConfigurationManager.cs +++ b/src/Runner.Listener/Configuration/ConfigurationManager.cs @@ -277,12 +277,15 @@ namespace GitHub.Runner.Listener.Configuration throw new NotSupportedException("Message queue listen OAuth token."); } - // Testing agent connection, detect any protential connection issue, like local clock skew that cause OAuth token expired. + // Testing agent connection, detect any potential connection issue, like local clock skew that cause OAuth token expired. var credMgr = HostContext.GetService(); VssCredentials credential = credMgr.LoadCredentials(); try { await _runnerServer.ConnectAsync(new Uri(runnerSettings.ServerUrl), credential); + // ConnectAsync() hits _apis/connectionData which is an anonymous endpoint + // Need to hit an authenticate endpoint to trigger OAuth token exchange. + await _runnerServer.GetAgentPoolsAsync(); _term.WriteSuccessMessage("Runner connection is good"); } catch (VssOAuthTokenRequestException ex) when (ex.Message.Contains("Current server time is")) diff --git a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs index 08b1ec625..e9d054353 100644 --- a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs +++ b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs @@ -175,8 +175,8 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration Assert.True(s.PoolId.Equals(_expectedPoolId)); Assert.True(s.WorkFolder.Equals(_expectedWorkFolder)); - // validate GetAgentPoolsAsync gets called once with automation pool type - _runnerServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny(), It.Is(p => p == TaskAgentPoolType.Automation)), Times.Once); + // validate GetAgentPoolsAsync gets called twice with automation pool type + _runnerServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny(), It.Is(p => p == TaskAgentPoolType.Automation)), Times.Exactly(2)); _runnerServer.Verify(x => x.AddAgentAsync(It.IsAny(), It.Is(a => a.Labels.Contains("self-hosted") && a.Labels.Contains(VarUtil.OS) && a.Labels.Contains(VarUtil.OSArchitecture))), Times.Once); }