feat(dashboard-testing): observe delayed final-suite nodes safely
This commit is contained in:
@@ -85,4 +85,47 @@ def test_junit_failure_projection_keeps_type_and_stack_without_driver_message():
|
||||
assert projection['locations'][-1]['path'] == __file__
|
||||
assert projection['locations'][-1]['line'] > 0
|
||||
assert 'PRIVATE_JUNIT_SENTINEL' not in observed and '[SQL:' not in observed
|
||||
|
||||
|
||||
def test_delayed_node_observes_locations_without_locals_or_source_and_cancels_timer():
|
||||
import sys
|
||||
from contextvars import ContextVar
|
||||
from types import SimpleNamespace
|
||||
timers, events = [], []
|
||||
private = 'PRIVATE_DELAYED_NODE_SENTINEL'
|
||||
trace = ContextVar('test_delay_trace', default='foreign')
|
||||
|
||||
class Timer:
|
||||
def __init__(self, seconds, callback):
|
||||
assert seconds == 60
|
||||
self.callback, self.cancelled, self.started = callback, False, False
|
||||
timers.append(self)
|
||||
|
||||
def start(self):
|
||||
self.started = True
|
||||
|
||||
def cancel(self):
|
||||
self.cancelled = True
|
||||
|
||||
foreign = SimpleNamespace(f_code=SimpleNamespace(co_filename='https://' + private, co_name=private),
|
||||
f_lineno=7, f_back=None, f_locals={'password':private})
|
||||
token = trace.set('owned-node-trace')
|
||||
observer = launcher.DelayedNode(ROOT, 'tests/test_current.py::test_owned',
|
||||
lambda message, **event: events.append({'trace':trace.get(), **event}), timer_factory=Timer,
|
||||
frames=lambda: {1:sys._getframe(), 2:foreign})
|
||||
trace.reset(token)
|
||||
observer.start()
|
||||
observer.stage = 'call'
|
||||
timers[0].callback()
|
||||
assert timers[0].started
|
||||
assert len(events) == 1 and events[0]['error_code'] == 'FINAL_NODE_DELAYED'
|
||||
assert events[0]['trace'] == 'owned-node-trace'
|
||||
assert events[0]['payload']['stage'] == 'call'
|
||||
assert {'file':'outside_source_roots','line':7,'function':'unavailable'} in events[0]['payload']['locations']
|
||||
wire = json.dumps(events)
|
||||
assert private not in wire and 'password' not in wire and 'https://' not in wire
|
||||
observer.finish()
|
||||
assert timers[0].cancelled
|
||||
timers[0].callback()
|
||||
assert len(events) == 1
|
||||
# #endregion Test.VerifyDashboardTestingCurrent
|
||||
|
||||
Reference in New Issue
Block a user