Skip to content

Commit

Permalink
Fix web-platform-tests#10026: add test execution time to wptreport.js…
Browse files Browse the repository at this point in the history
…on format
  • Loading branch information
gsnedders committed Jun 13, 2018
1 parent fec5f26 commit 3b59fab
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/wptrunner/wptrunner/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def find_or_create_test(self, data):
}
return self.raw_results[test_name]

def test_start(self, data):
test = self.find_or_create_test(data)
test["start_time"] = data["time"]

def create_subtest(self, data):
test = self.find_or_create_test(data)
subtest_name = data["subtest"]
Expand All @@ -54,6 +58,8 @@ def test_status(self, data):

def test_end(self, data):
test = self.find_or_create_test(data)
start_time = test.pop("start_time")
test["duration"] = data["time"] - start_time
test["status"] = data["status"]
if "message" in data:
test["message"] = data["message"]
39 changes: 39 additions & 0 deletions tools/wptrunner/wptrunner/tests/test_formatters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
import sys
import time
from os.path import dirname, join
from StringIO import StringIO

from mozlog import handlers, structuredlog

sys.path.insert(0, join(dirname(__file__), "..", ".."))

from wptrunner.formatters import WptreportFormatter


def test_wptreport_runtime(capfd):
# setup the logger
output = StringIO()
logger = structuredlog.StructuredLogger("test_a")
logger.add_handler(handlers.StreamHandler(output, WptreportFormatter()))

# output a bunch of stuff
logger.suite_start(["test-id-1"], run_info={})
logger.test_start("test-id-1")
time.sleep(0.125)
logger.test_end("test-id-1", "PASS")
logger.suite_end()

# check nothing got output to stdout/stderr
# (note that mozlog outputs exceptions during handling to stderr!)
captured = capfd.readouterr()
assert captured.out == ""
assert captured.err == ""

# check the actual output of the formatter
output.seek(0)
output_obj = json.load(output)
# be relatively lax in case of low resolution timers
# 62 is 0.125s = 125ms / 2 = 62ms (assuming int maths)
# this provides a margin of 62ms, sufficient for even DOS (55ms timer)
assert output_obj["results"][0]["duration"] >= 62

0 comments on commit 3b59fab

Please sign in to comment.