Skip to content

Commit

Permalink
Merge pull request #85 from stephenc/jenkins-42000
Browse files Browse the repository at this point in the history
[JENKINS-42000] Communication errors in organization scanning should not delete all everything
  • Loading branch information
stephenc committed Feb 14, 2017
2 parents 0178b37 + 0205467 commit 76313ec
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.19</version>
<version>2.22</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -66,7 +66,7 @@

<properties>
<jenkins.version>1.642.3</jenkins.version>
<scm-api.version>2.0.3</scm-api.version>
<scm-api.version>2.0.4</scm-api.version>
</properties>

<repositories>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/jenkins/branch/OrganizationFolder.java
Expand Up @@ -1194,7 +1194,7 @@ private boolean recognizes(Map<String, Object> attributes, MultiBranchProjectFac
}

@Override
public void complete() throws IllegalStateException, InterruptedException {
public void complete() throws IllegalStateException, IOException, InterruptedException {
try {
MultiBranchProjectFactory factory = null;
Map<String, Object> attributes = Collections.<String, Object>emptyMap();
Expand Down Expand Up @@ -1257,7 +1257,7 @@ public void complete() throws IllegalStateException, InterruptedException {
}
observer.created(project);
project.scheduleBuild();
} catch (InterruptedException x) {
} catch (InterruptedException | IOException x) {
throw x;
} catch (Exception x) {
x.printStackTrace(listener.error("Failed to create or update a subproject " + projectName));
Expand Down
107 changes: 107 additions & 0 deletions src/test/java/integration/EventsTest.java
Expand Up @@ -1203,6 +1203,113 @@ public void given_orgFolder_when_someReposMatch_then_scanCreatesMatchingProjects
}
}

@Test
@Issue("JENKINS-42000")
public void given_orgFolder_when_navigatorIoErrorScanning_then_scanRecordedAsFailure() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getProjectFactories().replaceBy(Collections
.singletonList(new BasicMultiBranchProjectFactory(new BasicSCMSourceCriteria("marker.txt"))));
c.createRepository("foo");
c.createRepository("bar");
c.createRepository("manchu");
c.addFile("foo", "master", "adding marker", "marker.txt", "A marker".getBytes());
c.addFile("bar", "master", "adding marker", "marker.txt", "A marker".getBytes());
c.addFile("manchu", "master", "adding marker", "marker.txt", "A marker".getBytes());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getComputation().getResult(), is(Result.SUCCESS));
assertThat("A scan picks up a newly qualified repo",
prj.getItems(),
not(is((Collection<MultiBranchProject<?, ?>>) Collections.<MultiBranchProject<?, ?>>emptyList())));
BasicMultiBranchProject foo = (BasicMultiBranchProject) prj.getItem("foo");
BasicMultiBranchProject bar = (BasicMultiBranchProject) prj.getItem("bar");
BasicMultiBranchProject manchu = (BasicMultiBranchProject) prj.getItem("manchu");
assertThat("We now have the `foo` project", foo, notNullValue());
assertThat("We now have the `bar` project", bar, notNullValue());
assertThat("We now have the `manchu` project", manchu, notNullValue());
assertThat("We now have only the projects expected",
prj.getItems(),
Matchers.<MultiBranchProject<?, ?>>containsInAnyOrder(foo, bar, manchu));
c.addFault(new MockFailure() {
@Override
public void check(@CheckForNull String repository, @CheckForNull String branchOrCR,
@CheckForNull String revision,
boolean actions) throws IOException {
if ("bar".equals(repository) && branchOrCR == null && revision == null && !actions) {
throw new IOException("Boom Boom Boom!!!");
}
}
});
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getComputation().getResult(), is(Result.FAILURE));
foo = (BasicMultiBranchProject) prj.getItem("foo");
bar = (BasicMultiBranchProject) prj.getItem("bar");
manchu = (BasicMultiBranchProject) prj.getItem("manchu");
assertThat("We now have the `foo` project", foo, notNullValue());
assertThat("We now have the `bar` project", bar, notNullValue());
assertThat("We now have the `manchu` project", manchu, notNullValue());
assertThat("We now have only the projects expected",
prj.getItems(),
Matchers.<MultiBranchProject<?, ?>>containsInAnyOrder(foo, bar, manchu));
}
}

@Test
@Issue("JENKINS-42000")
public void given_orgFolder_when_sourceIoErrorScanning_then_scanRecordedAsFailure() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
OrganizationFolder prj = r.jenkins.createProject(OrganizationFolder.class, "foo");
prj.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
prj.getProjectFactories().replaceBy(Collections
.singletonList(new BasicMultiBranchProjectFactory(new BasicSCMSourceCriteria("marker.txt"))));
c.createRepository("foo");
c.createRepository("bar");
c.createRepository("manchu");
c.addFile("foo", "master", "adding marker", "marker.txt", "A marker".getBytes());
c.addFile("bar", "master", "adding marker", "marker.txt", "A marker".getBytes());
c.addFile("manchu", "master", "adding marker", "marker.txt", "A marker".getBytes());
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat("A scan picks up a newly qualified repo",
prj.getItems(),
not(is((Collection<MultiBranchProject<?, ?>>) Collections.<MultiBranchProject<?, ?>>emptyList())));
BasicMultiBranchProject foo = (BasicMultiBranchProject) prj.getItem("foo");
BasicMultiBranchProject bar = (BasicMultiBranchProject) prj.getItem("bar");
BasicMultiBranchProject manchu = (BasicMultiBranchProject) prj.getItem("manchu");
assertThat("We now have the `foo` project", foo, notNullValue());
assertThat("We now have the `bar` project", bar, notNullValue());
assertThat("We now have the `manchu` project", manchu, notNullValue());
assertThat("We now have only the projects expected",
prj.getItems(),
Matchers.<MultiBranchProject<?, ?>>containsInAnyOrder(foo, bar, manchu));
c.addFault(new MockFailure() {
@Override
public void check(@CheckForNull String repository, @CheckForNull String branchOrCR,
@CheckForNull String revision,
boolean actions) throws IOException {
if ("bar".equals(repository) && branchOrCR != null && revision == null && !actions) {
throw new IOException("Boom Boom Boom!!!");
}
}
});
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(prj.getComputation().getResult(), is(Result.FAILURE));
foo = (BasicMultiBranchProject) prj.getItem("foo");
bar = (BasicMultiBranchProject) prj.getItem("bar");
manchu = (BasicMultiBranchProject) prj.getItem("manchu");
assertThat("We now have the `foo` project", foo, notNullValue());
assertThat("We now have the `bar` project", bar, notNullValue());
assertThat("We now have the `manchu` project", manchu, notNullValue());
assertThat("We now have only the projects expected",
prj.getItems(),
Matchers.<MultiBranchProject<?, ?>>containsInAnyOrder(foo, bar, manchu));
}
}

@Test
public void given_orgFolder_when_someReposMatch_then_eventCreatesMatchingProject() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
Expand Down

0 comments on commit 76313ec

Please sign in to comment.