def setUp(self): self.zombie_db_client = mock_client_factory.create() self.mock_db_client = self.zombie_db_client.mock # Add controllers that generate image collections self.controllers = [ self.mock_db_client.image_source_collection.insert_one( traj_follow_controller.TrajectoryFollowController( trajectory={}, trajectory_source=None, sequence_type=core.sequence_type.ImageSequenceType. NON_SEQUENTIAL).serialize()).inserted_id for _ in range(2) ] # Create image sources and generate dataset tasks for the controller self.generate_dataset_tasks = {} self.image_collections = {} for controller_id in self.controllers: # Add generate dataset tasks for all the image collections. self.image_collections[controller_id] = make_image_collection( self.mock_db_client).identifier self.generate_dataset_tasks[ controller_id] = self.mock_db_client.tasks_collection.insert_one( generate_dataset_task.GenerateDatasetTask( simulator_id=bson.ObjectId(), controller_id=controller_id, simulator_config={}, result=self.image_collections[controller_id], state=batch_analysis.task.JobState.DONE).serialize() ).inserted_id
def setUp(self): self.zombie_db_client = mock_client_factory.create() self.mock_db_client = self.zombie_db_client.mock # Create the basic image sources, systems, and benchmarks. self.image_collections = [ make_image_collection(self.mock_db_client).identifier for _ in range(2) ] self.systems = [ self.mock_db_client.system_collection.insert_one( mock_core.MockSystem().serialize()).inserted_id for _ in range(2) ] self.benchmarks = [ self.mock_db_client.benchmarks_collection.insert_one( mock_core.MockBenchmark().serialize()).inserted_id for _ in range(2) ] # Create run system tasks and trial results self.run_system_tasks = {} self.trial_results = [] for image_collection_id in self.image_collections: for system_id in self.systems: trial_result_id = self.mock_db_client.trials_collection.insert_one( core.trial_result.TrialResult( system_id, True, core.sequence_type.ImageSequenceType.NON_SEQUENTIAL, {}).serialize()).inserted_id self.trial_results.append(trial_result_id) self.run_system_tasks[ trial_result_id] = self.mock_db_client.tasks_collection.insert_one( run_system_task.RunSystemTask( system_id, image_collection_id, result=trial_result_id, state=batch_analysis.task.JobState.DONE).serialize( )).inserted_id self.benchmark_trial_tasks = {} self.benchmark_results = {} for trial_result_id in self.trial_results: self.benchmark_trial_tasks[trial_result_id] = [] self.benchmark_results[trial_result_id] = [] for benchmark_id in self.benchmarks: result_id = self.mock_db_client.results_collection.insert_one( core.benchmark.BenchmarkResult( benchmark_id, trial_result_id, True).serialize()).inserted_id self.benchmark_results[trial_result_id].append(result_id) self.benchmark_trial_tasks[trial_result_id].append( self.mock_db_client.tasks_collection.insert_one( benchmark_trial_task.BenchmarkTrialTask( trial_result_id, benchmark_id, result=result_id, state=batch_analysis.task.JobState.DONE).serialize( )).inserted_id)
def create_mock_db_client(self): """ Create the mock database client fed to deserialize. The default behaviour here is sufficient if the client is not used, override it to create specific return values :return: """ self.zombie_db_client = mock_db_client_fac.create() return self.zombie_db_client.mock
def test_schedule_all_schedules_all_benchmark_combinations(self): zombie_db_client = mock_client_factory.create() zombie_task_manager = mock_manager_factory.create() subject = MockExperiment() systems = [] image_sources = [] trial_results = [] benchmarks = [] for _ in range(3): # Create entity = mock_core.MockSystem() systems.append( zombie_db_client.mock.system_collection.insert_one( entity.serialize()).inserted_id) entity = mock_core.MockImageSource() image_sources.append( zombie_db_client.mock.image_source_collection.insert_one( entity.serialize()).inserted_id) entity = mock_core.MockBenchmark() benchmarks.append( zombie_db_client.mock.benchmarks_collection.insert_one( entity.serialize()).inserted_id) for system_id in systems: for image_source_id in image_sources: # Create trial results for each combination of systems and image sources, # as if the run system tasks are complete entity = core.trial_result.TrialResult( system_id, True, core.sequence_type.ImageSequenceType.NON_SEQUENTIAL, {}) trial_result_id = zombie_db_client.mock.trials_collection.insert_one( entity.serialize()).inserted_id trial_results.append(trial_result_id) task = zombie_task_manager.get_run_system_task( system_id, image_source_id) task.mark_job_started('test', 0) task.mark_job_complete(trial_result_id) subject.schedule_all(zombie_task_manager.mock, zombie_db_client.mock, systems, image_sources, benchmarks) # Check if we scheduled all the benchmarks for trial_result_id in trial_results: for benchmark_id in benchmarks: self.assertIn( mock.call(trial_result_id=trial_result_id, benchmark_id=benchmark_id, memory_requirements=mock.ANY, expected_duration=mock.ANY), zombie_task_manager.mock.get_benchmark_task.call_args_list)
def setUp(self): self.zombie_db_client = mock_client_factory.create() self.mock_db_client = self.zombie_db_client.mock # Create benchmark results and tasks self.benchmark_trial_tasks = {} self.benchmark_results = [] for _ in range(2): result_id = self.mock_db_client.results_collection.insert_one( core.benchmark.BenchmarkResult(bson.ObjectId(), bson.ObjectId(), True).serialize()).inserted_id self.benchmark_results.append(result_id) self.benchmark_trial_tasks[ result_id] = self.mock_db_client.tasks_collection.insert_one( benchmark_trial_task.BenchmarkTrialTask( bson.ObjectId(), bson.ObjectId(), result=result_id, state=batch_analysis.task.JobState.DONE).serialize() ).inserted_id
def setUp(self): self.zombie_db_client = mock_client_factory.create() self.mock_db_client = self.zombie_db_client.mock # Create the basic trial results and benchmarks self.trial_results = [ self.mock_db_client.trials_collection.insert_one( core.trial_result.TrialResult( bson.ObjectId(), True, core.sequence_type.ImageSequenceType.NON_SEQUENTIAL, {}).serialize()).inserted_id for _ in range(2) ] self.benchmarks = [ self.mock_db_client.benchmarks_collection.insert_one( mock_core.MockBenchmark().serialize()).inserted_id for _ in range(2) ] self.benchmark_trial_tasks = {} self.benchmark_results = {} # Create the benchmark results and tasks for benchmark_id in self.benchmarks: self.benchmark_trial_tasks[benchmark_id] = [] self.benchmark_results[benchmark_id] = [] for trial_result_id in self.trial_results: result_id = self.mock_db_client.results_collection.insert_one( core.benchmark.BenchmarkResult( benchmark_id, trial_result_id, True).serialize()).inserted_id self.benchmark_results[benchmark_id].append(result_id) self.benchmark_trial_tasks[benchmark_id].append( self.mock_db_client.tasks_collection.insert_one( benchmark_trial_task.BenchmarkTrialTask( trial_result_id, benchmark_id, result=result_id, state=batch_analysis.task.JobState.DONE).serialize( )).inserted_id)
def test_schedule_all_stores_benchmark_results(self): zombie_db_client = mock_client_factory.create() zombie_task_manager = mock_manager_factory.create() subject = MockExperiment() systems = [] image_sources = [] trial_results = [] benchmarks = [] benchmark_results = [] for _ in range(3): # Create entity = mock_core.MockSystem() systems.append( zombie_db_client.mock.system_collection.insert_one( entity.serialize()).inserted_id) entity = mock_core.MockImageSource() image_sources.append( zombie_db_client.mock.image_source_collection.insert_one( entity.serialize()).inserted_id) entity = mock_core.MockBenchmark() benchmarks.append( zombie_db_client.mock.benchmarks_collection.insert_one( entity.serialize()).inserted_id) for system_id in systems: for image_source_id in image_sources: # Create trial results for each combination of systems and image sources, # as if the run system tasks are complete entity = core.trial_result.TrialResult( system_id, True, core.sequence_type.ImageSequenceType.NON_SEQUENTIAL, {}) trial_result_id = zombie_db_client.mock.trials_collection.insert_one( entity.serialize()).inserted_id trial_results.append(trial_result_id) task = zombie_task_manager.get_run_system_task( system_id, image_source_id) task.mark_job_started('test', 0) task.mark_job_complete(trial_result_id) for trial_result_id in trial_results: for benchmark_id in benchmarks: # Create benchmark results for each combination of trial result and benchmark, # as if the benchmark system tasks are complete entity = core.benchmark.BenchmarkResult( benchmark_id, trial_result_id, True) benchmark_result_id = zombie_db_client.mock.trials_collection.insert_one( entity.serialize()).inserted_id benchmark_results.append(benchmark_result_id) task = zombie_task_manager.get_benchmark_task( trial_result_id, benchmark_id) task.mark_job_started('test', 0) task.mark_job_complete(benchmark_result_id) subject.schedule_all(zombie_task_manager.mock, zombie_db_client.mock, systems, image_sources, benchmarks) for trial_result_id in trial_results: for benchmark_id in benchmarks: benchmark_result_id = subject.get_benchmark_result( trial_result_id, benchmark_id) self.assertIsNotNone(benchmark_result_id) self.assertIn(benchmark_result_id, benchmark_results)
def setUp(self): self.zombie_db_client = mock_client_factory.create() self.mock_db_client = self.zombie_db_client.mock # Create the basic image sources, systems, and benchmarks. self.image_collections = [ make_image_collection(self.mock_db_client).identifier for _ in range(2) ] self.systems = [ self.mock_db_client.system_collection.insert_one( mock_core.MockSystem().serialize()).inserted_id for _ in range(2) ] self.benchmarks = [ self.mock_db_client.benchmarks_collection.insert_one( mock_core.MockBenchmark().serialize()).inserted_id for _ in range(2) ] # Add generate dataset tasks for all the image collections. self.generate_dataset_tasks = { image_collection_id: self.mock_db_client.tasks_collection.insert_one( generate_dataset_task.GenerateDatasetTask( bson.ObjectId(), bson.ObjectId(), {}, result=image_collection_id, state=batch_analysis.task.JobState.DONE).serialize() ).inserted_id for image_collection_id in self.image_collections } # Add controllers that follow the image sources self.controllers = { image_collection_id: self.mock_db_client.image_source_collection.insert_one( traj_follow_controller.TrajectoryFollowController( trajectory={}, trajectory_source=image_collection_id, sequence_type=core.sequence_type.ImageSequenceType. NON_SEQUENTIAL).serialize()).inserted_id for image_collection_id in self.image_collections } # Create run system tasks and trial results self.run_system_tasks = {} self.trial_results = {} for image_collection_id in self.image_collections: self.run_system_tasks[image_collection_id] = [] self.trial_results[image_collection_id] = [] for system_id in self.systems: trial_result_id = self.mock_db_client.trials_collection.insert_one( core.trial_result.TrialResult( system_id, True, core.sequence_type.ImageSequenceType.NON_SEQUENTIAL, {}).serialize()).inserted_id self.trial_results[image_collection_id].append(trial_result_id) self.run_system_tasks[image_collection_id].append( self.mock_db_client.tasks_collection.insert_one( run_system_task.RunSystemTask( system_id, image_collection_id, result=trial_result_id, state=batch_analysis.task.JobState.DONE).serialize( )).inserted_id)