MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_tracing

Function test_tracing

tests/test_misc.py:5264–5342  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

5262
5263@unittest.skipIf(env('HAVE_USDT') != '1', "Test requires tracing compiled in")
5264def test_tracing(node_factory):
5265 l1 = node_factory.get_node(start=False)
5266 trace_fnamebase = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "l1.trace")
5267 l1.daemon.env["CLN_DEV_TRACE_FILE"] = trace_fnamebase
5268 l1.start()
5269 l1.stop()
5270
5271 traces = set()
5272 suspended = set()
5273 for fname in glob.glob(f"{trace_fnamebase}.*"):
5274 with open(fname, "rt") as f:
5275 for linenum, l in enumerate(f.readlines(), 1):
5276 # In case an assertion fails
5277 print(f"Parsing {fname}:{linenum}: {l.strip()}")
5278 parts = l.split(maxsplit=2)
5279 cmd = parts[0]
5280 spanid = parts[1]
5281 if cmd == 'span_emit':
5282 assert spanid in traces
5283 assert spanid not in suspended
5284 # Should be valid JSON
5285 res = json.loads(parts[2])
5286
5287 # This is an array for some reason
5288 assert len(res) == 1
5289 res = res[0]
5290 assert res['id'] == spanid
5291 assert res['localEndpoint'] == {"serviceName": "lightningd"}
5292 expected_keys = ['id', 'name', 'timestamp', 'duration', 'tags', 'traceId', 'localEndpoint']
5293 if 'parentId' in res:
5294 assert res['parentId'] in traces
5295 expected_keys.append('parentId')
5296 assert set(res.keys()) == set(expected_keys)
5297 traces.remove(spanid)
5298 elif cmd == 'span_end':
5299 assert spanid in traces
5300 elif cmd == 'span_start':
5301 assert spanid not in traces
5302 traces.add(spanid)
5303 elif cmd == 'span_suspend':
5304 assert spanid in traces
5305 assert spanid not in suspended
5306 suspended.add(spanid)
5307 elif cmd == 'span_resume':
5308 assert spanid in traces
5309 suspended.remove(spanid)
5310 elif cmd == 'destroying':
5311 pass
5312 else:
5313 assert False, "Unknown trace line"
5314
5315 # We can actually have a calls suspended when we shut down!
5316 assert len(suspended) <= 1
5317 assert suspended == traces
5318
5319 # Test parent trace
5320 trace_fnamebase = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "l1.parent.trace")
5321 l1.daemon.env["CLN_DEV_TRACE_FILE"] = trace_fnamebase

Callers

nothing calls this directly

Calls 6

joinMethod · 0.80
get_nodeMethod · 0.45
startMethod · 0.45
stopMethod · 0.45
removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected