Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sleep mode for scenarios #1794

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,6 +32,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"
)
Expand Down Expand Up @@ -63,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

Expand Down Expand Up @@ -203,6 +210,10 @@ 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 deselect all
if session.config.option.sleep:
deselected.append(item)
continue

if (
declared_scenario == context.scenario.name
Expand All @@ -220,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)

Expand Down Expand Up @@ -249,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:

Expand Down
4 changes: 2 additions & 2 deletions docs/execute/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SCENARIO_NAME> --sleep

# play with the weblog, and look inside logs/interfaces/ what's happening
# play with the weblog, and look inside logs_<scenario_name>/interfaces/ what's happening
```
16 changes: 0 additions & 16 deletions tests/utils/test_sleep.py

This file was deleted.

4 changes: 0 additions & 4 deletions utils/_context/_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down