Skip to content

Commit 0db908d

Browse files
authored
Use authenticate endpoint for testing runner connection. (#311)
* use authenticate endpoint for testing runner connection. * PR feedback.
1 parent 68de3a9 commit 0db908d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Runner.Listener/Configuration/ConfigurationManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,15 @@ public async Task ConfigureAsync(CommandSettings command)
277277
throw new NotSupportedException("Message queue listen OAuth token.");
278278
}
279279

280-
// Testing agent connection, detect any protential connection issue, like local clock skew that cause OAuth token expired.
280+
// Testing agent connection, detect any potential connection issue, like local clock skew that cause OAuth token expired.
281281
var credMgr = HostContext.GetService<ICredentialManager>();
282282
VssCredentials credential = credMgr.LoadCredentials();
283283
try
284284
{
285285
await _runnerServer.ConnectAsync(new Uri(runnerSettings.ServerUrl), credential);
286+
// ConnectAsync() hits _apis/connectionData which is an anonymous endpoint
287+
// Need to hit an authenticate endpoint to trigger OAuth token exchange.
288+
await _runnerServer.GetAgentPoolsAsync();
286289
_term.WriteSuccessMessage("Runner connection is good");
287290
}
288291
catch (VssOAuthTokenRequestException ex) when (ex.Message.Contains("Current server time is"))

src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ public async Task CanEnsureConfigure()
175175
Assert.True(s.PoolId.Equals(_expectedPoolId));
176176
Assert.True(s.WorkFolder.Equals(_expectedWorkFolder));
177177

178-
// validate GetAgentPoolsAsync gets called once with automation pool type
179-
_runnerServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny<string>(), It.Is<TaskAgentPoolType>(p => p == TaskAgentPoolType.Automation)), Times.Once);
178+
// validate GetAgentPoolsAsync gets called twice with automation pool type
179+
_runnerServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny<string>(), It.Is<TaskAgentPoolType>(p => p == TaskAgentPoolType.Automation)), Times.Exactly(2));
180180

181181
_runnerServer.Verify(x => x.AddAgentAsync(It.IsAny<int>(), It.Is<TaskAgent>(a => a.Labels.Contains("self-hosted") && a.Labels.Contains(VarUtil.OS) && a.Labels.Contains(VarUtil.OSArchitecture))), Times.Once);
182182
}

0 commit comments

Comments
 (0)