Skip to content

Commit

Permalink
Add some waits to stabilize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Jan 21, 2021
1 parent 772a3c2 commit 2c442d3
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ public void testProviderRefresh() throws Exception {
// Must set this to a large enough number to avoid flaky test
GitHubAppCredentials.AppInstallationToken.NOT_STALE_MINIMUM_SECONDS = 5;

// Ensure we are working from sufficiently clean cache state
Thread.sleep(Duration.ofSeconds(GitHubAppCredentials.AppInstallationToken.NOT_STALE_MINIMUM_SECONDS + 2).toMillis());

AuthorizationProvider provider = appCredentials.getAuthorizationProvider();
GitHub githubInstance = createGitHubBuilder(githubApi.baseUrl())
.withAuthorizationProvider(provider).build();
Expand Down Expand Up @@ -311,6 +314,9 @@ public void testAgentRefresh() throws Exception {
// Must set this to a large enough number to avoid flaky test
GitHubAppCredentials.AppInstallationToken.NOT_STALE_MINIMUM_SECONDS = 5;

// Ensure we are working from sufficiently clean cache state
Thread.sleep(Duration.ofSeconds(GitHubAppCredentials.AppInstallationToken.NOT_STALE_MINIMUM_SECONDS + 2).toMillis());

final String gitCheckoutStep = String.format(
" git url: REPO, credentialsId: '%s'",
myAppCredentialsId);
Expand Down Expand Up @@ -353,7 +359,6 @@ public void testAgentRefresh() throws Exception {
r.waitUntilNoActivity();

System.out.println(JenkinsRule.getLog(run));
assertThat(run.getResult(), equalTo(Result.SUCCESS));

List<String> credentialsLog = getOutputLines();

Expand Down Expand Up @@ -392,6 +397,10 @@ credentialsLog, contains(
// checkout scm
// (No token generation)
));

// Check success after output. Output will be more informative if something goes wrong.
assertThat(run.getResult(), equalTo(Result.SUCCESS));

} finally {
GitHubAppCredentials.AppInstallationToken.NOT_STALE_MINIMUM_SECONDS = notStaleSeconds;
logRecorder.doClear();
Expand Down

0 comments on commit 2c442d3

Please sign in to comment.