Skip to content

Commit

Permalink
[JENKINS-57993] Verify no warnings are printed for a basic build (#503)
Browse files Browse the repository at this point in the history
[JENKINS-57993] Verify no warnings are printed for a basic build
  • Loading branch information
Vlatombe committed Oct 7, 2019
2 parents 61894e9 + 45edbbe commit e7548c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<connectorHost />
<jenkins.host.address />
<java.level>8</java.level>
<jenkins.version>2.176.1</jenkins.version>
<jenkins.version>2.190.1</jenkins.version>
<no-test-jar>false</no-test-jar>
<useBeta>true</useBeta>
<surefire.rerunFailingTestsCount>0</surefire.rerunFailingTestsCount>
Expand Down Expand Up @@ -205,6 +205,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency> <!-- TODO for #sshagent pending https://github.com/jenkinsci/ssh-credentials-plugin/pull/47 -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>trilead-api</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>bouncycastle-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
package org.csanchez.jenkins.plugins.kubernetes.pipeline;

import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;

Expand All @@ -39,6 +37,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import hudson.model.Computer;
import com.gargoylesoftware.htmlunit.html.DomNodeUtil;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
Expand All @@ -60,6 +59,7 @@
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRuleNonLocalhost;
import org.jvnet.hudson.test.LoggerRule;

import hudson.model.Result;
import java.util.Locale;
Expand All @@ -75,13 +75,17 @@ public class KubernetesPipelineTest extends AbstractKubernetesPipelineTest {
@Rule
public TemporaryFolder tmp = new TemporaryFolder();

@Rule
public LoggerRule warnings = new LoggerRule();

@Before
public void setUp() throws Exception {
deletePods(cloud.connect(), getLabels(cloud, this, name), false);
logs.capture(1000);
warnings.record("", Level.WARNING).capture(1000);
assertNotNull(createJobThenScheduleRun());
}

@Issue("JENKINS-57993")
@Test
public void runInPod() throws Exception {
SemaphoreStep.waitForStart("podTemplate/1", b);
Expand All @@ -100,17 +104,29 @@ public void runInPod() throws Exception {

Map<String, String> labels = getLabels(cloud, this, name);
SemaphoreStep.waitForStart("pod/1", b);
for (Computer c : r.jenkins.getComputers()) { // TODO perhaps this should be built into JenkinsRule via ComputerListener.preLaunch?
new Thread(() -> {
long pos = 0;
try {
while (Jenkins.getInstanceOrNull() != null) { // otherwise get NPE from Computer.getLogDir
if (c.getLogFile().isFile()) { // TODO should LargeText.FileSession handle this?
pos = c.getLogText().writeLogTo(pos, System.out);
}
Thread.sleep(100);
}
} catch (Exception x) {
x.printStackTrace();
}
}, "watching logs for " + c.getDisplayName()).start();
System.out.println(c.getLog());
}
PodList pods = cloud.connect().pods().withLabels(labels).list();
assertThat(
"Expected one pod with labels " + labels + " but got: "
+ pods.getItems().stream().map(pod -> pod.getMetadata()).collect(Collectors.toList()),
pods.getItems(), hasSize(1));
SemaphoreStep.success("pod/1", null);

for (String msg : logs.getMessages()) {
System.out.println(msg);
}

PodTemplate template = templates.get(0);
List<PodAnnotation> annotations = template.getAnnotations();
assertNotNull(annotations);
Expand All @@ -136,6 +152,11 @@ public void runInPod() throws Exception {
r.assertLogContains("script file contents: ", b);
assertFalse("There are pods leftover after test execution, see previous logs",
deletePods(cloud.connect(), getLabels(cloud, this, name), true));
assertThat("routine build should not issue warnings",
warnings.getRecords().stream().
filter(lr -> lr.getLevel().intValue() >= Level.WARNING.intValue()). // TODO .record(…, WARNING) does not accomplish this
map(lr -> lr.getSourceClassName() + "." + lr.getSourceMethodName() + ": " + lr.getMessage()).collect(Collectors.toList()), // LogRecord does not override toString
emptyIterable());
}

@Test
Expand Down

0 comments on commit e7548c7

Please sign in to comment.