convert to nanos from seconds rather than milliseconds when parsing JUnit xml (#5666)

* convert to nanos from seconds rather than milliseconds

* fix tests
This commit is contained in:
Stefano Franz 2019-11-04 15:17:57 +00:00 committed by GitHub
parent 5a0b8c7992
commit f7e0ce6f0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -328,7 +328,7 @@ public class TestDurationArtifacts {
// If the test doesn't have a duration (it should), we return zero.
if (!(testName.isEmpty() || testClassName.isEmpty())) {
final long nanos = !testDuration.isEmpty() ? (long) (Double.parseDouble(testDuration) * 1000000.0) : 0L;
final long nanos = !testDuration.isEmpty() ? (long) (Double.parseDouble(testDuration) * 1_000_000_000.0) : 0L;
results.add(new Tuple2<>(testClassName + "." + testName, nanos));
} else {
LOG.warn("Bad test in junit xml: name={} className={}", testName, testClassName);

View File

@ -38,7 +38,7 @@ public class TestDurationArtifactsTest {
" </properties>\n");
for (Tuple2<String, Long> test : tests) {
Double d = ((double) test.getSecond()) / 1_000_000;
Double d = ((double) test.getSecond()) / 1_000_000_000.0;
sb.append(" <testcase assertions=\"\" classname=\"" + CLASSNAME + "\" name=\""
+ test.getFirst() + "\" status=\"\" time=\"" + d.toString() + "\">\n" +
" <skipped/>\n" +
@ -67,7 +67,7 @@ public class TestDurationArtifactsTest {
" </properties>\n");
for (Tuple2<String, Long> test : tests) {
Double d = ((double) test.getSecond()) / 1_000_000;
Double d = ((double) test.getSecond()) / 1_000_000_000.0;
sb.append(" <testcase assertions=\"\" classname=\"" + CLASSNAME + "\" name=\""
+ test.getFirst() + "\" status=\"\" time=\"\">\n" +
" <skipped/>\n" +
@ -88,8 +88,8 @@ public class TestDurationArtifactsTest {
@Test
public void fromJunitXml() {
List<Tuple2<String, Long>> tests = new ArrayList<>();
tests.add(new Tuple2<>("TEST-A", 111_000_000L));
tests.add(new Tuple2<>("TEST-B", 222_200_000L));
tests.add(new Tuple2<>("TEST-A", 111_000_000_000L));
tests.add(new Tuple2<>("TEST-B", 222_200_000_000L));
final String xml = getXml(tests);
List<Tuple2<String, Long>> results
@ -100,9 +100,9 @@ public class TestDurationArtifactsTest {
Assert.assertFalse("Should have results", results.isEmpty());
Assert.assertEquals(results.size(), 2);
Assert.assertEquals(CLASSNAME + "." + "TEST-A", results.get(0).getFirst());
Assert.assertEquals(111_000_000L, results.get(0).getSecond().longValue());
Assert.assertEquals(111_000_000_000L, results.get(0).getSecond().longValue());
Assert.assertEquals(CLASSNAME + "." + "TEST-B", results.get(1).getFirst());
Assert.assertEquals(222_200_000L, results.get(1).getSecond().longValue());
Assert.assertEquals(222_200_000_000L, results.get(1).getSecond().longValue());
}
@Test