Skip to content

Commit

Permalink
Test for JENKINS-32258
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEWaite committed Jan 3, 2016
1 parent 3139a94 commit 3a8d219
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java
Expand Up @@ -87,6 +87,12 @@ public abstract class GitAPITestCase extends TestCase {
private static final String LOGGING_STARTED = "Logging started";

private static final String SRC_DIR = (new File(".")).getAbsolutePath();
private String revParseBranchName = null;

private void createRevParseBranch() throws GitException, InterruptedException {
revParseBranchName = "rev-parse-branch-" + UUID.randomUUID().toString();
w.git.checkout("origin/master", revParseBranchName);
}

/**
* One local workspace of a Git repository on a temporary directory
Expand Down Expand Up @@ -306,6 +312,7 @@ protected void setExpectedTimeouts(List<Integer> timeouts) {

@Override
protected void setUp() throws Exception {
revParseBranchName = null;
setTimeoutVisibleInCurrentTest(true);
expectedTimeouts = null;
Logger logger = Logger.getLogger(this.getClass().getPackage().getName() + "-" + logCount++);
Expand Down Expand Up @@ -351,6 +358,20 @@ public String localMirror() throws IOException, InterruptedException {
throw new IllegalStateException();
}

/* JENKINS-33258 detected many calls to git rev-parse. This checks
* those calls are not being made. The createRevParseBranch call
* creates a branch whose name is unknown to the tests. This
* checks that the branch name is not mentioned in a call to
* git rev-parse.
*/
private void checkRevParseCalls(String branchName) {
String messages = StringUtils.join(handler.getMessages(), ";");
// Linux uses rev-parse without quotes
assertFalse("git rev-parse called: " + messages, handler.containsMessageSubstring("rev-parse " + branchName));
// Windows quotes the rev-parse argument
assertFalse("git rev-parse called: " + messages, handler.containsMessageSubstring("rev-parse \"" + branchName));
}

private void checkTimeout() {
List<Integer> timeouts = handler.getTimeouts();
if (expectedTimeouts == null) {
Expand Down Expand Up @@ -380,6 +401,9 @@ protected void tearDown() throws Exception {
if (getTimeoutVisibleInCurrentTest()) {
checkTimeout();
}
if (revParseBranchName != null) {
checkRevParseCalls(revParseBranchName);
}
} finally {
handler.close();
}
Expand Down Expand Up @@ -458,6 +482,7 @@ public void test_clone() throws IOException, InterruptedException
{
int newTimeout = 7;
w.git.clone_().timeout(newTimeout).url(localMirror()).repositoryName("origin").execute();
createRevParseBranch(); // Verify JENKINS-32258 is fixed
w.git.checkout("origin/master", "master");
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "master");
Expand All @@ -480,6 +505,7 @@ public void test_clone_repositoryName() throws IOException, InterruptedException
public void test_clone_shallow() throws IOException, InterruptedException
{
w.git.clone_().url(localMirror()).repositoryName("origin").shallow().execute();
createRevParseBranch(); // Verify JENKINS-32258 is fixed
w.git.checkout("origin/master", "master");
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "master");
Expand All @@ -500,6 +526,7 @@ public void test_clone_shallow_with_depth() throws IOException, InterruptedExcep
public void test_clone_shared() throws IOException, InterruptedException
{
w.git.clone_().url(localMirror()).repositoryName("origin").shared().execute();
createRevParseBranch(); // Verify JENKINS-32258 is fixed
w.git.checkout("origin/master", "master");
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "master");
Expand All @@ -510,6 +537,7 @@ public void test_clone_shared() throws IOException, InterruptedException
public void test_clone_reference() throws IOException, InterruptedException
{
w.git.clone_().url(localMirror()).repositoryName("origin").reference(localMirror()).execute();
createRevParseBranch(); // Verify JENKINS-32258 is fixed
w.git.checkout("origin/master", "master");
check_remote_url("origin");
assertBranchesExist(w.git.getBranches(), "master");
Expand Down

0 comments on commit 3a8d219

Please sign in to comment.