Skip to content

Commit

Permalink
Merge pull request #214 from superboum/master
Browse files Browse the repository at this point in the history
[JENKINS-37185] Honor checkout timeout
  • Loading branch information
MarkEWaite committed Aug 6, 2016
2 parents 00731f9 + 742861e commit ea305aa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
Expand Up @@ -1976,7 +1976,9 @@ public void execute() throws GitException, InterruptedException {

if (branch!=null && deleteBranch) {
// First, checkout to detached HEAD, so we can delete the branch.
launchCommand("checkout", "-f", ref);
ArgumentListBuilder args = new ArgumentListBuilder();
args.add("checkout", "-f", ref);
launchCommandIn(args, workspace, environment, timeout);

// Second, check to see if the branch actually exists, and then delete it if it does.
for (Branch b : getBranches()) {
Expand Down
46 changes: 41 additions & 5 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java
Expand Up @@ -71,6 +71,7 @@
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import java.util.Iterator;

/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
Expand Down Expand Up @@ -388,7 +389,6 @@ private void checkTimeout() {
}
} else {
assertEquals("Wrong timeout count", expectedTimeouts.size(), timeouts.size());
timeouts = expectedTimeouts;
}
assertEquals("Wrong timeout", expectedTimeouts, timeouts);
}
Expand Down Expand Up @@ -474,7 +474,24 @@ private void setExpectedTimeoutWithAdjustedEnd(final int newTimeout, int adjustm
setExpectedTimeouts(expected);
}
}

private void setExpectedTimeoutAtPositions(Map<Integer, Integer> newTimeouts) {
if (getTimeoutVisibleInCurrentTest()) {
int size = handler.getTimeouts().size();
List<Integer> expected = new ArrayList<Integer>(size);
for (int i = 0; i < size; i++) {
expected.add(i, CliGitAPIImpl.TIMEOUT);
}

Iterator<Map.Entry<Integer, Integer>> entries = newTimeouts.entrySet().iterator();
while(entries.hasNext()) {
Map.Entry<Integer, Integer> entry = entries.next();
Integer position = entry.getKey();
Integer newTimeout = entry.getValue();
expected.set(position, newTimeout);
}
setExpectedTimeouts(expected);
}
}
/** Clone arguments include:
* repositoryName(String) - if omitted, CliGit does not set a remote repo name
* shallow() - no relevant assertion of success or failure of this argument
Expand All @@ -497,7 +514,9 @@ public void test_clone() throws Exception
assertFalse("Alternates file found: " + alternates, w.exists(alternates));
assertFalse("Unexpected shallow clone", w.cgit().isShallowRepository());

setExpectedTimeoutWithAdjustedEnd(newTimeout);
Map timeouts = new HashMap<Integer, Integer>();
timeouts.put(2, newTimeout);
setExpectedTimeoutAtPositions(timeouts);
}

public void test_checkout_exception() throws Exception {
Expand Down Expand Up @@ -2062,7 +2081,7 @@ public void test_trackingSubmoduleBranches() throws Exception {
assertFalse("file2 exists and should not because not on 'branch1'", w.exists(subFile2));
assertFalse("file3 exists and should not because not on 'branch2'", w.exists(subFile3));

setExpectedTimeoutWithAdjustedEnd(newTimeout, 2);
setExpectedTimeoutWithAdjustedEnd(newTimeout, 1);
}

@NotImplementedInJGit
Expand Down Expand Up @@ -2119,7 +2138,10 @@ public void test_sparse_checkout() throws Exception {
assertTrue(workingArea.exists("dir2"));
assertTrue(workingArea.exists("dir3"));

setExpectedTimeoutWithAdjustedEnd(newTimeout);
Map timeouts = new HashMap<Integer, Integer>();
timeouts.put(28, newTimeout);
timeouts.put(31, newTimeout);
setExpectedTimeoutAtPositions(timeouts);
}

public void test_clone_no_checkout() throws Exception {
Expand Down Expand Up @@ -3387,6 +3409,20 @@ public void test_checkout() throws Exception {
assertEquals("Wrong SHA1 as checkout of git-client-1.6.0", sha1Expected, sha1);
}

@Bug(37185)
@NotImplementedInJGit /* JGit doesn't have timeout */
public void test_checkout_honor_timeout() throws Exception {
w = clone(localMirror());

int newTimeout = 7;
w.git.checkout().branch("master").ref("origin/master").timeout(newTimeout).deleteBranchIfExist(true).execute();

Map timeouts = new HashMap<Integer, Integer>();
timeouts.put(1, newTimeout);
timeouts.put(4, newTimeout);
setExpectedTimeoutAtPositions(timeouts);
}

@Bug(25353)
@NotImplementedInJGit /* JGit lock file management ignored for now */
public void test_checkout_interrupted() throws Exception {
Expand Down

0 comments on commit ea305aa

Please sign in to comment.