Skip to content

Commit

Permalink
Improve parametric scenario output (#3334)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeauchesne authored Oct 29, 2024
1 parent 92adbe0 commit e02dd69
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/parametric/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ def test_agent(
Stop the agent on port {test_agent_port} and try again."""
pytest.fail(message, pytrace=False)

logger.info("Test agent is ready")
break
else:
with open(test_agent_log_file.name) as f:
Expand Down
25 changes: 22 additions & 3 deletions utils/parametric/_library_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from docker.models.containers import Container
import grpc
import pytest
from _pytest.outcomes import Failed
import requests

from utils.parametric.protos import apm_test_client_pb2 as pb
Expand All @@ -15,6 +16,12 @@
from utils.tools import logger


def _fail(message):
""" Used to mak a test as failed """
logger.error(message)
raise Failed(message, pytrace=False) from None


class StartSpanResponse(TypedDict):
span_id: int
trace_id: int
Expand Down Expand Up @@ -191,11 +198,23 @@ def _wait(self, timeout):
except Exception:
self.container.reload()
if self.container.status != "running":
message = f"Container {self.container.name} status is {self.container.status}"
raise RuntimeError(message)
self._print_logs()
message = f"Container {self.container.name} status is {self.container.status}. Please check logs."
_fail(message)

logger.debug(f"Wait for {delay}s for the HTTP library to be ready")
time.sleep(delay)
else:
raise RuntimeError(f"Timeout of {timeout} seconds exceeded waiting for HTTP server to start")
self._print_logs()
message = f"Timeout of {timeout} seconds exceeded waiting for HTTP server to start. Please check logs."
_fail(message)

def _print_logs(self):
try:
logs = self.container.logs().decode("utf-8")
logger.debug(f"Logs from container {self.container.name}:\n\n{logs}")
except Exception:
logger.error(f"Failed to get logs from container {self.container.name}")

def _url(self, path: str) -> str:
return urllib.parse.urljoin(self._base_url, path)
Expand Down
3 changes: 3 additions & 0 deletions utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def stdout(self, message, *args, **kws):
def get_logger(name="tests", use_stdout=False):
result = logging.getLogger(name)

logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)

if use_stdout:
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(logging.DEBUG)
Expand Down

0 comments on commit e02dd69

Please sign in to comment.