Skip to content

Commit c250e36

Browse files
committed
Run tests in CI in two batches: first, tests that don't require {pg,mongo,mysql}origin databases to be up (whilst they're starting up), then the remainder of the tests.
1 parent bebec8b commit c250e36

10 files changed

+54
-8
lines changed

.travis.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ python:
66
install:
77
- poetry install -E ingestion --develop splitgraph
88
script:
9-
- poetry run pytest -v
9+
# The majority of the test suite doesn't depend on {pg,mongo,mysql}origin being up and they
10+
# take a lot of time to start up (especially the first time). So, whilst the 3 DBs are busy starting up,
11+
# we run the core tests against the local/remote engines and then run the rest of the tests (about 10% of them)
12+
# with the databases up, merging coverage.
13+
- poetry run pytest -v -m "not mounting"
14+
- ./wait-for-test-architecture.sh --mounting
15+
- poetry run pytest -v -m "mounting" --cov-append
1016

1117
services:
1218
- docker

test/architecture/wait-for-architecture.sh

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ TEST_DIR="${THIS_DIR}/.."
55
REPO_ROOT_DIR="${TEST_DIR}/.."
66
DEFAULT_SG_CONFIG_FILE="${TEST_DIR}/resources/.sgconfig"
77

8+
if [[ "$1" == "--mounting" ]]; then
9+
echo "Wait for mounting architecture to be up"
10+
HEALTHCHECK="import test.splitgraph.conftest as c; c.healthcheck_mounting()"
11+
else
12+
echo "Wait for core architecture to be up"
13+
HEALTHCHECK="import test.splitgraph.conftest as c; c.healthcheck()"
14+
fi
15+
816
export SG_CONFIG_FILE=${SG_CONFIG_FILE-"${DEFAULT_SG_CONFIG_FILE}"}
917

10-
echo "Wait for architecture to be up"
1118
echo "Using config file at $SG_CONFIG_FILE ..."
1219

