Skip to content

Commit

Permalink
(fix) Handle test results with very large XML attributes and record f…
Browse files Browse the repository at this point in the history
…ailure timestamp
  • Loading branch information
craigatk committed Sep 22, 2020
1 parent 64409a0 commit 66aaecd
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 23 deletions.
2 changes: 2 additions & 0 deletions server/parsing/junit-results-parser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ dependencies {

testImplementation "org.spockframework:spock-core:1.3-groovy-2.5"

testImplementation("org.apache.commons:commons-lang3:3.8.1")

testImplementation(project(':server:test:test-fixtures'))
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package projektor.parser;

import com.ctc.wstx.api.WstxInputProperties;
import com.ctc.wstx.stax.WstxInputFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import projektor.parser.model.TestSuite;
import projektor.parser.model.TestSuites;

import javax.xml.stream.XMLInputFactory;
import java.io.IOException;
import java.util.List;

public class JUnitResultsParser {
private final ObjectMapper mapper = new XmlMapper()
.registerModule(new JavaTimeModule());
private final ObjectMapper mapper;

public JUnitResultsParser() {
XMLInputFactory xmlInputFactory = new WstxInputFactory();
xmlInputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, Integer.MAX_VALUE);

this.mapper = new XmlMapper(xmlInputFactory)
.registerModule(new JavaTimeModule());
}

/**
* Parses a test suite XML in this format
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package projektor.parser

import org.apache.commons.lang3.RandomStringUtils
import projektor.parser.model.TestCase
import projektor.parser.model.TestSuite
import spock.lang.Specification
import spock.lang.Subject

class JUnitResultsParserLargeSpec extends Specification {
@Subject
JUnitResultsParser testResultsParser = new JUnitResultsParser()

def "should be able to parse results with large XML attributes"() {
given:
String resultsXmlWithHugeAttribute = """<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="projektor.example.spock.PassingSpec" tests="1" skipped="0" failures="0" errors="0" timestamp="2019-10-01T13:15:45" hostname="Craigs-MacBook-Pro.local" time="0.002">
<properties/>
<testcase name="long-name-${RandomStringUtils.randomAlphabetic(1_000_000)}" classname="projektor.example.spock.PassingSpec" time="0.002"/>
<system-out><![CDATA[]]></system-out>
<system-err><![CDATA[]]></system-err>
</testsuite>
"""

when:
TestSuite testSuite = testResultsParser.parseTestSuite(resultsXmlWithHugeAttribute)

then:
testSuite.testCases.size() == 1

TestCase testCase = testSuite.testCases[0]

testCase.name.startsWith("long-name-")
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE results_processing_failure ADD COLUMN created_timestamp TIMESTAMP;
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ResultsProcessingDatabaseRepository(private val dslContext: DSLContext) :
val resultsProcessingFailure = ResultsProcessingFailure()
resultsProcessingFailure.publicId = publicId.id
resultsProcessingFailure.body = resultsBody
resultsProcessingFailure.createdTimestamp = Timestamp.valueOf(LocalDateTime.now())
resultsProcessingFailureDao.insert(resultsProcessingFailure)

updateProcessingStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class ResultsProcessingDatabaseRepositoryTest : DatabaseRepositoryTestCase() {
.isNotNull()
.and {
get { resultsBody }.isEqualTo(resultsBody)
get { createdTimestamp }.isNotNull()
}
}

Expand Down

0 comments on commit 66aaecd

Please sign in to comment.