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

Function test_tracing_socket

tests/test_misc.py:5349–5386  ·  view source on GitHub ↗

Test UDS datagram tracing backend via CLN_TRACE_SOCKET.

(node_factory)

Source from the content-addressed store, hash-verified

5347
5348
5349def test_tracing_socket(node_factory):
5350 """Test UDS datagram tracing backend via CLN_TRACE_SOCKET."""
5351 l1 = node_factory.get_node(start=False)
5352 sock_path = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "trace.sock")
5353
5354 # Create a SOCK_DGRAM UDS listener
5355 sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
5356 sock.bind(sock_path)
5357 sock.settimeout(5)
5358
5359 l1.daemon.env["CLN_TRACE_SOCKET"] = sock_path
5360 l1.start()
5361 l1.stop()
5362
5363 # Collect all datagrams that were sent
5364 spans = []
5365 while True:
5366 try:
5367 data = sock.recv(4096)
5368 spans.append(json.loads(data.decode("utf-8")))
5369 except socket.timeout:
5370 break
5371
5372 sock.close()
5373
5374 # We should have received at least some spans from startup
5375 assert len(spans) > 0, "No spans received via UDS socket"
5376
5377 for span_array in spans:
5378 # Each datagram is a Zipkin JSON array with one span
5379 assert isinstance(span_array, list)
5380 assert len(span_array) == 1
5381 span = span_array[0]
5382
5383 # Validate required Zipkin fields are present
5384 for key in ("id", "name", "timestamp", "duration", "traceId"):
5385 assert key in span, f"Missing key {key} in span {span}"
5386 assert span["localEndpoint"] == {"serviceName": "lightningd"}

Callers

nothing calls this directly

Calls 7

joinMethod · 0.80
get_nodeMethod · 0.45
startMethod · 0.45
stopMethod · 0.45
recvMethod · 0.45
decodeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected