Skip to content

Commit 3ac6082

Browse files
committed
Simplified log checking
Removed sorting that was likely to result in flaky results. There is only one way the agent log makes sense and the output is still checked.
1 parent 54e01d5 commit 3ac6082

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/test/java/org/jenkinsci/plugins/github_branch_source/GithubAppCredentialsTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.time.format.DateTimeFormatter;
2525
import java.time.temporal.ChronoUnit;
2626
import java.util.ArrayList;
27+
import java.util.Collections;
2728
import java.util.Comparator;
2829
import java.util.Date;
2930
import 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

Comments
 (0)