def test_command_tasks_handles_errors_correctly(self): # Given s = self._make_scheduler() cmd = 'python --junk' t = CommandTask(cmd, output_dir=self.sim_dir) self.assertFalse(t.complete()) # When t.run(s) try: wait_until(lambda: not t.complete()) except RuntimeError: pass # Then self.assertFalse(t.complete()) self.assertEqual(t.job_proxy.status(), 'error') # A new command task should still detect that the run failed, even # though the output directory exists. # Given t = CommandTask(cmd, output_dir=self.sim_dir) # When/Then self.assertFalse(t.complete())
def test_command_tasks_converts_dollar_output_dir(self): # Given s = self._make_scheduler() cmd = '''python -c "print('$output_dir')"''' t = CommandTask(cmd, output_dir=self.sim_dir) self.assertFalse(t.complete()) # When t.run(s) wait_until(lambda: not t.complete()) # Then self.assertTrue(t.complete()) self.assertEqual(t.job_proxy.status(), 'done') self.assertEqual(t.job_proxy.get_stdout().strip(), self.sim_dir)
def test_tasks_with_dependencies(self): # Given s = self._make_scheduler() cmd = 'python -c "import time; print(time.time())"' ct1_dir = os.path.join(self.sim_dir, '1') ct2_dir = os.path.join(self.sim_dir, '2') ct3_dir = os.path.join(self.sim_dir, '3') ct1 = CommandTask(cmd, output_dir=ct1_dir) ct2 = CommandTask(cmd, output_dir=ct2_dir, depends=[ct1]) ct3 = CommandTask(cmd, output_dir=ct3_dir, depends=[ct1, ct2]) # When t = TaskRunner(tasks=[ct1, ct2, ct3], scheduler=s) # Then self.assertEqual(len(t.todo), 3) # When t.run(wait=0.1) wait_until(lambda: not ct3.complete()) # Then. # Ensure that the tasks are run in the right order. ct1_t, ct2_t, ct3_t = [ self._get_time(x) for x in (ct1_dir, ct2_dir, ct3_dir) ] self.assertTrue(ct2_t > ct1_t) self.assertTrue(ct3_t > ct2_t)
def test_remote_command_tasks_complete_method_works(self): # Given s = self._make_scheduler() cmd = 'python -c "print(1)"' t = CommandTask(cmd, output_dir=self.sim_dir) self.assertFalse(t.complete()) self.assertFalse( os.path.exists(os.path.join(self.sim_dir, 'stdout.txt'))) # When t.run(s) wait_until(lambda: not t.complete()) # Then self.assertTrue(t.complete()) self.assertTrue( os.path.exists(os.path.join(self.sim_dir, 'stdout.txt'))) # Test that if we call it repeatedly that it does indeed return True self.assertTrue(t.complete())