Beispiel #1
0
    def test_job_with_error_is_handled_correctly(self):
        # Given.
        problem = EllipticalDrop(self.sim_dir, self.output_dir)
        problem.cases[0].base_command += ' --xxx'
        s = self._make_scheduler()
        t = TaskRunner(tasks=[SolveProblem(problem=problem)], scheduler=s)

        # When.
        try:
            t.run(wait=1)
        except RuntimeError:
            pass

        # Then.

        # Ensure that the directories are copied over when they have errors.
        sim1 = os.path.join(self.root, self.sim_dir, 'elliptical_drop',
                            'no_update_h')
        self.assertTrue(os.path.exists(sim1))
        sim2 = os.path.join(self.root, self.sim_dir, 'elliptical_drop',
                            'update_h')
        self.assertTrue(os.path.exists(sim2))

        # Ensure that all the correct but already scheduled jobs are completed.
        task_status = t.task_status
        status_values = list(task_status.values())
        self.assertEqual(status_values.count('error'), 1)
        self.assertEqual(status_values.count('done'), 1)
        self.assertEqual(status_values.count('not started'), 1)
        for t, s in task_status.items():
            if s == 'done':
                self.assertTrue(t.complete())
            if s == 'error':
                self.assertFalse(t.complete())
Beispiel #2
0
    def test_automation(self):
        # Given.
        problem = EllipticalDrop(self.sim_dir, self.output_dir)
        s = self._make_scheduler()
        t = TaskRunner(tasks=[SolveProblem(problem=problem)], scheduler=s)

        # When.
        t.run(wait=1)

        # Then.
        sim1 = os.path.join(self.root, self.sim_dir, 'elliptical_drop',
                            'no_update_h')
        self.assertTrue(os.path.exists(sim1))
        sim2 = os.path.join(self.root, self.sim_dir, 'elliptical_drop',
                            'update_h')
        self.assertTrue(os.path.exists(sim2))

        results = os.path.join(self.root, self.output_dir, 'elliptical_drop',
                               'result.txt')
        self.assertTrue(os.path.exists(results))
        data = open(results).read()
        self.assertTrue('no_update_h' in data)
        self.assertTrue('update_h' in data)

        # When.
        problem = EllipticalDrop(self.sim_dir, self.output_dir)
        t = TaskRunner(tasks=[SolveProblem(problem=problem)], scheduler=s)

        # Then.
        self.assertEqual(len(t.todo), 0)

        # When
        problem.clean()

        # Then.
        out1 = os.path.join(self.root, self.output_dir, 'elliptical_drop',
                            'update_h')
        out2 = os.path.join(self.root, self.output_dir, 'elliptical_drop',
                            'no_update_h')
        self.assertFalse(os.path.exists(out1))
        self.assertFalse(os.path.exists(out2))
        self.assertTrue(os.path.exists(sim1))
        self.assertTrue(os.path.exists(sim2))
Beispiel #3
0
    def test_nothing_is_run_when_output_exists(self):
        # Given.
        s = self._make_scheduler()
        output = os.path.join(self.output_dir, 'elliptical_drop')
        os.makedirs(output)

        # When
        problem = EllipticalDrop(self.sim_dir, self.output_dir)
        t = TaskRunner(tasks=[SolveProblem(problem=problem)], scheduler=s)

        # Then.
        self.assertEqual(len(t.todo), 0)
Beispiel #4
0
    def test_simulation_with_dependencies(self):
        # Given
        class A(Problem):
            def setup(self):
                cmd = 'python -c "import time; print(time.time())"'
                s1 = Simulation(self.input_path('1'), cmd)
                s2 = Simulation(self.input_path('2'), cmd, depends=[s1])
                s3 = Simulation(self.input_path('3'), cmd, depends=[s1, s2])
                self.cases = [s1, s2, s3]

            def run(self):
                self.make_output_dir()

        s = self._make_scheduler()

        # When
        problem = A(self.sim_dir, self.output_dir)
        task = SolveProblem(problem)
        t = TaskRunner(tasks=[task], scheduler=s)

        # Then
        self.assertEqual(len(t.todo), 4)
        # Basically only one instance of CommandTask should be created.
        names = [x.__class__.__name__ for x in t.todo]
        self.assertEqual(names.count('CommandTask'), 3)
        self.assertEqual(names.count('SolveProblem'), 1)

        # When
        t.run(wait=0.1)
        wait_until(lambda: not task.complete())

        # Then
        ct1_t, ct2_t, ct3_t = [
            self._get_time(problem.input_path(x)) for x in ('1', '2', '3')
        ]
        self.assertTrue(ct2_t > ct1_t)
        self.assertTrue(ct3_t > ct2_t)