Skip to content

Commit d30e915

Browse files
authored
PLM-160: Improve CI e2e tests (#108)
1 parent b36d43f commit d30e915

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

.github/workflows/e2etests.yml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,14 @@ jobs:
4141
run: |
4242
make test-build
4343
44-
- name: Run PLM
45-
run: |
46-
echo "Starting project..."
47-
bin/plm_test \
48-
--source="mongodb://source:pass@rs00:30000" \
49-
--target="mongodb://target:pass@rs10:30100" \
50-
--reset-state --start --log-level debug &> server.log &
51-
echo $! > server.pid
52-
sleep 5
53-
echo "Project started with PID $(cat server.pid)"
54-
cat server.log
55-
5644
- name: Run tests (pytest)
5745
run: |
5846
export TEST_SOURCE_URI=mongodb://adm:pass@rs00:30000
5947
export TEST_TARGET_URI=mongodb://adm:pass@rs10:30100
6048
export TEST_PLM_URL=http://127.0.0.1:2242
61-
poetry run pytest
49+
export TEST_PLM_BIN=./bin/plm_test
6250
63-
- name: Show server logs (on failure)
64-
if: failure()
65-
run: tail -n 500 server.log
51+
poetry run pytest
6652
6753
- name: Teardown Docker Compose
6854
if: always()

tests/conftest.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,25 @@ def pytest_collection_modifyitems(config, items):
3434
if "slow" in item.keywords:
3535
item.add_marker(skip_slow)
3636

37+
def source_uri(request: pytest.FixtureRequest):
38+
"""Provide the source MongoDB URI."""
39+
return request.config.getoption("--source-uri") or os.environ["TEST_SOURCE_URI"]
40+
41+
def target_uri(request: pytest.FixtureRequest):
42+
"""Provide the target MongoDB URI."""
43+
return request.config.getoption("--target-uri") or os.environ["TEST_TARGET_URI"]
3744

3845
@pytest.fixture(scope="session")
3946
def source_conn(request: pytest.FixtureRequest):
4047
"""Provide a MongoClient connection to the source MongoDB."""
41-
uri = request.config.getoption("--source-uri") or os.environ["TEST_SOURCE_URI"]
42-
with MongoClient(uri) as conn:
48+
with MongoClient(source_uri(request)) as conn:
4349
yield conn
4450

4551

4652
@pytest.fixture(scope="session")
4753
def target_conn(request: pytest.FixtureRequest):
4854
"""Provide a MongoClient connection to the target MongoDB."""
49-
uri = request.config.getoption("--target-uri") or os.environ["TEST_TARGET_URI"]
50-
with MongoClient(uri) as conn:
55+
with MongoClient(target_uri(request)) as conn:
5156
yield conn
5257

5358

@@ -76,11 +81,13 @@ def drop_all_database(source_conn: MongoClient, target_conn: MongoClient):
7681
testing.drop_all_database(target_conn)
7782

7883

79-
PML_PROC: subprocess.Popen = None
84+
PLM_PROC: subprocess.Popen = None
8085

8186

82-
def start_plm(plm_bin: str):
83-
rv = subprocess.Popen([plm_bin, "--reset-state", "--log-level=trace"])
87+
def start_plm(plm_bin: str, request: pytest.FixtureRequest):
88+
source = source_uri(request)
89+
target = target_uri(request)
90+
rv = subprocess.Popen([plm_bin,"--source", source ,"--target", target, "--reset-state", "--log-level=trace"])
8491
time.sleep(1)
8592
return rv
8693

@@ -97,15 +104,15 @@ def manage_plm_process(request: pytest.FixtureRequest, plm_bin: str):
97104
yield
98105
return
99106

100-
global PML_PROC # pylint: disable=W0603
101-
PML_PROC = start_plm(plm_bin)
107+
global PLM_PROC # pylint: disable=W0603
108+
PLM_PROC = start_plm(plm_bin, request)
102109

103110
def teardown():
104-
if PML_PROC and PML_PROC.poll() is None:
105-
stop_plm(PML_PROC)
111+
if PLM_PROC and PLM_PROC.poll() is None:
112+
stop_plm(PLM_PROC)
106113

107114
request.addfinalizer(teardown)
108-
yield PML_PROC
115+
yield PLM_PROC
109116

110117

111118
@pytest.hookimpl(hookwrapper=True)
@@ -122,7 +129,7 @@ def restart_plm_on_failure(request: pytest.FixtureRequest, plm_bin: str):
122129

123130
if hasattr(request.node, "rep_call") and request.node.rep_call.failed:
124131
# the test failed. restart plm process with a new state
125-
global PML_PROC # pylint: disable=W0603
126-
if PML_PROC and plm_bin:
127-
stop_plm(PML_PROC)
128-
PML_PROC = start_plm(plm_bin)
132+
global PLM_PROC # pylint: disable=W0603
133+
if PLM_PROC and plm_bin:
134+
stop_plm(PLM_PROC)
135+
PLM_PROC = start_plm(plm_bin, request)

tests/test_collections.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import random
33
from datetime import datetime
44

5+
import time
56
import pytest
67
import testing
78
from plm import PLM, Runner
@@ -125,7 +126,7 @@ def test_create_view_with_collation(t: Testing, phase: Runner.Phase):
125126
t.compare_all()
126127

127128

128-
@pytest.mark.timeout(15)
129+
@pytest.mark.timeout(20)
129130
@pytest.mark.parametrize("phase", [Runner.Phase.APPLY, Runner.Phase.CLONE])
130131
def test_create_timeseries_ignored(t: Testing, phase: Runner.Phase):
131132
with t.run(phase):
@@ -327,7 +328,7 @@ def test_modify_view(t: Testing, phase: Runner.Phase):
327328
t.compare_all()
328329

329330

330-
@pytest.mark.timeout(15)
331+
@pytest.mark.timeout(20)
331332
@pytest.mark.parametrize("phase", [Runner.Phase.APPLY, Runner.Phase.CLONE])
332333
def test_modify_timeseries_options_ignored(t: Testing, phase: Runner.Phase):
333334
t.source["db_1"].create_collection(
@@ -598,6 +599,8 @@ def test_plm_110_rename_during_clone_and_repl(t: Testing):
598599
r.start()
599600
r.wait_for_state(PLM.State.RUNNING)
600601

602+
time.sleep(1) # ensure actual clone has started
603+
601604
for ns in testing.list_all_namespaces(t.source):
602605
t.source.admin.command({"renameCollection": ns, "to": ns + "_renamed"})
603606
for ns in testing.list_all_namespaces(t.source):

0 commit comments

Comments
 (0)