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

Function test_tracing

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

Source from the content-addressed store, hash-verified

5175
5176@unittest.skipIf(env('HAVE_USDT') != '1', "Test requires tracing compiled in")
5177def test_tracing(node_factory):
5178 l1 = node_factory.get_node(start=False)
5179 trace_fnamebase = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "l1.trace")
5180 l1.daemon.env["CLN_DEV_TRACE_FILE"] = trace_fnamebase
5181 l1.start()
5182 l1.stop()
5183
5184 traces = set()
5185 suspended = set()
5186 for fname in glob.glob(f"{trace_fnamebase}.*"):
5187 with open(fname, "rt") as f:
5188 for linenum, l in enumerate(f.readlines(), 1):
5189 # In case an assertion fails
5190 print(f"Parsing {fname}:{linenum}: {l.strip()}")
5191 parts = l.split(maxsplit=2)
5192 cmd = parts[0]
5193 spanid = parts[1]
5194 if cmd == 'span_emit':
5195 assert spanid in traces
5196 assert spanid not in suspended
5197 # Should be valid JSON
5198 res = json.loads(parts[2])
5199
5200 # This is an array for some reason
5201 assert len(res) == 1
5202 res = res[0]
5203 assert res['id'] == spanid
5204 assert res['localEndpoint'] == {"serviceName": "lightningd"}
5205 expected_keys = ['id', 'name', 'timestamp', 'duration', 'tags', 'traceId', 'localEndpoint']
5206 if 'parentId' in res:
5207 assert res['parentId'] in traces
5208 expected_keys.append('parentId')
5209 assert set(res.keys()) == set(expected_keys)
5210 traces.remove(spanid)
5211 elif cmd == 'span_end':
5212 assert spanid in traces
5213 elif cmd == 'span_start':
5214 assert spanid not in traces
5215 traces.add(spanid)
5216 elif cmd == 'span_suspend':
5217 assert spanid in traces
5218 assert spanid not in suspended
5219 suspended.add(spanid)
5220 elif cmd == 'span_resume':
5221 assert spanid in traces
5222 suspended.remove(spanid)
5223 elif cmd == 'destroying':
5224 pass
5225 else:
5226 assert False, "Unknown trace line"
5227
5228 # We can actually have a calls suspended when we shut down!
5229 assert len(suspended) <= 1
5230 assert suspended == traces
5231
5232 # Test parent trace
5233 trace_fnamebase = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "l1.parent.trace")
5234 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