diff --git a/AGENTS.md b/AGENTS.md index 9f2d059563b..281d175541e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -112,6 +112,13 @@ server or MPM changes. On Unix, verify these pass locally by running `make check-pytest PYTEST_DIRS=test/modules/xxx` — this can be done without running `make install` first. +A module that only some tests in a package use goes in that package's +`add_optional_modules()`, not `add_modules()`, and those tests check +for it with `env.require(env.has_shared_module(...), ...)`. A module +listed in `add_modules()` that the build lacks stops setup with "Unable +to find modules", which fails every test in the package. See +`test/README.pytest` ("If your test needs a module"). + `test/` is kept identical on trunk and 2.4.x (`test/check-test-sync.sh`), so a new test reaches 2.4.x before the fix it tests. Any test that fails without the trunk change must carry a `not_backported` mark from diff --git a/test/README.pytest b/test/README.pytest index 30cc8f0274d..ed5eb6910fe 100644 --- a/test/README.pytest +++ b/test/README.pytest @@ -234,6 +234,23 @@ and cache the answer: @H2TestEnv.needs_h2load("1.41.0") @HttpdTestEnv.needs_multipart() +If your test needs a module, list it in the test package's +'*TestSetup' (its env.py). 'add_modules()' is for modules that +every test in the package needs: a build without one of them +stops setup with "Unable to find modules", so the whole package +fails. A module that only some of the tests use goes in +'add_optional_modules()', which loads it when it is there, and +the tests that use it check for it: + + env.require(env.has_shared_module("proxy_fcgi"), + "mod_proxy_fcgi not available", + dep="mod_proxy_fcgi", + detected=f"no mod_proxy_fcgi.so in {env.libexec_dir}") + +'has_shared_module()' is true for a module built as a DSO and for +one compiled into httpd. test/modules/proxy/test_13_fcgi_setenvif.py +is an example. + For a check that can only be made once the test is running, 'env.require()' does the same job from inside the body: @@ -268,12 +285,15 @@ This directory is the same on trunk and on 2.4.x: a test is written on trunk, then `test/` is copied to 2.4.x as it is, and `check-test-sync.sh` fails if the two branches differ. A test covering a trunk change that 2.4.x does not have yet carries a mark from `pyhttpd/backport.py` (or, in `pytest_suite/`, -`apache_pytest.not_backported`) naming the trunk revision: +`apache_pytest.not_backported`) naming the pull request that made the +change: from pyhttpd.backport import not_backported, skip_not_backported - @not_backported("r1939033", "nonce-count validation") - def test_digest_001(self, env): ... + @not_backported("gh-1096", "mod_substitute empty matches") + def test_filters_010_01(self, env): ... + +Older marks name svn revisions ("r1939033"), from before the move to git. `not_backported` makes the test an expected failure on a server older than 2.5.0, `skip_not_backported` skips it where failing would hang or crash the @@ -292,7 +312,7 @@ skipped, or failed under `--strict-optional`. When the change is backported, add the 2.4.x release it first appears in: - @not_backported("r1939033", "nonce-count validation", backported_in="2.4.71") + @not_backported("gh-1096", "mod_substitute empty matches", backported_in="2.4.72") on trunk, then copy `test/` to 2.4.x again. Older 2.4.x servers keep the expectation. `platform="win32"` limits it to one `sys.platform`. diff --git a/test/modules/filters/test_010_substitute_empty_match.py b/test/modules/filters/test_010_substitute_empty_match.py index 5a4a0bd48c3..b9f35cb01ca 100644 --- a/test/modules/filters/test_010_substitute_empty_match.py +++ b/test/modules/filters/test_010_substitute_empty_match.py @@ -2,6 +2,7 @@ import pytest +from pyhttpd.backport import not_backported, skip_not_backported from pyhttpd.conf import HttpdConf # Patterns that can match the empty string must not loop forever (or until @@ -33,6 +34,17 @@ 'mixed_empty_nonempty': ('b*', '-', 'f', 'abbc', '-a--c-'), } +# Without the change, most of these loop until "Line too long" is logged, +# and star_empty_* loop forever. +WHAT = "mod_substitute empty matches" +SKIP = skip_not_backported("gh-1096", WHAT, backported_in="2.4.72") +MARKS = { + 'anchor_nonempty': not_backported("gh-1096", WHAT, backported_in="2.4.72"), + 'lookbehind': (), +} +PARAMS = [pytest.param(name, id=name, marks=MARKS.get(name, SKIP)) + for name in CASES] + class TestSubstituteEmptyMatch: @@ -58,7 +70,7 @@ def configure(self, env, pattern, repl, flags): conf.install() assert env.apache_restart() == 0 - @pytest.mark.parametrize("name", list(CASES), ids=list(CASES)) + @pytest.mark.parametrize("name", PARAMS) def test_filters_010_01(self, env, name): pattern, repl, flags, _, expected = CASES[name] self.configure(env, pattern, repl, flags) diff --git a/test/modules/metadata/test_006_expr_backref.py b/test/modules/metadata/test_006_expr_backref.py index 4bfee9b223a..2fc7538baa3 100644 --- a/test/modules/metadata/test_006_expr_backref.py +++ b/test/modules/metadata/test_006_expr_backref.py @@ -1,5 +1,6 @@ import pytest +from pyhttpd.backport import skip_not_backported from pyhttpd.conf import HttpdConf # An expression that evaluates to true without evaluating a capturing regex @@ -15,6 +16,10 @@ LONG = "long-" + "x" * 200 +# Without r1915271 the Header edit* lines below crash every request, so +# none of the tests can run. +@skip_not_backported("r1915271", "mod_headers edit* recursion on empty matches", + backported_in="2.4.72") class TestExprBackref: @pytest.fixture(autouse=True, scope='class') diff --git a/test/modules/proxy/env.py b/test/modules/proxy/env.py index aa26f23ae09..3aa2870d58c 100644 --- a/test/modules/proxy/env.py +++ b/test/modules/proxy/env.py @@ -81,10 +81,12 @@ class ProxyTestSetup(HttpdTestSetup): def __init__(self, env: 'HttpdTestEnv'): super().__init__(env=env) self.add_source_dir(os.path.dirname(inspect.getfile(ProxyTestSetup))) - self.add_modules(["proxy", "proxy_http", "proxy_ajp", "proxy_balancer", - "proxy_connect", "proxy_uwsgi", "proxy_fcgi", - "lbmethod_byrequests", "remoteip"]) - self.add_optional_modules(["proxy_hcheck", "proxy_scgi"]) + self.add_modules(["proxy", "proxy_http", "proxy_balancer", + "proxy_connect", "lbmethod_byrequests", "remoteip"]) + # Modules only some tests use: a build without one skips those + # tests (env.require()) instead of failing setup for the package. + self.add_optional_modules(["proxy_hcheck", "proxy_scgi", "proxy_ajp", + "proxy_uwsgi", "proxy_fcgi"]) class ProxyTestEnv(HttpdTestEnv): diff --git a/test/modules/proxy/test_03_uwsgi.py b/test/modules/proxy/test_03_uwsgi.py index 07a7f616783..55ac601cb8e 100644 --- a/test/modules/proxy/test_03_uwsgi.py +++ b/test/modules/proxy/test_03_uwsgi.py @@ -44,6 +44,9 @@ class TestProxyUwsgi: @pytest.fixture(scope="class") def _proxy_uwsgi_setup(self, env): + env.require(env.has_shared_module("proxy_uwsgi"), "mod_proxy_uwsgi not available", + dep="mod_proxy_uwsgi", + detected=f"no mod_proxy_uwsgi.so in {env.libexec_dir}") faker = UwsgiFaker(port=UWSGI_PORT) faker.start() @@ -67,8 +70,9 @@ def _proxy_uwsgi_setup(self, env): @pytest.fixture(scope='class') def _class_scope(self, env): - if not env.has_shared_module("proxy_uwsgi"): - pytest.skip("mod_proxy_uwsgi not available") + env.require(env.has_shared_module("proxy_uwsgi"), "mod_proxy_uwsgi not available", + dep="mod_proxy_uwsgi", + detected=f"no mod_proxy_uwsgi.so in {env.libexec_dir}") faker = _UWSGIFaker("127.0.0.1", env.http_port2) faker.start() conf = HttpdConf(env) diff --git a/test/modules/proxy/test_13_fcgi_setenvif.py b/test/modules/proxy/test_13_fcgi_setenvif.py index 53e46fde9d1..cd52084b053 100644 --- a/test/modules/proxy/test_13_fcgi_setenvif.py +++ b/test/modules/proxy/test_13_fcgi_setenvif.py @@ -1,5 +1,6 @@ import pytest +from pyhttpd.backport import not_backported from pyhttpd.conf import HttpdConf from .fcgi_faker import FCGIFaker @@ -46,6 +47,8 @@ def get_params(self, env, headers): assert r.response["status"] == 200, r.response return r.response["json"] + @not_backported("gh-1096", "ProxyFCGISetEnvIf backreferences without a capturing match", + backported_in="2.4.72") def test_proxy_13_01_short_circuit(self, env): params = self.get_params(env, {"X-Match": "skip", "X-Prev": "previous"}) assert params["PREV_CAPTURE"] == "" diff --git a/test/pyhttpd/backport.py b/test/pyhttpd/backport.py index c258b48557a..44cfe5ba695 100644 --- a/test/pyhttpd/backport.py +++ b/test/pyhttpd/backport.py @@ -9,12 +9,15 @@ appears in, on trunk and copy the file over; older 2.4.x releases keep the expectation. - pytestmark = not_backported("r1939033", "nonce-count validation") + pytestmark = not_backported("gh-1096", "mod_substitute empty matches") - @skip_not_backported("r1938487", "recursion limit in mod_sed", - backported_in="2.4.71") + @skip_not_backported("gh-1096", "mod_substitute empty matches", + backported_in="2.4.72") def test_... +The first argument names the pull request that made the change ("gh-1096"). +Older marks name svn revisions ("r1939033"), from before the move to git. + platform limits the expectation to one sys.platform, for a failure on 2.4.x which trunk does not have there.