From 3cb170c2830fcac847de56642c368441f9d095b9 Mon Sep 17 00:00:00 2001 From: roberto montero Date: Fri, 3 Nov 2023 17:09:47 +0100 Subject: [PATCH 1/3] Sleep mode for scenarios --- conftest.py | 8 ++++++++ docs/execute/run.md | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/conftest.py b/conftest.py index 6fcbb7a2fd..fa0e98d66f 100644 --- a/conftest.py +++ b/conftest.py @@ -31,6 +31,7 @@ def pytest_addoption(parser): "--scenario", "-S", type=str, action="store", default="DEFAULT", help="Unique identifier of scenario" ) parser.addoption("--replay", "-R", action="store_true", help="Replay tests based on logs") + parser.addoption("--sleep", action="store_true", help="Startup scenario without launching the tests (keep running)") parser.addoption( "--force-execute", "-F", action="append", default=[], help="Item to execute, even if they are skipped" ) @@ -203,6 +204,13 @@ def get_declared_scenario(item): for item in items: declared_scenario = get_declared_scenario(item) + # If we are running scenario with the option sleep, we only select sleep test classes + if session.config.option.sleep: + if declared_scenario == "SLEEP": + selected.append(item) + else: + deselected.append(item) + continue if ( declared_scenario == context.scenario.name diff --git a/docs/execute/run.md b/docs/execute/run.md index 8636d14d4a..8cc6f147db 100644 --- a/docs/execute/run.md +++ b/docs/execute/run.md @@ -33,7 +33,7 @@ If the test contains `@scenarios.SCENARIO_NAME` such as `@scenarios.integrations ## Spawn componenents, but do nothing ```bash -./run.sh SLEEP +./run.sh --sleep -# play with the weblog, and look inside logs/interfaces/ what's happening +# play with the weblog, and look inside logs_/interfaces/ what's happening ``` From f9f8143c02d8d79f958b20f548a7fb5590f41a13 Mon Sep 17 00:00:00 2001 From: roberto montero Date: Mon, 6 Nov 2023 13:32:25 +0100 Subject: [PATCH 2/3] sleep mode --- conftest.py | 24 ++++++++++++++++++------ tests/utils/test_sleep.py | 16 ---------------- 2 files changed, 18 insertions(+), 22 deletions(-) delete mode 100644 tests/utils/test_sleep.py diff --git a/conftest.py b/conftest.py index fa0e98d66f..6eb41460a9 100644 --- a/conftest.py +++ b/conftest.py @@ -2,6 +2,7 @@ # This product includes software developed at Datadog (https://www.datadoghq.com/). # Copyright 2021 Datadog, Inc. import json +import time import pytest from pytest_jsonreport.plugin import JSONReport @@ -64,6 +65,11 @@ def pytest_sessionstart(session): # get the terminal to allow logging directly in stdout setattr(logger, "terminal", session.config.pluginmanager.get_plugin("terminalreporter")) + if session.config.option.sleep: + logger.terminal.write("\n ********************************************************** \n") + logger.terminal.write(" *** .:: Sleep mode activated. Press Ctrl+C to exit ::. *** ") + logger.terminal.write("\n ********************************************************** \n\n") + if session.config.option.collectonly: return @@ -204,12 +210,9 @@ def get_declared_scenario(item): for item in items: declared_scenario = get_declared_scenario(item) - # If we are running scenario with the option sleep, we only select sleep test classes + # If we are running scenario with the option sleep, we deselect all if session.config.option.sleep: - if declared_scenario == "SLEEP": - selected.append(item) - else: - deselected.append(item) + deselected.append(item) continue if ( @@ -228,7 +231,6 @@ def get_declared_scenario(item): else: logger.debug(f"{item.nodeid} is not included in {context.scenario}") deselected.append(item) - items[:] = selected config.hook.pytest_deselected(items=deselected) @@ -257,6 +259,16 @@ def pytest_collection_finish(session): if session.config.option.collectonly: return + if session.config.option.sleep: # on this mode, we simply sleep, not running any test or setup + try: + while True: + time.sleep(1) + except KeyboardInterrupt: # catching ctrl+C + context.scenario.close_targets() + return + except Exception as e: + raise e + last_item_file = "" for item in session.items: diff --git a/tests/utils/test_sleep.py b/tests/utils/test_sleep.py deleted file mode 100644 index b2bf107b7e..0000000000 --- a/tests/utils/test_sleep.py +++ /dev/null @@ -1,16 +0,0 @@ -# Unless explicitly stated otherwise all files in this repository are licensed under the the Apache License Version 2.0. -# This product includes software developed at Datadog (https://www.datadoghq.com/). -# Copyright 2021 Datadog, Inc. - -import time -from utils import scenarios - - -@scenarios.sleep -class Test_Sleep: - def setup_sleep(self): - """Sleep forever to allow you to perform some manual testing""" - time.sleep(3600 * 24) - - def test_sleep(self): - pass From 3f1b801e699e7b32e1d5dd9a5da371a8504c6720 Mon Sep 17 00:00:00 2001 From: roberto montero Date: Mon, 6 Nov 2023 15:21:16 +0100 Subject: [PATCH 3/3] remove sleep scenario --- utils/_context/_scenarios.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/utils/_context/_scenarios.py b/utils/_context/_scenarios.py index 07a159edca..00b0767289 100644 --- a/utils/_context/_scenarios.py +++ b/utils/_context/_scenarios.py @@ -949,10 +949,6 @@ class scenarios: include_postgres_db=True, doc="Default scenario, spwan tracer and agent, and run most of exisiting tests", ) - sleep = EndToEndScenario( - "SLEEP", - doc="Fake scenario that spawn tracer and agentm then sleep indefinitly. Help you to manually test container", - ) # performance scenario just spawn an agent and a weblog, and spies the CPU and mem usage performances = PerformanceScenario(