pytest: fix flake in test_misc.
What changed, and why it matters
This is a test-only reliability fix. A developer saw an occasional test failure where one background tracing call had not finished by the time the test ended. The patch adds a diagnostic line to the trace output and relaxes the test assertion to allow exactly one suspended call at shutdown, rather than requiring zero. There is no indication this affects real users, funds, or network security.
No security action needed. Treat as normal test-flake fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit addresses a flaky pytest case, test_misc.py::test_tracing. It changes common/trace.c to include the span name in span_start trace log lines, and updates the test parser to print each parsed line. The test assertion is relaxed from requiring suspended == set() and traces == set() to allowing len(suspended) <= 1 and suspended == traces, acknowledging that a span may still be suspended when the node shuts down. This is a test-hardening change, not a runtime bug fix.
Changed components
tests/test_misc.pycommon/trace.cInspect captured patch +5 / −4
diff --git a/common/trace.c b/common/trace.c
index 6c1d607c..8a6b24e9 100644
--- a/common/trace.c
+++ b/common/trace.c
@@ -312,7 +312,7 @@ void trace_span_start_(const char *name, const void *key)
current = s;
DTRACE_PROBE1(lightningd, span_start, s->id);
if (trace_to_file) {
- fprintf(trace_to_file, "span_start %016"PRIx64"\n", s->id);
+ fprintf(trace_to_file, "span_start %016"PRIx64" %s\n", s->id, name);
fflush(trace_to_file);
}
}
diff --git a/tests/test_misc.py b/tests/test_misc.py
index df89d8c9..f62ebc1b 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -5032,7 +5032,7 @@ def test_tracing(node_factory):
with open(fname, "rt") as f:
for linenum, l in enumerate(f.readlines(), 1):
# In case an assertion fails
- print(f"Parsing {fname}:{linenum}")
+ print(f"Parsing {fname}:{linenum}: {l.strip()}")
parts = l.split(maxsplit=2)
cmd = parts[0]
spanid = parts[1]
@@ -5070,8 +5070,9 @@ def test_tracing(node_factory):
else:
assert False, "Unknown trace line"
- assert suspended == set()
- assert traces == set()
+ # We can actually have a calls suspended when we shut down!
+ assert len(suspended) <= 1
+ assert suspended == traces
# Test parent trace
trace_fnamebase = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "l1.parent.trace")
Why this scored 13/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.