import mozunit import pytest from conftest import setup_args from mozlog.formatters import JSONFormatter from mozlog.handlers.base import StreamHandler from mozlog.structuredlog import StructuredLogger
def inner():
lines = buf.getvalue().splitlines()
buf.truncate(0) # Python3 will not reposition the buffer position after # truncate and will extend the buffer with null bytes. # Force the buffer position to the start of the buffer # to prevent null bytes from creeping in.
buf.seek(0) return lines
lines = get_lines()
actions = [json.loads(l)["action"] for l in lines] assert actions == expected
return inner
def test_buffering_on(get_message_logger, assert_actions):
ml = get_message_logger(buffering=True)
# no buffering initially (outside of test)
ml.fake_message("log")
assert_actions(["log"])
# inside a test buffering is enabled, only 'test_start' logged
ml.fake_message("test_start")
ml.fake_message("test_status")
ml.fake_message("log")
assert_actions(["test_start"])
# buffering turned off manually within a test
ml.fake_message("buffering_off")
ml.fake_message("test_status")
ml.fake_message("log")
assert_actions(["test_status", "log"])
# buffering turned back on again
ml.fake_message("buffering_on")
ml.fake_message("test_status")
ml.fake_message("log")
assert_actions([])
# test end, it failed! All previsouly buffered messages are now logged.
ml.fake_message("test_end", status="FAIL")
assert_actions([ "log", # "Buffered messages logged" "test_status", "log", "test_status", "log", "log", # "Buffered messages finished" "test_end",
])
# enabling buffering outside of a test has no affect
ml.fake_message("buffering_on")
ml.fake_message("log")
ml.fake_message("test_status")
assert_actions(["log", "test_status"])
def test_buffering_off(get_message_logger, assert_actions):
ml = get_message_logger(buffering=False)
# messages logged no matter what the state
ml.fake_message("test_status")
ml.fake_message("buffering_off")
ml.fake_message("log")
assert_actions(["test_status", "log"])
# even after a 'buffering_on' action
ml.fake_message("buffering_on")
ml.fake_message("test_status")
ml.fake_message("log")
assert_actions(["test_status", "log"])
# no buffer to empty on test fail
ml.fake_message("test_end", status="FAIL")
assert_actions(["test_end"])
def _shutdown_leak_lines(lines): return [
json.loads(l) for l in lines if json.loads(l).get("action") == "test_status" and json.loads(l).get("subtest") == "Shutdown"
]
def test_shutdown_leak_in_retry_mode_queues_test_for_retry(
get_output_handler, get_lines
): """A shutdown leak detected on the initial run is added to failedTests
(so the test is retried) instead of bumping countfail."""
leak = {"test": "test_leak.html", "msg": "leaked 1 window", "time": 0}
fake_leaks = types.SimpleNamespace(process=lambda: (0, [leak]))
output = get_output_handler(shutdownLeaks=fake_leaks)
output.harness.message_logger.retry_mode = True
leaks = _shutdown_leak_lines(get_lines()) assert len(leaks) == 1 # In retry mode the synthetic leak message is rewritten so it doesn't # surface as a TEST-UNEXPECTED-FAIL on the initial run. mozlog drops the # "expected" key when it matches "status". assert"expected"notin leaks[0] assert leaks[0]["status"] == "FAIL"
def test_shutdown_leak_without_retry_mode_logs_unexpected(
get_output_handler, get_lines
): """Outside retry mode (or on the retry pass), a shutdown leak bumps
countfail andis logged as a real unexpected failure."""
leak = {"test": "test_leak.html", "msg": "leaked 1 window", "time": 0}
fake_leaks = types.SimpleNamespace(process=lambda: (0, [leak]))
output = get_output_handler(shutdownLeaks=fake_leaks)
output.harness.message_logger.retry_mode = False
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.