def test_initialize_experiment_in_db(dispatcher_experiment): """Tests that _initialize_experiment_in_db adds the right things to the database.""" trials_args = itertools.product(dispatcher_experiment.benchmarks, range(dispatcher_experiment.num_trials), dispatcher_experiment.fuzzers) trials = [ models.Trial(fuzzer=fuzzer, experiment=dispatcher_experiment.experiment_name, benchmark=benchmark) for benchmark, _, fuzzer in trials_args ] dispatcher._initialize_experiment_in_db(dispatcher_experiment.config, trials) db_experiments = db_utils.query(models.Experiment).all() assert len(db_experiments) == 1 db_experiment = db_experiments[0] assert db_experiment.name == os.environ['EXPERIMENT'] trials = db_utils.query(models.Trial).all() fuzzer_and_benchmarks = [(trial.benchmark, trial.fuzzer) for trial in trials] assert fuzzer_and_benchmarks == ([('benchmark-1', 'fuzzer-a'), ('benchmark-1', 'fuzzer-b')] * 4) + [('benchmark-2', 'fuzzer-a'), ('benchmark-2', 'fuzzer-b')] * 4
def test_measure_all_trials(_, __, mocked_execute, db, fs): """Tests that measure_all_trials does what is intended under normal conditions.""" mocked_execute.return_value = new_process.ProcessResult(0, '', False) dispatcher._initialize_experiment_in_db( experiment_utils.get_experiment_name(), BENCHMARKS, FUZZERS, NUM_TRIALS) trials = scheduler.get_pending_trials( experiment_utils.get_experiment_name()).all() for trial in trials: trial.time_started = datetime.datetime.utcnow() db_utils.add_all(trials) fs.create_file(measurer.get_experiment_folders_dir() / NEW_UNIT) mock_pool = test_utils.MockPool() assert measurer.measure_all_trials(experiment_utils.get_experiment_name(), MAX_TOTAL_TIME, mock_pool, queue.Queue()) actual_ids = [call[2] for call in mock_pool.func_calls] # 4 (trials) * 2 (fuzzers) * 2 (benchmarks) assert sorted(actual_ids) == list(range(1, 17))