Skip to content

Commit

Permalink
Use waitForMessage instead of assertLogContains
Browse files Browse the repository at this point in the history
Jesse Glick noted that some flaky pipeline tests in other plugins
could be resolved by switching from assertLogContains to
waitForMessage. Since the git plugin has shown a tendency to flaky
tests on Windows, let's use Jesse's recommendation as well.

See jenkinsci/bom#110 (comment)
  • Loading branch information
MarkEWaite committed Apr 10, 2020
1 parent cc56808 commit 5d1b932
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void checkoutWithValidCredentials() throws Exception {
+ " )"
+ "}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("using credential github", b);
r.waitForMessage("using credential github", b);
}

@Issue("JENKINS-30515")
Expand All @@ -78,7 +78,7 @@ public void checkoutWithDifferentCredentials() throws Exception {
+ " )"
+ "}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("Warning: CredentialId \"github\" could not be found", b);
r.waitForMessage("Warning: CredentialId \"github\" could not be found", b);
}

@Issue("JENKINS-30515")
Expand All @@ -97,7 +97,7 @@ public void checkoutWithInvalidCredentials() throws Exception {
+ " )"
+ "}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("Warning: CredentialId \"github\" could not be found", b);
r.waitForMessage("Warning: CredentialId \"github\" could not be found", b);
}

@Issue("JENKINS-30515")
Expand All @@ -114,7 +114,7 @@ public void checkoutWithNoCredentialsStoredButUsed() throws Exception {
+ " )"
+ "}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("Warning: CredentialId \"github\" could not be found", b);
r.waitForMessage("Warning: CredentialId \"github\" could not be found", b);
}

@Issue("JENKINS-30515")
Expand All @@ -131,7 +131,7 @@ public void checkoutWithNoCredentialsSpecified() throws Exception {
+ " )"
+ "}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("No credentials specified", b);
r.waitForMessage("No credentials specified", b);
}


Expand Down
10 changes: 5 additions & 5 deletions src/test/java/hudson/plugins/git/GitSCMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1119,19 +1119,19 @@ public void testEnvVarsAvailable() throws Exception {
FreeStyleBuild build1 = build(project, Result.SUCCESS, commitFile1);

assertEquals("origin/master", getEnvVars(project).get(GitSCM.GIT_BRANCH));
rule.assertLogContains(getEnvVars(project).get(GitSCM.GIT_BRANCH), build1);
rule.waitForMessage(getEnvVars(project).get(GitSCM.GIT_BRANCH), build1);

rule.assertLogContains(checkoutString(project, GitSCM.GIT_COMMIT), build1);
rule.waitForMessage(checkoutString(project, GitSCM.GIT_COMMIT), build1);

final String commitFile2 = "commitFile2";
commit(commitFile2, johnDoe, "Commit number 2");
FreeStyleBuild build2 = build(project, Result.SUCCESS, commitFile2);

rule.assertLogNotContains(checkoutString(project, GitSCM.GIT_PREVIOUS_COMMIT), build2);
rule.assertLogContains(checkoutString(project, GitSCM.GIT_PREVIOUS_COMMIT), build1);
rule.waitForMessage(checkoutString(project, GitSCM.GIT_PREVIOUS_COMMIT), build1);

rule.assertLogNotContains(checkoutString(project, GitSCM.GIT_PREVIOUS_SUCCESSFUL_COMMIT), build2);
rule.assertLogContains(checkoutString(project, GitSCM.GIT_PREVIOUS_SUCCESSFUL_COMMIT), build1);
rule.waitForMessage(checkoutString(project, GitSCM.GIT_PREVIOUS_SUCCESSFUL_COMMIT), build1);
}

@Issue("HUDSON-7411")
Expand Down Expand Up @@ -2140,7 +2140,7 @@ public void testCheckoutFailureIsRetryable() throws Exception {
try {
FileUtils.touch(lock);
final FreeStyleBuild build2 = build(project, Result.FAILURE);
rule.assertLogContains("java.io.IOException: Could not checkout", build2);
rule.waitForMessage("java.io.IOException: Could not checkout", build2);
} finally {
lock.delete();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/hudson/plugins/git/GitStatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ private void doNotifyCommitWithDefaultParameter(final boolean allowed, String sa

FreeStyleBuild build = project.scheduleBuild2(0, new Cause.UserCause()).get();

jenkins.assertLogContains("aaa aaaccc ccc", build);
jenkins.waitForMessage("aaa aaaccc ccc", build);

String extraValue = "An-extra-value";
when(requestWithParameter.getParameterMap()).thenReturn(setupParameterMap(extraValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public void checkoutTimeout() throws Exception {
+ " )"
+ "}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("# timeout=1234", b);
r.waitForMessage("# timeout=1234", b);
}
}
10 changes: 5 additions & 5 deletions src/test/java/jenkins/plugins/git/GitStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public void basicCloneAndUpdate() throws Exception {
" }\n" +
"}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("Cloning the remote Git repository", b); // GitSCM.retrieveChanges
r.waitForMessage("Cloning the remote Git repository", b); // GitSCM.retrieveChanges
assertTrue(b.getArtifactManager().root().child("file").isFile());
sampleRepo.write("nextfile", "");
sampleRepo.git("add", "nextfile");
sampleRepo.git("commit", "--message=next");
b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("Fetching changes from the remote Git repository", b); // GitSCM.retrieveChanges
r.waitForMessage("Fetching changes from the remote Git repository", b); // GitSCM.retrieveChanges
assertTrue(b.getArtifactManager().root().child("nextfile").isFile());
}

Expand All @@ -123,14 +123,14 @@ public void changelogAndPolling() throws Exception {
" }\n" +
"}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("Cloning the remote Git repository", b);
r.waitForMessage("Cloning the remote Git repository", b);
sampleRepo.write("nextfile", "");
sampleRepo.git("add", "nextfile");
sampleRepo.git("commit", "--message=next");
sampleRepo.notifyCommit(r);
b = p.getLastBuild();
assertEquals(2, b.number);
r.assertLogContains("Fetching changes from the remote Git repository", b);
r.waitForMessage("Fetching changes from the remote Git repository", b);
List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets();
assertEquals(1, changeSets.size());
ChangeLogSet<? extends ChangeLogSet.Entry> changeSet = changeSets.get(0);
Expand Down Expand Up @@ -254,7 +254,7 @@ public void commitToWorkspace() throws Exception {
" rungit 'show master'\n" +
"}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("+edited by build", b);
r.waitForMessage("+edited by build", b);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ protected FreeStyleProject configureGitTagMessageJob(String refSpec, String bran
protected void assertBuildEnvironment(FreeStyleBuild build, String expectedName, String expectedMessage)
throws Exception {
// In the freestyle shell step, unknown environment variables are returned as empty strings
jenkins.assertLogContains(String.format("tag='%s'", Util.fixNull(expectedName)), build);
jenkins.assertLogContains(String.format("msg='%s'", Util.fixNull(expectedMessage)), build);
jenkins.waitForMessage(String.format("tag='%s'", Util.fixNull(expectedName)), build);
jenkins.waitForMessage(String.format("msg='%s'", Util.fixNull(expectedMessage)), build);
}

private static Builder createEnvEchoBuilder(String key, String envVarName) {
Expand Down

0 comments on commit 5d1b932

Please sign in to comment.