Skip to content

Commit c5362e2

Browse files
wskozlowskiWojtek
andauthored
Feature/1270 (#761)
* embedded tuples * embedded collection files * embedding objects + test parallelism * embedding dicts * deep unreferencing tests * defensive thread shutdown * refresh fix (edge case for initial prefix) --------- Co-authored-by: Wojtek <wskozlowski@dbzero.io>
1 parent dd68f1d commit c5362e2

46 files changed

Lines changed: 2701 additions & 182 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ All tests must pass before a change is considered complete.
2323
### Running tests
2424

2525
- Python tests: `./scripts/run_tests.sh`
26+
- Final Python test checks: `./scripts/run_tests.sh -j 6`
2627
- C++ tests after a `-t` build: `./build/release/tests.x`
2728
- During development, do not run stress tests by default; they are intentionally slow. Run focused tests specific to the feature or refactor being worked on before finalization.
2829
- If any C++ source under the native/core part of the project was modified, also run the C++ test suite (do not rely on the Python tests alone to cover native changes).

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ This project adheres to a code of conduct that all contributors are expected to
9494
# Run Python tests (excludes stress tests)
9595
./scripts/run_tests.sh
9696

97+
# Run Python tests in parallel
98+
./scripts/run_tests.sh -j 6
99+
97100
# Run specific Python test
98101
./scripts/run_tests.sh -k=test_name
99102

‎dbzero/dbzero/dbzero.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def load_dynamic(name, path):
1010

1111
def __bootstrap__():
1212
global __bootstrap__, __loader__, __file__
13-
paths = [os.path.join(os.path.split(__file__)[0]), "/src/dev/build/debug", "/usr/local/lib/python3/dist-packages/dbzero/"]
13+
paths = [os.path.join(os.path.split(__file__)[0]), "/src/dev/build/release", "/usr/local/lib/python3/dist-packages/dbzero/"]
1414
__file__ = None
1515
for path in paths:
1616
if os.path.isdir(path):

‎python_tests/conftest.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@
1313

1414

1515
TEST_FILES_DIR_ROOT = os.path.join(os.getcwd(), "python_tests", "files")
16-
DB0_DIR = os.path.join(os.getcwd(), "db0-test-data")
16+
PYTEST_WORKER_ID = os.environ.get("PYTEST_XDIST_WORKER")
17+
WORKER_SUFFIX = f"-{PYTEST_WORKER_ID}" if PYTEST_WORKER_ID else ""
18+
DB0_DIR = os.path.join(os.getcwd(), f"db0-test-data{WORKER_SUFFIX}")
19+
20+
21+
def worker_path(path):
22+
if not WORKER_SUFFIX:
23+
return path
24+
directory, filename = os.path.split(path)
25+
name, extension = os.path.splitext(filename)
26+
return os.path.join(directory, f"{name}{WORKER_SUFFIX}{extension}")
1727

1828

1929
def __extract_param(request, key, default):
@@ -211,4 +221,4 @@ def db0_large_lang_cache_no_autocommit():
211221
yield db0
212222
db0.close()
213223
if os.path.exists(DB0_DIR):
214-
shutil.rmtree(DB0_DIR)
224+
shutil.rmtree(DB0_DIR)

‎python_tests/test_copy_prefix.py‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import os
77
import time
88
from .memo_test_types import MemoTestClass, MemoTestSingleton
9-
from .conftest import DB0_DIR
9+
from .conftest import DB0_DIR, worker_path
1010
import multiprocessing
1111

1212

1313
def test_copy_current_prefix(db0_fixture):
14-
file_name = "./test-copy.db0"
14+
file_name = worker_path("./test-copy.db0")
1515
# remove file if it exists
1616
if os.path.exists(file_name):
1717
os.remove(file_name)
@@ -30,7 +30,7 @@ def test_copy_current_prefix(db0_fixture):
3030

3131

3232
def test_recover_prefix_from_copy(db0_fixture):
33-
file_name = "./test-copy.db0"
33+
file_name = worker_path("./test-copy.db0")
3434
# remove file if it exists
3535
if os.path.exists(file_name):
3636
os.remove(file_name)
@@ -58,7 +58,7 @@ def test_recover_prefix_from_copy(db0_fixture):
5858

5959

6060
def test_copy_prefix_custom_step_size(db0_fixture):
61-
file_name = "./test-copy.db0"
61+
file_name = worker_path("./test-copy.db0")
6262
if os.path.exists(file_name):
6363
os.remove(file_name)
6464

@@ -110,7 +110,7 @@ def writer_process(prefix, obj_count = 50, commit_count = 50, long_run = False):
110110

111111

112112
def test_copy_prefix_being_actively_modified(db0_fixture):
113-
file_name = "./test-copy.db0"
113+
file_name = worker_path("./test-copy.db0")
114114
if os.path.exists(file_name):
115115
os.remove(file_name)
116116

@@ -153,7 +153,7 @@ def test_copy_prefix_being_actively_modified(db0_fixture):
153153

154154

155155
def test_copy_prefix_fails_if_no_active_prefix(db0_fixture):
156-
file_name = "./test-copy.db0"
156+
file_name = worker_path("./test-copy.db0")
157157
# remove file if it exists
158158
if os.path.exists(file_name):
159159
os.remove(file_name)
@@ -172,7 +172,7 @@ def test_copy_prefix_fails_if_no_active_prefix(db0_fixture):
172172

173173

174174
def test_copy_prefix_without_opening_it(db0_fixture):
175-
file_name = "./test-copy.db0"
175+
file_name = worker_path("./test-copy.db0")
176176
# remove file if it exists
177177
if os.path.exists(file_name):
178178
os.remove(file_name)
@@ -207,7 +207,7 @@ def validate_current_prefix(expected_len = None, expected_min_len = None):
207207
return len(root.value)
208208

209209
def validate_copy(copy_id, expected_len = None, expected_min_len = None):
210-
file_name = f"./test-copy-{copy_id}.db0"
210+
file_name = worker_path(f"./test-copy-{copy_id}.db0")
211211
os.remove(px_path)
212212
# restore the copy
213213
os.rename(file_name, px_path)
@@ -250,7 +250,7 @@ def validate_copy(copy_id, expected_len = None, expected_min_len = None):
250250
while True:
251251
if not p.is_alive():
252252
break
253-
file_name = f"./test-copy-{copy_id}.db0"
253+
file_name = worker_path(f"./test-copy-{copy_id}.db0")
254254
if os.path.exists(file_name):
255255
os.remove(file_name)
256256
# copy prefix without opening it, use default step size
@@ -266,7 +266,7 @@ def validate_copy(copy_id, expected_len = None, expected_min_len = None):
266266
total_len += obj_count * commit_count
267267

268268
# make final stale copy (i.e. without active modifications)
269-
final_copy = f"./test-copy-final.db0"
269+
final_copy = worker_path("./test-copy-final.db0")
270270
if os.path.exists(final_copy):
271271
os.remove(final_copy)
272272
db0.copy_prefix(final_copy, prefix=px_name)
@@ -284,7 +284,7 @@ def validate_copy(copy_id, expected_len = None, expected_min_len = None):
284284

285285

286286
def test_modify_copied_prefix(db0_fixture):
287-
file_name = "./test-copy.db0"
287+
file_name = worker_path("./test-copy.db0")
288288
# remove file if it exists
289289
if os.path.exists(file_name):
290290
os.remove(file_name)
@@ -326,7 +326,7 @@ def modify_prefix():
326326

327327
@pytest.mark.parametrize("db0_fixture", [{"autocommit": False}], indirect=True)
328328
def test_copy_prefix_of_recovered_copy(db0_fixture):
329-
file_name = "./test-copy.db0"
329+
file_name = worker_path("./test-copy.db0")
330330
# remove file if it exists
331331
if os.path.exists(file_name):
332332
os.remove(file_name)
@@ -398,7 +398,7 @@ def validate_current_prefix(expected_len = None, expected_min_len = None):
398398
return len(root.value)
399399

400400
def validate_copy(copy_id, expected_len = None, expected_min_len = None):
401-
file_name = f"./test-copy-{copy_id}.db0"
401+
file_name = worker_path(f"./test-copy-{copy_id}.db0")
402402
os.remove(px_path)
403403
# restore the copy
404404
os.rename(file_name, px_path)
@@ -437,7 +437,7 @@ def validate_copy(copy_id, expected_len = None, expected_min_len = None):
437437
while True:
438438
if not p.is_alive():
439439
break
440-
file_name = f"./test-copy-{copy_id}.db0"
440+
file_name = worker_path(f"./test-copy-{copy_id}.db0")
441441
if os.path.exists(file_name):
442442
os.remove(file_name)
443443
db0.copy_prefix(file_name, prefix=px_name)
@@ -468,7 +468,7 @@ def validate_current_prefix(expected_len = None, expected_min_len = None):
468468
return len(root.value)
469469

470470
def validate_copy(copy_id, expected_len = None, expected_min_len = None):
471-
file_name = f"./test-copy-{copy_id}.db0"
471+
file_name = worker_path(f"./test-copy-{copy_id}.db0")
472472
os.remove(px_path)
473473
# restore the copy
474474
os.rename(file_name, px_path)
@@ -513,7 +513,7 @@ def validate_copy(copy_id, expected_len = None, expected_min_len = None):
513513
while True:
514514
if not p.is_alive():
515515
break
516-
file_name = f"./test-copy-{copy_id}.db0"
516+
file_name = worker_path(f"./test-copy-{copy_id}.db0")
517517
if os.path.exists(file_name):
518518
os.remove(file_name)
519519
# copy prefix without opening it, use default step size
@@ -529,7 +529,7 @@ def validate_copy(copy_id, expected_len = None, expected_min_len = None):
529529
total_len += obj_count * commit_count
530530

531531
# make final stale copy (i.e. without active modifications)
532-
final_copy = f"./test-copy-final.db0"
532+
final_copy = worker_path("./test-copy-final.db0")
533533
if os.path.exists(final_copy):
534534
os.remove(final_copy)
535535
db0.copy_prefix(final_copy, prefix=px_name)
@@ -543,4 +543,4 @@ def validate_copy(copy_id, expected_len = None, expected_min_len = None):
543543
# this is the restored version
544544
total_len = last_len
545545

546-
546+

‎python_tests/test_issues_14.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import dbzero as db0
55
import pytest
6-
from .conftest import DB0_DIR
6+
from .conftest import DB0_DIR, worker_path
77
from .memo_test_types import MemoTestSingleton, MemoTestClass
88
import multiprocessing
99
import os
@@ -43,7 +43,7 @@ def validate_current_prefix(expected_len = None, expected_min_len = None):
4343
return len(root.value)
4444

4545
def validate_copy(copy_id, expected_len = None, expected_min_len = None):
46-
file_name = f"./test-copy-{copy_id}.db0"
46+
file_name = worker_path(f"./test-copy-{copy_id}.db0")
4747
os.remove(px_path)
4848
# restore the copy
4949
os.rename(file_name, px_path)
@@ -69,7 +69,7 @@ def validate_copy(copy_id, expected_len = None, expected_min_len = None):
6969
db0.open(px_name, "r")
7070

7171
# make final stale copy (i.e. without active modifications)
72-
final_copy = f"./test-copy-final.db0"
72+
final_copy = worker_path("./test-copy-final.db0")
7373
if os.path.exists(final_copy):
7474
os.remove(final_copy)
7575
db0.copy_prefix(final_copy, prefix=px_name)

0 commit comments

Comments
 (0)