Skip to content

Commit 3099cfe

Browse files
authored
In e2e tests, wait for ingested data to become available, and run a connectivity_test before e2e tests (#193)
* In e2e tests, wait for ingested data to become available, and run a connectivity_test before e2e tests * Code review fix * Move sleep :-) * Add --capture=no to the connectivity test * pre-commit
1 parent c21679d commit 3099cfe

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

.github/workflows/tests-e2e.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ jobs:
6060
NEPTUNE_QUERY_RETRY_SOFT_TIMEOUT: "120"
6161
TEST_MARKERS: ${{ matrix.test_markers }}
6262
run: |
63-
pytest --retries=3 --retry-delay=2 --junitxml="test-results/test-e2e.xml" ${TEST_MARKERS:+-m "$TEST_MARKERS"} tests/e2e
63+
pytest --capture=no tests/e2e/test_connectivity.py &&
64+
pytest --retries=1 --retry-delay=2 --junitxml="test-results/test-e2e.xml" ${TEST_MARKERS:+-m "$TEST_MARKERS"} tests/e2e
65+
# --capture=no is passed to the test_connectivity run, so that we can see logs from data ingestion
66+
# This helps with debugging. At the very least, it shows the URL of the environment under test
6467

6568
- name: Notify on failure
6669
if: failure() && github.event_name == 'schedule'

tests/e2e/data_ingestion.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import neptune_scale.types
2626
from neptune_api import AuthenticatedClient
2727

28+
from neptune_query.internal.identifiers import ProjectIdentifier
29+
from neptune_query.internal.retrieval import search
30+
2831
IngestionHistogram = neptune_scale.types.Histogram
2932
IngestionFile = neptune_scale.types.File
3033

@@ -110,6 +113,30 @@ def get_run_by_run_id(self: IngestedProjectData, run_id: str) -> IngestedRunData
110113
raise ValueError(f"Run not found: {run_id}")
111114

112115

116+
def _wait_for_ingestion(
117+
client: AuthenticatedClient, project_identifier: ProjectIdentifier, expected_data: ProjectData
118+
) -> None:
119+
for attempt in range(20):
120+
found_runs = 0
121+
122+
for page in search.fetch_run_sys_ids(
123+
client=client,
124+
project_identifier=project_identifier,
125+
filter_=None,
126+
):
127+
found_runs += len(page.items)
128+
129+
if found_runs == len(expected_data.runs):
130+
return
131+
132+
# Next attempt in 2 seconds, please
133+
sleep(2)
134+
135+
raise RuntimeError(
136+
f"Timed out waiting for data ingestion, " f"found runs: {found_runs} out of expected: {len(expected_data.runs)}"
137+
)
138+
139+
113140
def ingest_project(
114141
*,
115142
client: AuthenticatedClient,
@@ -143,6 +170,8 @@ def ingest_project(
143170
project_data=project_data,
144171
)
145172

173+
_wait_for_ingestion(client=client, project_identifier=project_identifier, expected_data=project_data)
174+
146175
return IngestedProjectData(
147176
project_identifier=project_identifier,
148177
ingested_runs=[
@@ -222,8 +251,6 @@ def _ingest_runs(runs_data: list[RunData], api_token: str, project_identifier: s
222251
for run in runs:
223252
run.close()
224253

225-
sleep(2) # Extra wait to ensure data is available to query before proceeding
226-
227254

228255
def _get_all_steps(run_data: RunData) -> Iterable[float]:
229256
# Collect all unique steps

tests/e2e/test_connectivity.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
3+
from tests.e2e.conftest import EnsureProjectFunction
4+
from tests.e2e.data_ingestion import (
5+
IngestedProjectData,
6+
ProjectData,
7+
RunData,
8+
)
9+
10+
11+
@pytest.fixture(scope="module")
12+
def project_1(ensure_project: EnsureProjectFunction) -> IngestedProjectData:
13+
return ensure_project(
14+
project_data=ProjectData(
15+
runs=[
16+
RunData(
17+
experiment_name="test_connectivity_experiment",
18+
run_id="test_connectivity_run",
19+
configs={"im_alive": 1},
20+
),
21+
]
22+
)
23+
)
24+
25+
26+
def test_connectivity(client, project_1: IngestedProjectData) -> None:
27+
"""A placeholder test to ensure connectivity to the Neptune server"""
28+
assert True

0 commit comments

Comments
 (0)