Skip to content

Commit fcc159c

Browse files
author
Shubham
committed
Enable Sync testing in GitLab CI
Add a tag that disables/skips Sync tests when the build is not a 'Sync' variant.
1 parent 98ba442 commit fcc159c

3 files changed

Lines changed: 91 additions & 3 deletions

File tree

.gitlab-ci.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ build:
2727
paths:
2828
- dist/*.whl
2929

30+
# Build the Sync version of the package
31+
build-sync:
32+
tags: [ x64, docker, linux ]
33+
image: python:latest
34+
stage: build
35+
script:
36+
- python -m pip install --upgrade pip
37+
# Using released C library (Sync version)
38+
- make depend-sync
39+
- make test
40+
- make build-sync
41+
artifacts:
42+
expire_in: 1 days
43+
paths:
44+
- dist/*.whl
45+
3046
# Next, test the packaged wheel built by "build"
3147
.test:
3248
stage: test
@@ -72,3 +88,49 @@ test:windows:x64:
7288
tags: [windows, x64, python]
7389
variables:
7490
PYTHON: "python.exe"
91+
92+
# Sync version test jobs
93+
.test-sync:
94+
stage: test
95+
needs: [ build-sync ]
96+
script:
97+
- pip3 install --user pytest
98+
- rm -r objectbox # todo this is ugly; let's copy required files in a sub-folder instead?
99+
- pip3 install --user --force-reinstall dist/*.whl # Artifacts from build-sync
100+
- ${PYTHON} -m pytest --runsync
101+
variables:
102+
PYTHON: "python3"
103+
104+
test-sync:linux:x64:
105+
extends: .test-sync
106+
tags: [ x64, docker, linux ]
107+
image: python:$PYTHON_VERSION
108+
parallel:
109+
matrix:
110+
- PYTHON_VERSION: [ '3.7', '3.8', '3.9', '3.10', '3.11', '3.12' ]
111+
112+
test-sync:linux:armv7hf:
113+
extends: .test-sync
114+
tags: [ armv7hf, shell, linux, python3 ]
115+
116+
test-sync:linux:aarch64:
117+
extends: .test-sync
118+
tags: [ aarch64, shell, linux, python3 ]
119+
120+
test-sync:mac:x64:
121+
extends: .test-sync
122+
script:
123+
- python3 -m venv .venv
124+
- source .venv/bin/activate
125+
- python3 -m pip install pytest
126+
- rm -r objectbox # todo this is ugly; let's copy required files in a sub-folder instead?
127+
- pip3 install --force-reinstall dist/*.whl # Artifacts from build-sync
128+
- python -m pytest --runsync
129+
tags: [ mac, x64, shell, python3 ]
130+
131+
test-sync:windows:x64:
132+
extends: .test-sync
133+
tags: [ windows, x64, python ]
134+
variables:
135+
PYTHON: "python.exe"
136+

tests/conftest.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import pytest
2-
from objectbox.logger import logger
3-
from objectbox.sync import SyncLoginListener, SyncConnectionListener, SyncErrorListener, SyncClient, SyncCredentials
41
from common import *
2+
from objectbox.sync import SyncLoginListener, SyncConnectionListener, SyncErrorListener, SyncClient, SyncCredentials
53

64

75
# Fixtures in this file are used by all files in the same directory:
@@ -95,3 +93,22 @@ def sync_server():
9593
yield server_config
9694
if server_config:
9795
stop_sync_server(server_config.container_id)
96+
97+
98+
def pytest_addoption(parser):
99+
parser.addoption(
100+
"--runsync", action="store_false", default=False, help="run Sync tests"
101+
)
102+
103+
104+
def pytest_configure(config):
105+
config.addinivalue_line("markers", "sync: run Sync tests")
106+
107+
108+
def pytest_collection_modifyitems(config, items):
109+
if config.getoption("--runsync"):
110+
return
111+
skip_sync = pytest.mark.skip(reason="need --runsync option to run")
112+
for item in items:
113+
if "sync" in item.keywords:
114+
item.add_marker(skip_sync)

tests/test_sync.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
from objectbox.sync import *
77

88

9+
@pytest.mark.sync
910
def test_sync_protocol_version():
1011
version = SyncClient.protocol_version()
1112
assert version >= 1
1213

1314

15+
@pytest.mark.sync
1416
def test_sync_client_states(sync_client):
1517
assert sync_client.get_sync_state() == SyncState.CREATED
1618
sync_client.start()
@@ -20,6 +22,7 @@ def test_sync_client_states(sync_client):
2022
sync_client.close()
2123

2224

25+
@pytest.mark.sync
2326
def test_sync_listener(sync_server, sync_client, login_listener, connection_listener):
2427
if not sync_server:
2528
pytest.skip("Sync server not available")
@@ -34,6 +37,7 @@ def test_sync_listener(sync_server, sync_client, login_listener, connection_list
3437
assert connection_listener.connected_called
3538

3639

40+
@pytest.mark.sync
3741
def test_filter_variables(test_store):
3842
server_urls = ["ws://localhost:9999"]
3943

@@ -54,6 +58,7 @@ def test_filter_variables(test_store):
5458
client.close()
5559

5660

61+
@pytest.mark.sync
5762
def test_outgoing_message_count(sync_client):
5863
count = sync_client.get_outgoing_message_count()
5964
assert count == 0
@@ -67,6 +72,7 @@ def test_outgoing_message_count(sync_client):
6772
sync_client.get_outgoing_message_count()
6873

6974

75+
@pytest.mark.sync
7076
def test_multiple_credentials(sync_client):
7177
# empty list should raise ValueError
7278
with pytest.raises(ValueError, match='Provide at least one credential'):
@@ -87,17 +93,20 @@ def test_multiple_credentials(sync_client):
8793
])
8894

8995

96+
@pytest.mark.sync
9097
def test_client_closed_when_store_closed(test_store, sync_client):
9198
assert not sync_client.is_closed()
9299
test_store.close()
93100
assert sync_client.is_closed()
94101

95102

103+
@pytest.mark.sync
96104
def assert_raises_value_error(fn: Callable[[], object | None], message: str | None = None):
97105
with pytest.raises(ValueError, match=message):
98106
fn()
99107

100108

109+
@pytest.mark.sync
101110
def test_client_access_after_close_throws_error(sync_client):
102111
sync_client.close()
103112

0 commit comments

Comments
 (0)