2424import java .time .format .DateTimeFormatter ;
2525import java .time .temporal .ChronoUnit ;
2626import java .util .ArrayList ;
27+ import java .util .Collections ;
2728import java .util .Comparator ;
2829import java .util .Date ;
2930import java .util .List ;
@@ -215,6 +216,8 @@ public void testAgentRefresh() throws Exception {
215216 //Verify correct messages from GitHubAppCredential logger indicating token was retrieved on agent
216217 assertThat ("Creds should cache on master, pass to agent, and refresh agent from master once" ,
217218 credentialsLog , contains (
219+ // (agent log added out of order, see below)
220+ "Keeping cached GitHub App Installation Token for app ID 54321 on agent: token is stale but has not expired" ,
218221 // node ('my-agent') {
219222 "Generating App Installation Token for app ID 54321" ,
220223 "Token will become stale after 15 seconds" ,
@@ -232,15 +235,15 @@ credentialsLog, contains(
232235 // (error forced by wiremock - failed refresh on the agent)
233236 "Generating App Installation Token for app ID 54321 for agent" ,
234237 "Failed to retrieve GitHub App installation token for app ID 54321" ,
235- "Keeping cached GitHub App Installation Token for app ID 54321 on agent: token is stale but has not expired" ,
238+ // (agent log added out of order) "Keeping cached GitHub App Installation Token for app ID 54321 on agent: token is stale but has not expired",
236239 // checkout scm - refresh on controller
237240 "Generating App Installation Token for app ID 54321" ,
238241 "Token will become stale after 15 seconds" ,
239242 "Generated App Installation Token for app ID 54321" ,
240243 "Retrieved GitHub App Installation Token for app ID 54321"
241244 // checkout scm
242245 // (No token generation)
243- ));
246+ ));
244247 } finally {
245248 GitHubAppCredentials .AppInstallationToken .NOT_STALE_MINIMUM_SECONDS = notStaleSeconds ;
246249 logRecorder .doClear ();
@@ -251,9 +254,8 @@ private List<String> getOutputLines() {
251254 final Formatter formatter = new SimpleFormatter ();
252255 List <LogRecord > result = new ArrayList <>(logRecorder .getLogRecords ());
253256 result .addAll (logRecorder .getSlaveLogRecords ().get (agent .toComputer ()));
257+ Collections .reverse (result );
254258 return result .stream ()
255- // order by millis maintaining sequence within milli
256- .sorted (Comparator .comparingLong (record -> record .getMillis () * 100L + record .getSequenceNumber ()))
257259 .map (formatter ::formatMessage )
258260 .collect (Collectors .toList ());
259261 }
0 commit comments