Skip to content

Commit b9018cb

Browse files
committed
making tests more port-independent and applying a little bit of DRY
1 parent 034d2c2 commit b9018cb

File tree

9 files changed

+73
-106
lines changed

9 files changed

+73
-106
lines changed

noxfile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# Define which Python versions to test with
44
PYPROJECT = nox.project.load_toml("pyproject.toml")
55
PYTHON_VERSIONS = nox.project.python_versions(PYPROJECT)
6-
DEFAULT_PYTHON = "3.10" # Arbitrary decision, choose a reliable version
6+
DEFAULT_PYTHON = "3.10" # Modern-ish version compatible with the legacy-deps
77

88
# Default sessions (these will be executed in Github Actions)
99
# Maintain a clear separation between code checking and code altering tasks (don't add format)
10-
nox.options.sessions = ["lint", "tests"]
10+
nox.options.sessions = ["lint", "tests", "legacy_deps_tests"]
1111
# nox.options.reuse_existing_virtualenvs = True # TODO: Check if necessary
1212

1313

tests/conftest.py

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
import sys
2+
3+
import pytest
4+
5+
6+
@pytest.fixture(scope="session")
7+
def python_version():
8+
return f"{sys.version_info.major}.{sys.version_info.minor}"
9+
10+
11+
@pytest.fixture(scope="session")
12+
def docker_setup(python_version, request):
13+
legacy_deps = request.config.getoption("--build-legacy-deps")
14+
legacy_arg = f" --build-arg LEGACY_DEPS=True " if legacy_deps else " "
15+
return [
16+
f"build{ legacy_arg }--build-arg PYTHON_VERSION={python_version}-bookworm",
17+
"up -d",
18+
]
19+
20+
21+
@pytest.fixture(scope="session")
22+
def proxy_connection(docker_ip, docker_services):
23+
proxy_port = docker_services.port_for("proxy", 8676)
24+
return "127.0.0.1", proxy_port
25+
26+
27+
@pytest.fixture(scope="session")
28+
def mds_connection(docker_ip, docker_services):
29+
mds_port = docker_services.port_for("metadata-service", 16587)
30+
return "127.0.0.1", mds_port
31+
32+
133
def pytest_addoption(parser):
234
parser.addoption(
335
"--build-legacy-deps",

tests/functional/conftest.py

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
11
import os
2-
import sys
32

43
import grpc
54
import pytest
65

76

8-
@pytest.fixture(scope="session")
9-
def python_version():
10-
return f"{sys.version_info.major}.{sys.version_info.minor}"
11-
12-
13-
@pytest.fixture(scope="session")
14-
def docker_setup(python_version, request):
15-
legacy_deps = request.config.getoption("--build-legacy-deps")
16-
legacy_arg = f" --build-arg LEGACY_DEPS=True " if legacy_deps else " "
17-
return [
18-
f"build{ legacy_arg }--build-arg PYTHON_VERSION={python_version}-bookworm",
19-
"up -d",
20-
]
21-
22-
237
@pytest.fixture(scope="session")
248
def docker_compose_file(pytestconfig):
259
return os.path.join(str(pytestconfig.rootdir), "tests/functional", "docker-compose.yml")
2610

2711

2812
@pytest.fixture(scope="session")
29-
def deploy_dataclay(docker_ip, docker_services):
13+
def wait_dataclay(mds_connection):
3014
"""Ensure that services are up and responsive."""
3115

32-
mds_port = docker_services.port_for("metadata-service", 16587)
33-
grpc.channel_ready_future(grpc.insecure_channel(f"127.0.0.1:{mds_port}")).result(timeout=10)
16+
mds_host, mds_port = mds_connection
17+
grpc.channel_ready_future(grpc.insecure_channel(f"{mds_host}:{mds_port}")).result(timeout=10)
3418

3519
# TODO: Wait for the backend to be ready before starting the tests
3620
# NOTE: Below code is not working since it is not the correct ip
@@ -40,10 +24,11 @@ def deploy_dataclay(docker_ip, docker_services):
4024

4125

4226
@pytest.fixture(scope="session")
43-
def client(deploy_dataclay):
27+
def client(wait_dataclay, mds_connection):
4428
import dataclay
4529

46-
client = dataclay.Client(host="127.0.0.1")
30+
mds_host, mds_port = mds_connection
31+
client = dataclay.Client(host=mds_host, port=mds_port)
4732
client.start()
4833
yield client
4934
client.stop()

tests/functional/docker-compose.legacy-deps.yml

-6
This file was deleted.

tests/functional/docker-compose.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ services:
22

33
redis:
44
image: redis:latest
5-
ports:
6-
- 6379:6379
75

86
metadata-service:
97
image: "ghcr.io/bsc-dom/dataclay:dev"
@@ -16,7 +14,7 @@ services:
1614
depends_on:
1715
- redis
1816
ports:
19-
- 16587:16587
17+
- 16587
2018
environment:
2119
- DATACLAY_KV_HOST=redis
2220
- DATACLAY_KV_PORT=6379
@@ -69,7 +67,7 @@ services:
6967
proxy:
7068
image: "ghcr.io/bsc-dom/dataclay:dev"
7169
ports:
72-
- 8676:8676
70+
- 8676
7371
depends_on:
7472
- metadata-service
7573
- backend_1

tests/functional/test_client.py

-9
This file was deleted.

tests/proxy/conftest.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
3+
import grpc
4+
import pytest
5+
6+
7+
@pytest.fixture(scope="session")
8+
def docker_compose_file(pytestconfig):
9+
return os.path.join(str(pytestconfig.rootdir), "tests/proxy", "docker-compose.yml")
10+
11+
12+
@pytest.fixture(scope="session")
13+
def wait_dataclay(proxy_connection):
14+
"""Ensure that services are up and responsive."""
15+
16+
proxy_host, proxy_port = proxy_connection
17+
grpc.channel_ready_future(grpc.insecure_channel(f"{proxy_host}:{proxy_port}")).result(timeout=10)
18+
19+
# backend_port = docker_services.port_for("backend", 6867)
20+
# grpc.channel_ready_future(grpc.insecure_channel(f"127.0.0.1:{backend_port}")).result(timeout=10)
21+
+5-32
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
1-
import os
2-
import sys
3-
4-
import grpc
51
import pytest
62

73
import dataclay
84

95

106
@pytest.fixture(scope="session")
11-
def python_version():
12-
return f"{sys.version_info.major}.{sys.version_info.minor}"
13-
14-
15-
@pytest.fixture(scope="session")
16-
def docker_setup(python_version):
17-
return [f"build --build-arg PYTHON_VERSION={python_version}-bookworm", "up -d"]
18-
19-
20-
@pytest.fixture(scope="session")
21-
def docker_compose_file(pytestconfig):
22-
return os.path.join(str(pytestconfig.rootdir), "tests/proxy", "docker-compose.yml")
23-
24-
25-
@pytest.fixture(scope="session")
26-
def deploy_dataclay(docker_ip, docker_services):
27-
"""Ensure that services are up and responsive."""
28-
29-
proxy_port = docker_services.port_for("proxy", 8676)
30-
grpc.channel_ready_future(grpc.insecure_channel(f"127.0.0.1:{proxy_port}")).result(timeout=10)
31-
32-
# backend_port = docker_services.port_for("backend", 6867)
33-
# grpc.channel_ready_future(grpc.insecure_channel(f"127.0.0.1:{backend_port}")).result(timeout=10)
34-
35-
36-
@pytest.fixture(scope="session")
37-
def client(deploy_dataclay):
38-
client = dataclay.Client(proxy_host="127.0.0.1", username="Marc", password="s3cret")
7+
def client(wait_dataclay, proxy_connection):
8+
proxy_host, proxy_port = proxy_connection
9+
client = dataclay.Client(
10+
proxy_host=proxy_host, proxy_port=proxy_port, username="Marc", password="s3cret"
11+
)
3912
client.start()
4013
yield client
4114
client.stop()

tests/proxy/proxy_owner/conftest.py

+5-32
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
1-
import os
2-
import sys
3-
4-
import grpc
51
import pytest
62

73
import dataclay
84

95

106
@pytest.fixture(scope="session")
11-
def python_version():
12-
return f"{sys.version_info.major}.{sys.version_info.minor}"
13-
14-
15-
@pytest.fixture(scope="session")
16-
def docker_setup(python_version):
17-
return [f"build --build-arg PYTHON_VERSION={python_version}-bookworm", "up -d"]
18-
19-
20-
@pytest.fixture(scope="session")
21-
def docker_compose_file(pytestconfig):
22-
return os.path.join(str(pytestconfig.rootdir), "tests/proxy", "docker-compose.yml")
23-
24-
25-
@pytest.fixture(scope="session")
26-
def deploy_dataclay(docker_ip, docker_services):
27-
"""Ensure that services are up and responsive."""
28-
29-
proxy_port = docker_services.port_for("proxy", 8676)
30-
grpc.channel_ready_future(grpc.insecure_channel(f"127.0.0.1:{proxy_port}")).result(timeout=10)
31-
32-
# backend_port = docker_services.port_for("backend", 6867)
33-
# grpc.channel_ready_future(grpc.insecure_channel(f"127.0.0.1:{backend_port}")).result(timeout=10)
34-
35-
36-
@pytest.fixture(scope="session")
37-
def client(deploy_dataclay):
38-
client = dataclay.Client(proxy_host="127.0.0.1", username="Alex", password="s3cret")
7+
def client(wait_dataclay, proxy_connection):
8+
proxy_host, proxy_port = proxy_connection
9+
client = dataclay.Client(
10+
proxy_host=proxy_host, proxy_port=proxy_port, username="Alex", password="s3cret"
11+
)
3912
client.start()
4013
yield client
4114
client.stop()

0 commit comments

Comments
 (0)