Skip to content

Commit

Permalink
Merge pull request #276 from iteratec/fix/first_paint_metric
Browse files Browse the repository at this point in the history
Fix persisting of first paint metric when value is not an integer
  • Loading branch information
DanielSteger authored Sep 24, 2019
2 parents 9c44553 + eea8631 commit 0df31af
Show file tree
Hide file tree
Showing 3 changed files with 1,832 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
/*
* OpenSpeedMonitor (OSM)
* Copyright 2014 iteratec GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Expand Down Expand Up @@ -318,8 +318,22 @@ class EventResultPersisterService implements iResultListener {
}

private void setPropertyWithinEventResult(Measurand measurand, GPathResult inputValues, EventResult result) {
if (tagExists(inputValues, measurand.getTagInResultXml())) {
result.setProperty(measurand.getEventResultField(), inputValues.getProperty(measurand.getTagInResultXml()).toInteger())
def value = inputValues.getProperty(measurand.getTagInResultXml())

if (!value.isEmpty()) {
if (value.toString().isBigInteger()) {
value = value.toInteger()
} else if (value.toString().isBigDecimal()) {
value = value.toDouble().round().toInteger()
} else {
return
}

if (value <= 0) {
return
}

result.setProperty(measurand.getEventResultField(), value)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
/*
* OpenSpeedMonitor (OSM)
* Copyright 2014 iteratec GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Expand Down Expand Up @@ -283,6 +283,30 @@ class PersistingNewEventResultsSpec extends Specification implements BuildDataTe
erBothTwo.timeToInteractiveInMillisecs == 11430
}

void "first paint gets persisted correctly"() {
setup: "given a result with first paint"
File file = new File("src/test/resources/WptResultXmls/firstPaint.xml")
WptResultXml xmlResult = new WptResultXml(new XmlSlurper().parse(file))
WebPageTestServer wptServer = WebPageTestServer.build()
Location.build(uniqueIdentifierForServer: xmlResult.responseNode.data.location.toString(), wptServer: wptServer)
Job job = Job.build(label: "ExampleJob Chrome firstPaint")
JobResult.build(job: job, testId: xmlResult.testId, jobResultStatus: JobResultStatus.SUCCESS, wptServerBaseurl: wptServer.baseUrl)
service.timeToCsMappingService = Stub(TimeToCsMappingService) {
getCustomerSatisfactionInPercent(_) >> { value -> value }
}

when: "the service creates new event results from the XML result"
service.listenToResult(xmlResult, wptServer, job.id)
List<EventResult> eventResults = EventResult.list()
EventResult firstEventResult = eventResults.find { it.oneBasedStepIndexInJourney == 1 }
EventResult secondEventResult = eventResults.find { it.oneBasedStepIndexInJourney == 2 }


then: "there is one EventResult with just first cpu idle and two with first cpu idle AND time to interactive"
firstEventResult.firstPaint == 605
secondEventResult.firstPaint == 502
}

void "check CSI value creation"() {
setup: "mock service and create testee"
service.timeToCsMappingService = Mock(TimeToCsMappingService)
Expand Down
Loading

0 comments on commit 0df31af

Please sign in to comment.