forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix web-platform-tests#10026: add test execution time to wptreport.js…
…on format
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |