tests: fix flaky reckless tests by waiting for the canned github server
What changed, and why it matters
This commit fixes a flaky automated test, not a security bug. The test harness previously started a fake GitHub server and sometimes tried to use it before it was ready, causing random test failures. The patch simply waits for the server to be ready before continuing. There is no vulnerability in production code and no user impact.
No security action needed. Treat as a normal test reliability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is confined to tests/test_reckless.py in the canned_github_server fixture. It adds a wait loop that polls the spawned Flask process and attempts a TCP connection to 127.0.0.1:
Changed components
tests/test_reckless.py::canned_github_server fixtureInspect captured patch +16 / −1
diff --git a/tests/test_reckless.py b/tests/test_reckless.py
index d294b79a..c7c7f426 100644
--- a/tests/test_reckless.py
+++ b/tests/test_reckless.py
@@ -2,7 +2,7 @@ from fixtures import * # noqa: F401,F403
import subprocess
from pathlib import PosixPath, Path
import socket
-from pyln.testing.utils import VALGRIND
+from pyln.testing.utils import TIMEOUT, VALGRIND
import pytest
import os
import re
@@ -85,6 +85,21 @@ def canned_github_server(directory):
del my_env['GIT_INDEX_FILE']
# We also need the github api data for the repo which will be served via http
shutil.copyfile(str(FILE_PATH / 'data/recklessrepo/rkls_api_lightningd_plugins.json'), os.path.join(directory, 'rkls_api_lightningd_plugins.json'))
+
+ # Flask can be slow to start listening under CI load; make sure the
+ # first reckless invocation doesn't race it and get connection refused.
+ start = time.time()
+ while True:
+ assert server.poll() is None, "canned github server died"
+ try:
+ with socket.create_connection(('127.0.0.1', int(free_port)),
+ timeout=5):
+ break
+ except OSError:
+ if time.time() >= start + TIMEOUT:
+ server.terminate()
+ raise RuntimeError("canned github server never started listening")
+ time.sleep(0.2)
yield
# Delete requirements.txt from the testplugpass directory
with open(requirements_file_path, 'w') as f:
Why this scored 15/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.