Commit 088fe0ce authored by Samuel GAIST's avatar Samuel GAIST

[backend][tests] Add a couple of tests using v2 database

parent 92982a99
......@@ -105,19 +105,22 @@ class BackendUtilitiesMixin(object):
environment=dict(name=env.name, version=env.version),
)
raw_access_db_name = "simple_rawdata_access/1"
source_prefix = os.path.join(settings.BASE_DIR, "src", "beat.examples")
db_root_file_path = os.path.join(settings.PREFIX, "db_root.json")
db_path = os.path.join(
settings.PREFIX, "data", raw_access_db_name.replace("/", "_")
)
db_root_data = {raw_access_db_name: db_path}
db_root_data = {}
os.makedirs(db_path, exist_ok=True)
for version in range(1, 3):
raw_access_db_name = f"simple_rawdata_access/{version}"
source_prefix = os.path.join(settings.BASE_DIR, "src", "beat.examples")
db_path = os.path.join(
settings.PREFIX, "data", raw_access_db_name.replace("/", "_")
)
db_root_data[raw_access_db_name] = db_path
with open(os.path.join(db_path, "datafile.txt"), "wt") as datafile:
datafile.write("1")
os.makedirs(db_path, exist_ok=True)
with open(os.path.join(db_path, "datafile.txt"), "wt") as datafile:
datafile.write("1")
db_root_file_path = os.path.join(settings.PREFIX, "db_root.json")
with open(db_root_file_path, "wt") as db_root_file:
db_root_file.write(json.dumps(db_root_data))
......
......@@ -121,25 +121,28 @@ class ScheduleExperimentTest(BaseBackendTestCase):
self.assertEqual(experiment.status, Experiment.DONE)
def test_success(self):
fullname = "user/user/single/1/single"
for name in ["single", "single_db_v2"]:
fullname = f"user/user/single/1/{name}"
with self.subTest(experiment_name=fullname):
xp = Experiment.objects.get(name=fullname.split("/")[-1])
xp = Experiment.objects.get(name=fullname.split("/")[-1])
b0 = xp.blocks.all()[0]
b1 = xp.blocks.all()[1]
b0 = xp.blocks.all()[0]
b1 = xp.blocks.all()[1]
self.check_pending_block_of_pending_experiment(b0)
self.check_pending_block_of_pending_experiment(b1)
self.check_pending_block_of_pending_experiment(b0)
self.check_pending_block_of_pending_experiment(b1)
self.assertEqual(Job.objects.count(), 0)
self.assertEqual(Job.objects.count(), 0)
schedule_experiment(xp)
schedule_experiment(xp)
self.check_pending_block_of_scheduled_experiment(b0)
self.check_pending_block_of_scheduled_experiment(b1, runnable=False)
self.check_pending_block_of_scheduled_experiment(b0)
self.check_pending_block_of_scheduled_experiment(b1, runnable=False)
self.assertEqual(Job.objects.count(), 2)
self.assertEqual(JobSplit.objects.count(), 0)
self.assertEqual(Job.objects.count(), 2)
Job.objects.all().delete()
self.assertEqual(JobSplit.objects.count(), 0)
def test_first_block_in_cache(self):
fullname = "user/user/single/1/single"
......@@ -623,25 +626,28 @@ class SplitNewJobsTest(BaseBackendTestCase):
self.assertTrue(split.end_date is None)
def test_one_experiment_one_slot(self):
fullname = "user/user/single/1/single"
for name in ["single", "single_db_v2"]:
fullname = f"user/user/single/1/{name}"
with self.subTest(experiment_name=fullname):
xp = Experiment.objects.get(name=fullname.split("/")[-1])
xp = Experiment.objects.get(name=fullname.split("/")[-1])
schedule_experiment(xp)
schedule_experiment(xp)
self.assertEqual(Job.objects.count(), 2)
self.assertEqual(JobSplit.objects.count(), 0)
self.assertEqual(Job.objects.count(), 2)
self.assertEqual(JobSplit.objects.count(), 0)
split_new_jobs()
split_new_jobs()
self.assertEqual(JobSplit.objects.count(), 1)
self.assertEqual(JobSplit.objects.count(), 1)
xp.refresh_from_db()
xp.refresh_from_db()
b0 = xp.blocks.all()[0]
split = b0.job.splits.all()[0]
b0 = xp.blocks.all()[0]
split = b0.job.splits.all()[0]
self.check_split(split, split_index=0)
self.check_split(split, split_index=0)
Job.objects.all().delete()
JobSplit.objects.all().delete()
def test_one_experiment_two_slots(self):
fullname = "user/user/single/1/single_split_2"
......@@ -776,9 +782,6 @@ class SplitNewJobsTest(BaseBackendTestCase):
split1 = b0.job.splits.all()[0]
split2 = b0.job.splits.all()[1]
print(split2.start_index)
print(split2.end_index)
self.check_split(split1, split_index=0, start_index=0, end_index=5)
self.check_split(split2, split_index=1, start_index=6, end_index=8)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment