Skip to content

Commit a616465

Browse files
committed
feat: update test workflow and refactor OPAL server/client configurations to use session matrix
1 parent 3467931 commit a616465

File tree

4 files changed

+18
-61
lines changed

4 files changed

+18
-61
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Tests
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [ e2e-add-kafka-fix ]
99
pull_request:
10-
branches: [ master ]
10+
branches: [ e2e-add-kafka-fix ]
1111

1212
# Allows you to run this workflow manually from the Actions tab
1313
workflow_dispatch:

tests/conftest.py

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,6 @@ def opal_network():
9797
else:
9898
logger.error(f"Failed to remove network got exception\n{e}")
9999

100-
@pytest.fixture(scope="session")
101-
def number_of_opal_servers():
102-
"""The number of OPAL servers to start.
103-
104-
This fixture is used to determine how many OPAL servers to start for
105-
the tests. The default value is 2, but it can be overridden by setting
106-
the environment variable OPAL_TESTS_NUMBER_OF_OPAL_SERVERS.
107-
108-
Returns:
109-
int: The number of OPAL servers to start.
110-
"""
111-
return 2
112-
113-
114100
from tests.fixtures.broadcasters import (
115101
broadcast_channel,
116102
kafka_broadcast_channel,
@@ -125,9 +111,7 @@ def number_of_opal_servers():
125111
def opal_servers(
126112
opal_network: Network,
127113
policy_repo,
128-
number_of_opal_servers: int,
129114
opal_server_image: str,
130-
topics: dict[str, int],
131115
broadcast_channel: BroadcastContainerBase,
132116
# kafka_broadcast_channel: KafkaContainer,
133117
# redis_broadcast_channel: RedisBroadcastContainer,
@@ -167,7 +151,7 @@ def opal_servers(
167151
containers = [] # List to store container instances
168152

169153

170-
for i in range(number_of_opal_servers):
154+
for i in range(session_matrix["number_of_opal_servers"]):
171155
container_name = f"opal_server_{i+1}"
172156

173157
repo_url = policy_repo.get_repo_url()
@@ -180,7 +164,7 @@ def opal_servers(
180164
policy_repo_url=repo_url,
181165
image=opal_server_image,
182166
log_level="DEBUG",
183-
data_topics=" ".join(topics.keys()),
167+
data_topics=" ".join(session_matrix["topics"].keys()),
184168
polling_interval=3,
185169
policy_repo_main_branch=policy_repo.test_branch,
186170
),
@@ -209,18 +193,6 @@ def opal_servers(
209193
for container in containers:
210194
container.stop()
211195

212-
213-
@pytest.fixture(scope="session")
214-
def number_of_opal_clients():
215-
"""The number of OPAL clients to start.
216-
217-
This fixture is used to determine how many OPAL clients to start for
218-
the tests. The default value is 2, but it can be overridden by
219-
setting the environment variable OPAL_TESTS_NUMBER_OF_OPAL_CLIENTS.
220-
"""
221-
return 2
222-
223-
224196
@pytest.fixture(scope="session")
225197
def connected_clients(opal_clients: List[OpalClientContainer]):
226198
"""A fixture that waits for all OPAL clients to connect to the PubSub
@@ -264,7 +236,7 @@ def opal_clients(
264236
# opa_server: OpaContainer,
265237
# cedar_server: CedarContainer,
266238
request,
267-
number_of_opal_clients: int,
239+
session_matrix,
268240
opal_client_with_opa_image,
269241
):
270242
"""A fixture that starts and manages multiple OPAL client containers.
@@ -303,7 +275,7 @@ def opal_clients(
303275

304276
containers = [] # List to store OpalClientContainer instances
305277

306-
for i in range(number_of_opal_clients):
278+
for i in range(session_matrix["number_of_opal_clients"]):
307279
container_name = f"opal_client_{i+1}" # Unique name for each client
308280

309281
client_token = opal_servers[0].obtain_OPAL_tokens(container_name)["client"]
@@ -355,26 +327,8 @@ def opal_clients(
355327
logger.error(f"Failed to stop containers: {container}")
356328
pass
357329

358-
359330
@pytest.fixture(scope="session")
360-
def topics():
361-
"""A fixture that returns a dictionary mapping topic names to the number of
362-
OpalClientContainer instances that should subscribe to each topic.
363-
364-
Returns
365-
-------
366-
dict
367-
A dictionary mapping topic names to the number of OpalClientContainer
368-
instances that should subscribe to each topic.
369-
"""
370-
topics = {"topic_1": 1, "topic_2": 1}
371-
return topics
372-
373-
374-
@pytest.fixture(scope="session")
375-
def topiced_clients(
376-
topics, opal_network: Network, opal_servers: list[OpalServerContainer]
377-
):
331+
def topiced_clients(opal_network: Network, opal_servers: list[OpalServerContainer], session_matrix):
378332
"""Fixture that starts and manages multiple OPAL client containers, each
379333
subscribing to a different topic.
380334
@@ -427,7 +381,7 @@ def topiced_clients(
427381
}
428382
)
429383

430-
for topic, number_of_clients in topics.items():
384+
for topic, number_of_clients in session_matrix["topics"].items():
431385
for i in range(number_of_clients):
432386
container_name = f"opal_client_{topic}_{i+1}" # Unique name for each client
433387

tests/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ def __next__(self):
177177
"skip_rebuild_images": pytest_settings.skip_rebuild_images,
178178
"keep_images": pytest_settings.keep_images,
179179

180+
"number_of_opal_servers": 2,
181+
"number_of_opal_clients": 2,
182+
"topics": {"topic_1": 1, "topic_2": 1},
180183
}
181184

182185
print("Finished iterating over PyTestSessionSettings...")

tests/test_app.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,18 @@ async def test_policy_and_data_updates(
207207

208208

209209
@pytest.mark.parametrize("attempts", [10]) # Number of attempts to repeat the check
210-
def test_read_statistics(
211-
attempts,
212-
opal_servers: list[OpalServerContainer],
213-
number_of_opal_servers: int,
214-
number_of_opal_clients: int,
215-
):
210+
def test_read_statistics(attempts, opal_servers: list[OpalServerContainer], session_matrix,):
216211
"""Tests the statistics feature by verifying the number of clients and
217212
servers."""
218213

219214
logger.info("- Testing statistics feature")
220215

221-
time.sleep(15)
216+
217+
218+
number_of_opal_servers = session_matrix["number_of_opal_servers"]
219+
number_of_opal_clients = session_matrix["number_of_opal_clients"]
220+
221+
time.sleep(5)
222222

223223
for server in opal_servers:
224224
logger.info(f"OPAL Server: {server.settings.container_name}:7002")

0 commit comments

Comments
 (0)