1320
_init_engines() {
@@ -20,7 +27,7 @@ _init_engines() {
2027

2128
_run_health_check() {
2229
pushd "$REPO_ROOT_DIR" \
23-
&& python -c "import test.splitgraph.conftest as c; c.healthcheck()" \
30+
&& python -c "$HEALTHCHECK" \
2431
&& return 0
2532

2633
return 1

test/splitgraph/commands/test_commit_diff.py

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def test_commit_on_empty(snap_only, pg_repo_local):
315315
assert OUTPUT.diff('test', image_1=OUTPUT.head.image_hash, image_2=None) == []
316316

317317

318+
@pytest.mark.mounting
318319
@pytest.mark.parametrize("mode", _COMMIT_MODES)
319320
def test_multiple_mountpoint_commit_diff(mode, pg_repo_local, mg_repo_local):
320321
pg_repo_local.run_sql("""INSERT INTO fruits VALUES (3, 'mayonnaise');

test/splitgraph/commands/test_mounting.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from datetime import datetime as dt
22

3+
import pytest
4+
35
from splitgraph import get_engine
46
from splitgraph.core.repository import Repository
57
from test.splitgraph.conftest import _mount_postgres, _mount_mysql, _mount_mongo
@@ -9,19 +11,22 @@
911
MYSQL_MNT = Repository.from_schema("test/mysql_mount")
1012

1113

14+
@pytest.mark.mounting
1215
def test_mount_unmount(local_engine_empty):
1316
_mount_postgres(PG_MNT)
1417
assert (1, 'apple') in get_engine().run_sql("""SELECT * FROM "test/pg_mount".fruits""")
1518
PG_MNT.delete()
1619
assert not get_engine().schema_exists(PG_MNT.to_schema())
1720

1821

22+
@pytest.mark.mounting
1923
def test_mount_partial(local_engine_empty):
2024
_mount_postgres(PG_MNT, tables=['fruits'])
2125
assert get_engine().table_exists(PG_MNT.to_schema(), 'fruits')
2226
assert not get_engine().table_exists(PG_MNT.to_schema(), 'vegetables')
2327

2428

29+
@pytest.mark.mounting
2530
def test_mount_mysql(local_engine_empty):
2631
try:
2732
_mount_mysql(MYSQL_MNT)
@@ -34,6 +39,7 @@ def test_mount_mysql(local_engine_empty):
3439
MYSQL_MNT.delete()
3540

3641

42+
@pytest.mark.mounting
3743
def test_cross_joins(local_engine_empty):
3844
_mount_postgres(PG_MNT)
3945
_mount_mongo(MG_MNT)

test/splitgraph/commands/test_provenance.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from splitgraph.splitfile import execute_commands
24
from splitgraph.splitfile.execution import rebuild_image
35
from test.splitgraph.conftest import OUTPUT, load_splitfile
@@ -40,6 +42,7 @@ def test_splitfile_recreate_custom_from(local_engine_empty, pg_repo_remote_multi
4042
"JOIN vegetables ON fruit_id = vegetable_id"]
4143

4244

45+
@pytest.mark.mounting
4346
def test_splitfile_incomplete_provenance(local_engine_empty, pg_repo_remote_multitag):
4447
# This splitfile has a MOUNT as its first command. We're expecting image_hash_to_splitfile to base the result
4548
# on the image created by MOUNT and not regenerate the MOUNT command.

test/splitgraph/conftest.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ def _mount_mysql(repository):
5757

5858

5959
def healthcheck():
60-
# A pre-flight check before we run the tests to make sure the test architecture has been brought up:
61-
# the local_engine and the two origins (tested by mounting). There's still an implicit race condition
62-
# here since we don't touch the remote_engine but we don't run any tests against it until later on,
63-
# so it should have enough time to start up.
60+
# A pre-flight check for most tests: check that the local and the remote engine fixtures are up and
61+
# running.
62+
get_current_repositories(get_engine())
63+
get_current_repositories(get_engine('remote_engine'))
64+
65+
66+
def healthcheck_mounting():
67+
# A pre-flight check for heavier tests that also ensures the three origin databases that we mount for FDW tests
68+
# are up. Tests that require one of these databases to be up are marked with @pytest.mark.mounting and can be
69+
# excluded with `poetry run pytest -m "not mounting"`.
6470
for mountpoint in [PG_MNT, MG_MNT, MYSQL_MNT]:
6571
mountpoint.delete()
6672
_mount_postgres(PG_MNT)

test/splitgraph/splitfile/test_execution.py

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_splitfile_preprocessor_escaping():
2828
assert 'tag-v1-whatever' in commands
2929

3030

31+
@pytest.mark.mounting
3132
def test_basic_splitfile(pg_repo_local, mg_repo_local):
3233
execute_commands(load_splitfile('create_table.splitfile'), output=OUTPUT)
3334
log = list(reversed(OUTPUT.head.get_log()))
@@ -42,6 +43,7 @@ def test_basic_splitfile(pg_repo_local, mg_repo_local):
4243
assert OUTPUT.run_sql("SELECT * FROM my_fruits") == [(1, 'pineapple'), (2, 'banana')]
4344

4445

46+
@pytest.mark.mounting
4547
def test_update_without_import_splitfile(pg_repo_local, mg_repo_local):
4648
# Test that correct commits are produced by executing an splitfile (both against newly created and already
4749
# existing tables on an existing mountpoint)
@@ -55,6 +57,7 @@ def test_update_without_import_splitfile(pg_repo_local, mg_repo_local):
5557
assert OUTPUT.run_sql("SELECT * FROM my_fruits") == [(1, 'pineapple')]
5658

5759

60+
@pytest.mark.mounting
5861
def test_local_import_splitfile(pg_repo_local, mg_repo_local):
5962
execute_commands(load_splitfile('import_local.splitfile'), output=OUTPUT)
6063
head = OUTPUT.head
@@ -69,6 +72,7 @@ def test_local_import_splitfile(pg_repo_local, mg_repo_local):
6972
assert not OUTPUT.engine.table_exists(OUTPUT.to_schema(), 'fruits')
7073

7174

75+
@pytest.mark.mounting
7276
def test_advanced_splitfile(pg_repo_local, mg_repo_local):
7377
execute_commands(load_splitfile('import_local_multiple_with_queries.splitfile'), output=OUTPUT)
7478

@@ -86,6 +90,7 @@ def test_advanced_splitfile(pg_repo_local, mg_repo_local):
8690
assert OUTPUT.run_sql("SELECT * FROM my_fruits") == [(2, 'orange')]
8791

8892

93+
@pytest.mark.mounting
8994
def test_splitfile_cached(pg_repo_local, mg_repo_local):
9095
# Check that no new commits/snaps are created if we rerun the same splitfile
9196
execute_commands(load_splitfile('import_local_multiple_with_queries.splitfile'), output=OUTPUT)
@@ -144,6 +149,7 @@ def test_import_updating_splitfile_with_uploading(local_engine_empty, remote_eng
144149
assert OUTPUT.run_sql("SELECT fruit_id, name FROM my_fruits") == [(1, 'apple'), (2, 'orange'), (3, 'mayonnaise')]
145150

146151

152+
@pytest.mark.mounting
147153
def test_splitfile_end_to_end_with_uploading(local_engine_empty, remote_engine,
148154
pg_repo_remote_multitag, mg_repo_remote):
149155
# An end-to-end test:
@@ -171,6 +177,7 @@ def test_splitfile_end_to_end_with_uploading(local_engine_empty, remote_engine,
171177
assert stage_2.run_sql("SELECT id, name, fruit, vegetable FROM diet") == [(2, 'James', 'orange', 'carrot')]
172178

173179

180+
@pytest.mark.mounting
174181
def test_splitfile_schema_changes(pg_repo_local, mg_repo_local):
175182
execute_commands(load_splitfile('schema_changes.splitfile'), output=OUTPUT)
176183
old_output_head = OUTPUT.head
@@ -189,6 +196,7 @@ def test_splitfile_schema_changes(pg_repo_local, mg_repo_local):
189196
assert OUTPUT.run_sql("SELECT * FROM spirit_fruits") == [('James', 'orange', 12), ('Alex', 'mayonnaise', 22)]
190197

191198

199+
@pytest.mark.mounting
192200
def test_import_with_custom_query(pg_repo_local, mg_repo_local):
193201
# Mostly a lazy way for the test to distinguish between the importer storing the results of a query as a snap
194202
# and pointing the commit history to the diff for unchanged objects.
@@ -224,6 +232,7 @@ def test_import_with_custom_query(pg_repo_local, mg_repo_local):
224232
assert OUTPUT.objects.get_object_meta(objects)[objects[0]].parent_id is not None
225233

226234

235+
@pytest.mark.mounting
227236
def test_import_mount(local_engine_empty):
228237
execute_commands(load_splitfile('import_from_mounted_db.splitfile'), output=OUTPUT)
229238

@@ -246,6 +255,7 @@ def test_import_mount(local_engine_empty):
246255
assert OUTPUT.objects.get_object_meta(objects)[objects[0]].parent_id is None
247256

248257

258+
@pytest.mark.mounting
249259
def test_import_all(local_engine_empty):
250260
execute_commands(load_splitfile('import_all_from_mounted.splitfile'), output=OUTPUT)
251261

@@ -331,6 +341,7 @@ def test_from_local(pg_repo_local):
331341
assert OUTPUT.run_sql("SELECT * FROM join_table") == [(1, 'apple', 'potato'), (2, 'orange', 'carrot')]
332342

333343

344+
@pytest.mark.mounting
334345
def test_splitfile_with_external_sql(pg_repo_local, pg_repo_remote, mg_repo_local):
335346
# Tests are running from root so we pass in the path to the SQL manually to the splitfile.
336347
execute_commands(load_splitfile('external_sql.splitfile'),

test/splitgraph/test_commandline.py

+3
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def test_commandline_tag_checkout(pg_repo_local):
353353
assert pg_repo_local.images.by_tag('v1', raise_on_none=False) is None
354354

355355

356+
@pytest.mark.mounting
356357
def test_misc_mountpoint_management(pg_repo_local, mg_repo_local):
357358
runner = CliRunner()
358359

@@ -388,6 +389,7 @@ def test_misc_mountpoint_management(pg_repo_local, mg_repo_local):
388389
assert mg_repo_local.run_sql("SELECT duration from stuff WHERE name = 'James'") == [(Decimal(2),)]
389390

390391

392+
@pytest.mark.mounting
391393
def test_import(pg_repo_local, mg_repo_local):
392394
runner = CliRunner()
393395
head = pg_repo_local.head
@@ -508,6 +510,7 @@ def test_splitfile_rebuild_update(local_engine_empty, pg_repo_remote_multitag):
508510
assert OUTPUT.images() == curr_commits
509511

510512

513+
@pytest.mark.mounting
511514
def test_mount_and_import(local_engine_empty):
512515
runner = CliRunner()
513516
try:

test/splitgraph/test_object_hashing.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from functools import reduce
33
from hashlib import sha256
44

5+
import pytest
6+
57
from splitgraph import SPLITGRAPH_META_SCHEMA, execute_commands, Repository
68
from splitgraph.core.fragment_manager import Digest
79
from test.splitgraph.conftest import OUTPUT, PG_DATA, load_splitfile
@@ -277,6 +279,7 @@ def test_diff_fragment_hashing_reused_twice(pg_repo_local):
277279
[(1, 'apple'), (2, 'mustard'), (3, 'kumquat')]
278280

279281

282+
@pytest.mark.mounting
280283
def test_import_splitfile_reuses_hash(local_engine_empty):
281284
# Create two repositories and run the same Splitfile that loads some data from a mounted database.
282285
# Check that the same contents result in the same hash and no extra objects being created

wait-for-test-architecture.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
REPO_ROOT_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
44
TEST_DIR="${REPO_ROOT_DIR}/test"
55

6-
exec "$TEST_DIR"/architecture/wait-for-architecture.sh
6+
exec "$TEST_DIR"/architecture/wait-for-architecture.sh $1

0 commit comments

Comments
 (0)