Skip to content

Commit

Permalink
Fixing result ordinal when run is currently building
Browse files Browse the repository at this point in the history
  • Loading branch information
waschndolos committed Dec 5, 2023
1 parent b2e55e1 commit 6dde751
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ public void calculateMetric(Run<?, ?> jenkinsObject, String[] labelValues) {
return;
}

int ordinal = -1;
Result result = jenkinsObject.getResult();
if (result == null) {
return;
if (null != result) {
ordinal = result.ordinal;
}

if (labelValues == null) {
this.collector.labels().set(result.ordinal);
this.collector.labels().set(ordinal);

Check warning on line 47 in src/main/java/org/jenkinsci/plugins/prometheus/collectors/builds/BuildResultOrdinalGauge.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 47 is not covered by tests
} else {
this.collector.labels(labelValues).set(result.ordinal);
this.collector.labels(labelValues).set(ordinal);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BuildResultOrdinalGaugeTest extends MockedRunCollectorTest {


@Test
public void testNothingCalculatedAsRunNotYetOver() {
public void testResultIsMinusOneWhenRunResultIsNull() {

Mockito.when(mock.getResult()).thenReturn(null);

Expand All @@ -24,7 +24,11 @@ public void testNothingCalculatedAsRunNotYetOver() {
List<Collector.MetricFamilySamples> collect = sut.collect();

Assertions.assertEquals(1, collect.size());
Assertions.assertEquals(0, collect.get(0).samples.size(), "Would expect no result");
Assertions.assertEquals(1, collect.get(0).samples.size(), "Would expect one result");

Assertions.assertEquals("default_jenkins_builds_build_result_ordinal", collect.get(0).samples.get(0).name);
Assertions.assertEquals(-1.0, collect.get(0).samples.get(0).value);

}

@Test
Expand Down

0 comments on commit 6dde751

Please sign in to comment.