def test_running_to_finished(self): logger.info("Testing job status update running to finished") with tempfile.TemporaryDirectory() as sub_dir: # Setup running job in DB self.job_user_A_project_A.sub_dir = sub_dir job_dir = os.path.join("/W04_cluster_scratch/", str(self.job_user_A_project_A.job_id)) self.job_user_A_project_A.job_dir = job_dir self.job_user_A_project_A.job_status = Job.JOB_STATUS_RUNNING self.job_user_A_project_A.full_clean() self.job_user_A_project_A.save() created_job = Job.objects.get(pk=self.job_user_A_project_A.job_id) self.assertEqual(created_job.job_status, Job.JOB_STATUS_RUNNING) # Create finished job on filesystem new_job_dir = os.path.join(sub_dir, str(self.job_user_A_project_A.job_id)) os.makedirs(new_job_dir) update_status_of_job(created_job) updated_job = Job.objects.get(job_id=self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_id, self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_status, Job.JOB_STATUS_FINISHED) self.assertEqual(updated_job.job_dir, new_job_dir)
def test_running_to_running(self): logger.info("Testing job status update running to running") with tempfile.TemporaryDirectory() as sub_dir: with tempfile.TemporaryDirectory() as scratch_dir: make_cluster_script(job_id=123, sub_dir=sub_dir, scratch_dir=scratch_dir) self.job_user_A_project_A.sub_dir = sub_dir self.job_user_A_project_A.job_dir = scratch_dir self.job_user_A_project_A.job_status = Job.JOB_STATUS_RUNNING self.job_user_A_project_A.full_clean() self.job_user_A_project_A.save() created_job = Job.objects.get( pk=self.job_user_A_project_A.job_id) self.assertEqual(created_job.job_status, Job.JOB_STATUS_RUNNING) update_status_of_job(created_job) updated_job = Job.objects.get(job_id=self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_id, self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_status, Job.JOB_STATUS_RUNNING) self.assertEqual(updated_job.job_dir, scratch_dir) self.assertEqual(updated_job.updated, created_job.updated)
def test_pending_to_running_no_scratch_dir(self): logger.info("Testing job status update pending to running." " Scratch dir does not exist.") with tempfile.TemporaryDirectory() as sub_dir: # Setup pending job in DB self.job_user_A_project_A.sub_dir = sub_dir job_dir = os.path.join( sub_dir, str(self.job_user_A_project_A.job_id) + ".pending") self.job_user_A_project_A.job_dir = job_dir self.job_user_A_project_A.full_clean() self.job_user_A_project_A.save() created_job = Job.objects.get(pk=self.job_user_A_project_A.job_id) self.assertEqual(created_job.job_status, Job.JOB_STATUS_PENDING) not_existing_dir = "/does/not/exist/dir" self.assertFalse(os.path.exists(not_existing_dir)) make_cluster_script(job_id=self.job_user_A_project_A.job_id, sub_dir=sub_dir, scratch_dir=not_existing_dir) update_status_of_job(created_job) updated_job = Job.objects.get(job_id=self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_id, self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_status, Job.JOB_STATUS_NONE) self.assertEqual(updated_job.job_dir, None)
def test_pending_to_running(self): logger.info("Testing job status update pending to running") with tempfile.TemporaryDirectory() as sub_dir: # Setup pending job in DB self.job_user_A_project_A.sub_dir = sub_dir job_dir = os.path.join( sub_dir, str(self.job_user_A_project_A.job_id) + ".pending") self.job_user_A_project_A.job_dir = job_dir self.job_user_A_project_A.full_clean() self.job_user_A_project_A.save() created_job = Job.objects.get(pk=self.job_user_A_project_A.job_id) self.assertEqual(created_job.job_status, Job.JOB_STATUS_PENDING) # Create running status on filesystem with tempfile.TemporaryDirectory() as scratch_dir: make_cluster_script(job_id=self.job_user_A_project_A.job_id, sub_dir=sub_dir, scratch_dir=scratch_dir) update_status_of_job(created_job) updated_job = Job.objects.get(job_id=self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_id, self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_status, Job.JOB_STATUS_RUNNING) self.assertEqual(updated_job.job_dir, scratch_dir)
def test_wrong_input_type(self): logger.info("Testing job status update with integer input") update_status_of_job(123) logger.info("Testing job status update with string input") update_status_of_job("123") logger.info("Testing job status update with bool input") update_status_of_job(True) update_status_of_job(False) logger.info("Testing job status update with None input") update_status_of_job(None)
def test_running_to_none(self): logger.info("Testing job status update running to none") with tempfile.TemporaryDirectory() as sub_dir: # # Setup running job in DB self.job_user_A_project_A.sub_dir = sub_dir job_dir = os.path.join("/W04_cluster_scratch/", str(self.job_user_A_project_A.job_id)) self.job_user_A_project_A.job_dir = job_dir self.job_user_A_project_A.job_status = Job.JOB_STATUS_RUNNING self.job_user_A_project_A.full_clean() self.job_user_A_project_A.save() created_job = Job.objects.get(pk=self.job_user_A_project_A.job_id) self.assertEqual(created_job.job_status, Job.JOB_STATUS_RUNNING) update_status_of_job(created_job) updated_job = Job.objects.get(job_id=self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_id, self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_status, Job.JOB_STATUS_NONE) self.assertIsNone(updated_job.job_dir)
def test_pending_to_none(self): logger.info("Testing job status update pending to none") with tempfile.TemporaryDirectory() as sub_dir: # Setup pending job in DB self.job_user_A_project_A.sub_dir = sub_dir job_dir = os.path.join( sub_dir, str(self.job_user_A_project_A.job_id) + ".pending") self.job_user_A_project_A.job_dir = job_dir self.job_user_A_project_A.full_clean() self.job_user_A_project_A.save() created_job = Job.objects.get(pk=self.job_user_A_project_A.job_id) self.assertEqual(created_job.job_status, Job.JOB_STATUS_PENDING) update_status_of_job(created_job) updated_job = Job.objects.get(job_id=self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_id, self.job_user_A_project_A.job_id) self.assertEqual(updated_job.job_status, Job.JOB_STATUS_NONE) self.assertIsNone(updated_job.job_dir)