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

Function test_tracing_socket

tests/test_misc.py:5383–5420  ·  view source on GitHub ↗

Test UDS datagram tracing backend via CLN_TRACE_SOCKET.

(node_factory)

Source from the content-addressed store, hash-verified

5381
5382
5383def test_tracing_socket(node_factory):
5384 """Test UDS datagram tracing backend via CLN_TRACE_SOCKET."""
5385 l1 = node_factory.get_node(start=False)
5386 sock_path = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "trace.sock")
5387
5388 # Create a SOCK_DGRAM UDS listener
5389 sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
5390 sock.bind(sock_path)
5391 sock.settimeout(5)
5392
5393 l1.daemon.env["CLN_TRACE_SOCKET"] = sock_path
5394 l1.start()
5395 l1.stop()
5396
5397 # Collect all datagrams that were sent
5398 spans = []
5399 while True:
5400 try:
5401 data = sock.recv(4096)
5402 spans.append(json.loads(data.decode("utf-8")))
5403 except socket.timeout:
5404 break
5405
5406 sock.close()
5407
5408 # We should have received at least some spans from startup
5409 assert len(spans) > 0, "No spans received via UDS socket"
5410
5411 for span_array in spans:
5412 # Each datagram is a Zipkin JSON array with one span
5413 assert isinstance(span_array, list)
5414 assert len(span_array) == 1
5415 span = span_array[0]
5416
5417 # Validate required Zipkin fields are present
5418 for key in ("id", "name", "timestamp", "duration", "traceId"):
5419 assert key in span, f"Missing key {key} in span {span}"
5420 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