Skip to content

Commit

Permalink
stabilize test (#313)
Browse files Browse the repository at this point in the history
kill the long running sleep jobs at the end to ensure file handles are closed on windows. Otherwise post test cleanup might fail.
  • Loading branch information
mawinter69 authored Jul 7, 2023
1 parent 4390a15 commit e141973
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1C</forkCount>
<forkCount>0.75C</forkCount>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.User;
import hudson.model.queue.QueueTaskFuture;
import jenkins.model.Jenkins;
import org.htmlunit.Page;
import org.htmlunit.html.HtmlPage;
Expand Down Expand Up @@ -77,6 +78,7 @@ public void testExecutorsPath() throws Exception {
final HtmlPage htmlPage = webClient.goTo("computer/(master)/executors/" + number + "/currentExecutable/");
final String contentAsString = htmlPage.getWebResponse().getContentAsString();
assertThat(contentAsString, not(containsString(BUILD_CONTENT))); // Fails while unfixed
build.doStop();
}

@Test
Expand All @@ -88,12 +90,13 @@ public void testExecutorsContent() throws Exception {
job.getBuildersList().add(new SleepBuilder(10000));
job.save();

job.scheduleBuild2(0, new Cause.UserIdCause("admin")).waitForStart();
FreeStyleBuild build = job.scheduleBuild2(0, new Cause.UserIdCause("admin")).waitForStart();

final JenkinsRule.WebClient webClient = jenkinsRule.createWebClient();
final Page page = webClient.goTo("computer/(master)/api/xml?depth=1", "application/xml");
final String xml = page.getWebResponse().getContentAsString();
assertThat(xml, not(containsString("job/folder/job/job"))); // Fails while unfixed
build.doStop();
}

@Test
Expand All @@ -105,15 +108,17 @@ public void testWidgets() throws Exception {
job.getBuildersList().add(new SleepBuilder(100000));
job.save();

job.scheduleBuild2(0, new Cause.UserIdCause("admin")).waitForStart(); // schedule one build now
job.scheduleBuild2(0, new Cause.UserIdCause("admin")); // schedule an additional queue item
FreeStyleBuild b1 = job.scheduleBuild2(0, new Cause.UserIdCause("admin")).waitForStart(); // schedule one build now
QueueTaskFuture<?> f2 = job.scheduleBuild2(0, new Cause.UserIdCause("admin")); // schedule an additional queue item
Assert.assertEquals(1, Jenkins.get().getQueue().getItems().length); // expect there to be one queue item

final JenkinsRule.WebClient webClient = jenkinsRule.createWebClient().withThrowExceptionOnFailingStatusCode(false);

final HtmlPage htmlPage = webClient.goTo("");
final String contentAsString = htmlPage.getWebResponse().getContentAsString();
assertThat(contentAsString, not(containsString("job/folder/job/job"))); // Fails while unfixed
f2.cancel(true);
b1.doStop();
}

@Test
Expand All @@ -135,36 +140,36 @@ public void testEscapeHatch() throws Exception {

final JenkinsRule.WebClient webClient = jenkinsRule.createWebClient().withThrowExceptionOnFailingStatusCode(false);

{ // queue related assertions
final HtmlPage htmlPage = webClient.goTo("queue/items/0/task/");
final String contentAsString = htmlPage.getWebResponse().getContentAsString();
assertThat(contentAsString, containsString(JOB_CONTENT)); // Fails while unfixed

final Page page = webClient.goTo("queue/api/xml/", "application/xml");
final String xml = page.getWebResponse().getContentAsString();
assertThat(xml, containsString("job/folder/job/job")); // Fails while unfixed
}

final FreeStyleBuild build = job.scheduleBuild2(0, new Cause.UserIdCause("admin")).waitForStart();
final int number = build.getExecutor().getNumber();
Assert.assertEquals(0, Jenkins.get().getQueue().getItems().length); // collapsed queue items

{ // executor related assertions
final HtmlPage htmlPage = webClient.goTo("computer/(master)/executors/" + number + "/currentExecutable/");
final String contentAsString = htmlPage.getWebResponse().getContentAsString();
assertThat(contentAsString, containsString(BUILD_CONTENT)); // Fails while unfixed

final Page page = webClient.goTo("computer/(master)/api/xml?depth=1", "application/xml");
final String xml = page.getWebResponse().getContentAsString();
assertThat(xml, containsString("job/folder/job/job")); // Fails while unfixed
}

{ // widget related assertions
final HtmlPage htmlPage = webClient.goTo("");
final String contentAsString = htmlPage.getWebResponse().getContentAsString();
assertThat(contentAsString, containsString("job/folder/job/job")); // Fails while unfixed
}

{ // queue related assertions
final HtmlPage htmlPage = webClient.goTo("queue/items/0/task/");
final String contentAsString = htmlPage.getWebResponse().getContentAsString();
assertThat(contentAsString, containsString(JOB_CONTENT)); // Fails while unfixed

final Page page = webClient.goTo("queue/api/xml/", "application/xml");
final String xml = page.getWebResponse().getContentAsString();
assertThat(xml, containsString("job/folder/job/job")); // Fails while unfixed
}

final FreeStyleBuild build = job.scheduleBuild2(0, new Cause.UserIdCause("admin")).waitForStart();
final int number = build.getExecutor().getNumber();
Assert.assertEquals(0, Jenkins.get().getQueue().getItems().length); // collapsed queue items

{ // executor related assertions
final HtmlPage htmlPage = webClient.goTo("computer/(master)/executors/" + number + "/currentExecutable/");
final String contentAsString = htmlPage.getWebResponse().getContentAsString();
assertThat(contentAsString, containsString(BUILD_CONTENT)); // Fails while unfixed

final Page page = webClient.goTo("computer/(master)/api/xml?depth=1", "application/xml");
final String xml = page.getWebResponse().getContentAsString();
assertThat(xml, containsString("job/folder/job/job")); // Fails while unfixed
}

{ // widget related assertions
final HtmlPage htmlPage = webClient.goTo("");
final String contentAsString = htmlPage.getWebResponse().getContentAsString();
assertThat(contentAsString, containsString("job/folder/job/job")); // Fails while unfixed
}
build.doStop();
} finally {
System.clearProperty(propertyName);
}
Expand Down

0 comments on commit e141973

Please sign in to comment.