88import re
99from base64 import urlsafe_b64encode
1010from collections import namedtuple # Not using dataclasses for Py2 compatibility
11+ from collections .abc import Collection
1112from io import open
1213from typing import Dict , List , Literal , Optional , Tuple , overload # noqa: F401
1314
@@ -238,7 +239,7 @@ def run_check(config=None, **kwargs):
238239
239240
240241@pytest .fixture
241- def dd_agent_check_discovery (dd_agent_check ):
242+ def dd_agent_check_discovery (dd_agent_check , is_process_e2e ):
242243 """Wrapper around ``dd_agent_check`` for config-discovery e2e tests.
243244
244245 Passes the empty-instances config required to let ``auto_conf.yaml`` drive
@@ -248,7 +249,13 @@ def dd_agent_check_discovery(dd_agent_check):
248249 if not e2e_testing ():
249250 pytest .skip ('Not running E2E tests' )
250251
251- def run (* , discovery_min_instances = 1 , discovery_timeout = 30 , ** kwargs ):
252+ # Process autodiscovery needs to wait for the agent to recognize the process
253+ # as a service which happens after a minimum process age of 1 minute. This
254+ # time can be reduced significantly once agent-side support for reducing the
255+ # minimum age via configuration is available.
256+ extra_timeout = 60 if is_process_e2e else 0
257+
258+ def run (* , discovery_min_instances = 1 , discovery_timeout = 30 + extra_timeout , ** kwargs ):
252259 return dd_agent_check (
253260 {'init_config' : {}, 'instances' : []},
254261 discovery_min_instances = discovery_min_instances ,
@@ -483,12 +490,29 @@ def enum_object_items(data_source, machine_name, object_name, detail_level):
483490)
484491
485492
493+ def _is_process_e2e_env () -> bool :
494+ return os .getenv ('DDEV_E2E_PROCESS_DISCOVERY' , 'false' ) == 'true'
495+
496+
497+ def _should_skip_in_process_e2e (keywords : Collection [str ]) -> bool :
498+ """In the process-autodiscovery e2e env, only ``process_e2e`` tests run."""
499+ return 'process_e2e' not in keywords
500+
501+
502+ @pytest .fixture (scope = 'session' )
503+ def is_process_e2e () -> bool :
504+ return _is_process_e2e_env ()
505+
506+
486507def pytest_configure (config ):
487508 # pytest will emit warnings if these aren't registered ahead of time
488509 for ttype in TEST_TYPES :
489510 config .addinivalue_line ('markers' , '{}: {}' .format (ttype .name , ttype .description ))
490511
491512 config .addinivalue_line ("markers" , "latest_metrics: marker for verifying support of new metrics" )
513+ config .addinivalue_line (
514+ "markers" , "process_e2e: also run this e2e test in the process autodiscovery e2e environment"
515+ )
492516
493517
494518def pytest_addoption (parser ):
@@ -498,16 +522,22 @@ def pytest_addoption(parser):
498522def pytest_collection_modifyitems (config , items ):
499523 # at test collection time, this function gets called by pytest, see:
500524 # https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option
501- # if the particular option is not present, it will skip all tests marked `latest_metrics`
502- if config .getoption ("--run-latest-metrics" ):
503- # --run-check-metrics given in cli: do not skip slow tests
504- return
525+ skip_latest_metrics = (
526+ None
527+ if config .getoption ("--run-latest-metrics" )
528+ else pytest .mark .skip (reason = "need --run-latest-metrics option to run" )
529+ )
530+ skip_non_process_e2e = (
531+ pytest .mark .skip (reason = "not a process autodiscovery e2e test" ) if _is_process_e2e_env () else None
532+ )
505533
506- skip_latest_metrics = pytest .mark .skip (reason = "need --run-latest-metrics option to run" )
507534 for item in items :
508- if "latest_metrics" in item .keywords :
535+ if skip_latest_metrics and "latest_metrics" in item .keywords :
509536 item .add_marker (skip_latest_metrics )
510537
538+ if skip_non_process_e2e and _should_skip_in_process_e2e (item .keywords ):
539+ item .add_marker (skip_non_process_e2e )
540+
511541 item_path = item .path
512542 if item_path is None :
513543 continue
0 commit comments