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

Solve database lock during long computations by breaking up the make callback into three parts #1171

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def schema_simp(connection_test, prefix):
schema(schema_simple.B)
schema(schema_simple.L)
schema(schema_simple.D)
schema(schema_simple.N)
schema(schema_simple.E)
schema(schema_simple.F)
schema(schema_simple.F)
Expand Down
28 changes: 27 additions & 1 deletion tests/schema_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,33 @@ def _make_tuples(self, key):
# make reference to a random tuple from L
random.seed(str(key))
lookup = list(L().fetch("KEY"))
self.insert(dict(key, id_d=i, **random.choice(lookup)) for i in range(4))
self.insert(dict(key, id_d=i, **random.choice(lookup))
for i in range(4))


class N(dj.Computed):
definition = """
# test for three part make function
-> A
id_d :int
---
-> L
"""

def make_fetch(self, key):
# make reference to a random tuple from L
lookup = list(L().fetch("KEY"))
inputs = key, lookup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't have to return the key since its provided by populate

return inputs

def make_compute(self, inputs):
key, lookup = inputs
random.seed(str(key))
values = [dict(key, id_d=i, **random.choice(lookup)) for i in range(4)]
return values

def make_insert(self, values):
self.insert(values)


class E(dj.Computed):
Expand Down
21 changes: 11 additions & 10 deletions tests/test_autopopulate.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import pytest
from datajoint import DataJointError
import datajoint as dj
import pymysql
from . import schema


def test_populate(trial, subject, experiment, ephys, channel):
def test_populate(schema_any, trial, subject, experiment, ephys, channel):
# test simple populate
assert subject, "root tables are empty"
assert not experiment, "table already filled?"
experiment.populate()
assert len(experiment) == len(subject) * experiment.fake_experiments_per_subject
assert len(experiment) == len(subject) * \
experiment.fake_experiments_per_subject

# test restricted populate
assert not trial, "table already filled?"
Expand All @@ -31,7 +30,7 @@ def test_populate(trial, subject, experiment, ephys, channel):
assert channel


def test_populate_with_success_count(subject, experiment, trial):
def test_populate_with_success_count(schema_any, subject, experiment, trial):
# test simple populate
assert subject, "root tables are empty"
assert not experiment, "table already filled?"
Expand Down Expand Up @@ -62,10 +61,11 @@ def test_populate_exclude_error_and_ignore_jobs(schema_any, subject, experiment)
schema_any.jobs.error(experiment.table_name, key, "")

experiment.populate(reserve_jobs=True)
assert len(experiment.key_source & experiment) == len(experiment.key_source) - 2
assert len(experiment.key_source & experiment) == len(
experiment.key_source) - 2


def test_allow_direct_insert(subject, experiment):
def test_allow_direct_insert(schema_any, subject, experiment):
assert subject, "root tables are empty"
key = subject.fetch("KEY", limit=1)[0]
key["experiment_id"] = 1000
Expand All @@ -74,14 +74,15 @@ def test_allow_direct_insert(subject, experiment):


@pytest.mark.parametrize("processes", [None, 2])
def test_multi_processing(subject, experiment, processes):
def test_multi_processing(schema_any, subject, experiment, processes):
assert subject, "root tables are empty"
assert not experiment, "table already filled?"
experiment.populate(processes=None)
assert len(experiment) == len(subject) * experiment.fake_experiments_per_subject
assert len(experiment) == len(subject) * \
experiment.fake_experiments_per_subject


def test_allow_insert(subject, experiment):
def test_allow_insert(schema_any, subject, experiment):
assert subject, "root tables are empty"
key = subject.fetch("KEY")[0]
key["experiment_id"] = 1001
Expand Down
Loading