]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Fix false negatives checking error_log with test_proxy_beacon: [skip ci]
authorJoe Orton <jorton@apache.org>
Fri, 7 Aug 2026 14:24:32 +0000 (14:24 +0000)
committerJoe Orton <jorton@apache.org>
Fri, 7 Aug 2026 14:24:32 +0000 (14:24 +0000)
* test/pytest_suite/conftest.py (framework): Record error_log's size
  before httpd starts, as session_log_start.

* test/pytest_suite/tests/t/modules/test_proxy_beacon.py
  (test_proxy_beacon): Scope the "added backend" log check to
  session_log_start instead of the per-test window or byte 0.

Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
GitHub: PR #701

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1936976 13f79535-47bb-0310-9956-ffa450edef68

test/pytest_suite/conftest.py
test/pytest_suite/tests/t/modules/test_proxy_beacon.py

index 5ffb1cbd79e25ec4fcdc7dce25bcf4ad11c995c0..9fbaa80efe5518f2d280ac8160df257b9acf2d5a 100644 (file)
@@ -250,6 +250,18 @@ def framework(request: pytest.FixtureRequest):
         )
         fpm_mgr.start()
 
+    # Record the error_log size right before this session's httpd starts.
+    # error_log is opened in append mode and t_logs/ is not cleaned between
+    # invocations, so it can carry entries from earlier, unrelated test runs
+    # (possibly hours/days old, with different pids). Tests that need "since
+    # this server session started" (as opposed to "since this individual
+    # test started") must scope their log reads to this offset, not to
+    # position 0 -- see test_proxy_beacon.py.
+    error_log = Path(config.vars["t_logs"]) / "error_log"
+    config.vars["session_log_start"] = str(
+        error_log.stat().st_size if error_log.exists() else 0
+    )
+
     server = HttpdServer(config)
     server.start()
     try:
index 2fa951c3d608cf93bce8f24d49e44ad3f14100c5..bab950c7353b5df82e855574b12763ac2b0c55a7 100644 (file)
@@ -68,6 +68,19 @@ def test_proxy_beacon(http):
         fh.seek(start)
         loglines = fh.read().splitlines()
 
+    # "added backend" is logged once ever per url for the life of the
+    # (session-scoped) httpd process -- it dedups via ctx->seen in
+    # mod_proxy_beacon (beacon_try_add()/beacon_handle_announce()). Since this
+    # test may run long after server startup, that one-time event can predate
+    # `start` and must be searched for since session start instead. Do NOT
+    # scan from byte 0 of error_log: t_logs/ isn't cleaned between separate
+    # test runs, so the file can carry "added backend" lines from earlier,
+    # unrelated httpd sessions (different pids, possibly hours old).
+    session_start = int(http.vars("session_log_start") or 0)
+    with error_log.open("r", errors="replace") as fh:
+        fh.seek(session_start)
+        session_loglines = fh.read().splitlines()
+
     # Announcements are received and carry a routable url=.
     received = [ln for ln in loglines if "received: BEACON" in ln]
     assert received, "no announcements received by the SUB"
@@ -77,7 +90,7 @@ def test_proxy_beacon(http):
     # Phase 2: the backend was added exactly once (dedup), no add-failure spam.
     # Qualify by balancer://beacon so the capacity-test balancer (below) doesn't
     # perturb these counts.
-    added = [ln for ln in loglines
+    added = [ln for ln in session_loglines
              if "added backend" in ln and "balancer://beacon" in ln]
     assert len(added) == 1, (
         f"backend should be added exactly once; saw {len(added)}: {added}")
@@ -103,7 +116,9 @@ def test_proxy_beacon(http):
 
     # Slot exhaustion: balancer://cap has room for one member but two backends
     # announce to it. Exactly one must be added; the other can never fit.
-    cap_added = [ln for ln in loglines
+    # Same one-time-dedup-event caveat as the balancer://beacon "added" check
+    # above: search since session start, not just this test's window.
+    cap_added = [ln for ln in session_loglines
                  if "added backend" in ln and "balancer://cap" in ln]
     assert len(cap_added) == 1, (
         f"exactly one backend should fit balancer://cap; saw: {cap_added}")