Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change index creation time from being on connect to on create #51

Merged
merged 7 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions suitcase/mongo_normalized/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def __init__(
self._asset_registry_db = assets_db
self._ignore_duplicates = ignore_duplicates
self._resource_uid_unique = resource_uid_unique
self._create_indexes()

def _create_indexes(self):
def create_indexes(self):
"""
Create indexes on the various collections.

Expand Down
2 changes: 1 addition & 1 deletion suitcase/mongo_normalized/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from ophyd.tests.conftest import hw # noqa
from suitcase.utils.tests.conftest import ( # noqa
example_data, generate_data, plan_type, detector_list, event_type)
from .fixtures import db_factory # noqa
from .fixtures import db_factory, db_factory_no_indexes # noqa
22 changes: 21 additions & 1 deletion suitcase/mongo_normalized/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
import mongomock
import pytest
import uuid
from suitcase.mongo_normalized import Serializer


@pytest.fixture()
def db_factory_no_indexes(request):
def inner():
database_name = f'test-{str(uuid.uuid4())}'
uri = 'mongodb://localhost:27017/'
client = mongomock.MongoClient(uri)
db = client[database_name]

def drop():
client.drop_database(database_name)

request.addfinalizer(drop)
return db
return inner


@pytest.fixture()
Expand All @@ -12,10 +29,13 @@ def inner():
database_name = f'test-{str(uuid.uuid4())}'
uri = 'mongodb://localhost:27017/'
client = mongomock.MongoClient(uri)
db = client[database_name]
serializer = Serializer(db, db)
serializer.create_indexes()

def drop():
client.drop_database(database_name)

request.addfinalizer(drop)
return client[database_name]
return db
return inner
11 changes: 5 additions & 6 deletions suitcase/mongo_normalized/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_duplicates(db_factory, example_data):
metadatastore_db = db_factory()
asset_registry_db = db_factory()
serializer = Serializer(metadatastore_db, asset_registry_db)

for item in documents:
serializer(*item)
for item in documents:
Expand Down Expand Up @@ -204,12 +205,10 @@ def test_index_creation(db_factory):
assert indexes["descriptor_-1_time_1"]


def test_resource_uid_unique(db_factory):
db = db_factory()
print(type(db))
metadatastore_db = db_factory()
asset_registry_db = db_factory()
Serializer(metadatastore_db, asset_registry_db, resource_uid_unique=True)
def test_resource_uid_unique(db_factory_no_indexes):
metadatastore_db = db_factory_no_indexes()
asset_registry_db = db_factory_no_indexes()
Serializer(metadatastore_db, asset_registry_db, resource_uid_unique=True).create_indexes()

indexes = asset_registry_db.resource.index_information()
assert indexes["uid_1"].get("unique")
Loading