Skip to content

Commit

Permalink
ci(ingest/kafka): improve kafka integration test reliability (datahub…
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored May 25, 2023
1 parent 1478d70 commit 2d44216
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions metadata-ingestion/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ markers =
testpaths =
tests/unit
tests/integration
filterwarnings =
# Ignore some warnings that come from dependencies.
ignore:Deprecated call to \`pkg_resources.declare_namespace:DeprecationWarning
ignore:pkg_resources is deprecated as an API:DeprecationWarning
ignore:Did not recognize type:sqlalchemy.exc.SAWarning

[coverage:run]
# Because of some quirks in the way setup.cfg, coverage.py, pytest-cov,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
image: confluentinc/cp-zookeeper:7.2.0
env_file: zookeeper.env
hostname: test_zookeeper
container_name: test_zookeeper
ports:
- "52181"
volumes:
Expand Down
6 changes: 6 additions & 0 deletions metadata-ingestion/tests/integration/kafka/test_kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
def test_kafka_ingest(docker_compose_runner, pytestconfig, tmp_path, mock_time):
test_resources_dir = pytestconfig.rootpath / "tests/integration/kafka"

with docker_compose_runner(
test_resources_dir / "docker-compose.yml", "kafka", cleanup=False
) as docker_services:
wait_for_port(docker_services, "test_zookeeper", 52181, timeout=120)

# Running docker compose twice, since the broker sometimes fails to come up on the first try.
with docker_compose_runner(
test_resources_dir / "docker-compose.yml", "kafka"
) as docker_services:
Expand Down
4 changes: 4 additions & 0 deletions metadata-ingestion/tests/test_helpers/docker_helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import contextlib
import logging
import subprocess
from typing import Callable, Optional, Union

import pytest
import pytest_docker.plugin

logger = logging.getLogger(__name__)


def is_responsive(container_name: str, port: int, hostname: Optional[str]) -> bool:
"""A cheap way to figure out if a port is responsive on a container"""
Expand Down Expand Up @@ -37,6 +40,7 @@ def wait_for_port(
if checker
else lambda: is_responsive(container_name, container_port, hostname),
)
logger.info(f"Container {container_name} is ready!")
finally:
# use check=True to raise an error if command gave bad exit code
subprocess.run(f"docker logs {container_name}", shell=True, check=True)
Expand Down
5 changes: 5 additions & 0 deletions metadata-ingestion/tests/unit/test_packaging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import pytest

import datahub as datahub_metadata


@pytest.mark.filterwarnings(
"ignore:pkg_resources is deprecated as an API:DeprecationWarning"
)
def test_datahub_version():
# Simply importing pkg_resources checks for unsatisfied dependencies.
import pkg_resources
Expand Down

0 comments on commit 2d44216

Please sign in to comment.