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

Function test_tracing

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

Source from the content-addressed store, hash-verified

5228
5229@unittest.skipIf(env('HAVE_USDT') != '1', "Test requires tracing compiled in")
5230def test_tracing(node_factory):
5231 l1 = node_factory.get_node(start=False)
5232 trace_fnamebase = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "l1.trace")
5233 l1.daemon.env["CLN_DEV_TRACE_FILE"] = trace_fnamebase
5234 l1.start()
5235 l1.stop()
5236
5237 traces = set()
5238 suspended = set()
5239 for fname in glob.glob(f"{trace_fnamebase}.*"):
5240 with open(fname, "rt") as f:
5241 for linenum, l in enumerate(f.readlines(), 1):
5242 # In case an assertion fails
5243 print(f"Parsing {fname}:{linenum}: {l.strip()}")
5244 parts = l.split(maxsplit=2)
5245 cmd = parts[0]
5246 spanid = parts[1]
5247 if cmd == 'span_emit':
5248 assert spanid in traces
5249 assert spanid not in suspended
5250 # Should be valid JSON
5251 res = json.loads(parts[2])
5252
5253 # This is an array for some reason
5254 assert len(res) == 1
5255 res = res[0]
5256 assert res['id'] == spanid
5257 assert res['localEndpoint'] == {"serviceName": "lightningd"}
5258 expected_keys = ['id', 'name', 'timestamp', 'duration', 'tags', 'traceId', 'localEndpoint']
5259 if 'parentId' in res:
5260 assert res['parentId'] in traces
5261 expected_keys.append('parentId')
5262 assert set(res.keys()) == set(expected_keys)
5263 traces.remove(spanid)
5264 elif cmd == 'span_end':
5265 assert spanid in traces
5266 elif cmd == 'span_start':
5267 assert spanid not in traces
5268 traces.add(spanid)
5269 elif cmd == 'span_suspend':
5270 assert spanid in traces
5271 assert spanid not in suspended
5272 suspended.add(spanid)
5273 elif cmd == 'span_resume':
5274 assert spanid in traces
5275 suspended.remove(spanid)
5276 elif cmd == 'destroying':
5277 pass
5278 else:
5279 assert False, "Unknown trace line"
5280
5281 # We can actually have a calls suspended when we shut down!
5282 assert len(suspended) <= 1
5283 assert suspended == traces
5284
5285 # Test parent trace
5286 trace_fnamebase = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "l1.parent.trace")
5287 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