Exemple #1
0
    def testPrintJobLog(self, mock_print):
        """Test that ToilStatus.printJobLog() reads the log from a failed command without error."""
        # Run a workflow that will always fail
        cmd = [
            'toil-cwl-runner', '--jobStore', self.toilDir, '--clean=never',
            'src/toil/test/cwl/alwaysfails.cwl', '--message', 'Testing'
        ]
        wf = subprocess.Popen(cmd)
        wf.wait()
        # print log and check output
        status = ToilStatus(self.toilDir)
        status.printJobLog()

        # Make sure it printed some kind of complaint about the missing command.
        args, kwargs = mock_print.call_args
        self.assertIn('invalidcommand', args[0])
Exemple #2
0
    def testGetPIDStatus(self):
        """Test that ToilStatus.getPIDStatus() behaves as expected."""
        jobstoreName = 'pidStatusTest'
        jobstoreLoc = os.path.join(os.getcwd(), jobstoreName)

        cmd = [
            'python', '-m', 'toil.test.sort.sort', 'file:' + jobstoreName,
            '--clean', 'never'
        ]
        wf = subprocess.Popen(cmd)
        time.sleep(
            2)  # Need to let jobstore be created before checking its contents.
        self.assertEqual(ToilStatus.getPIDStatus(jobstoreLoc), 'RUNNING')
        wf.wait()
        self.assertEqual(ToilStatus.getPIDStatus(jobstoreLoc), 'COMPLETED')
        os.remove(os.path.join(jobstoreLoc, 'pid.log'))
        self.assertEqual(ToilStatus.getPIDStatus(jobstoreLoc), 'QUEUED')
        shutil.rmtree(jobstoreLoc)
Exemple #3
0
    def testGetPIDStatus(self):
        """Test that ToilStatus.getPIDStatus() behaves as expected."""
        cmd = [
            'python', '-m', 'toil.test.sort.sort', 'file:' + self.toilDir,
            '--clean', 'never'
        ]
        wf = subprocess.Popen(cmd)
        time.sleep(
            2)  # Need to let jobstore be created before checking its contents.
        self.assertEqual('RUNNING', ToilStatus.getPIDStatus(self.toilDir))
        wf.wait()
        self.assertEqual('COMPLETED', ToilStatus.getPIDStatus(self.toilDir))
        os.remove(os.path.join(self.toilDir, 'pid.log'))
        self.assertEqual('QUEUED', ToilStatus.getPIDStatus(self.toilDir))

        for f in ['fileToSort.txt',
                  'sortedFile.txt']:  # This toil WF does not clean these up.
            if os.path.exists(f):
                os.remove(f)
Exemple #4
0
    def testGetStatusSuccessfulToilWF(self):
        """
        Test that ToilStatus.getStatus() behaves as expected with a successful Toil workflow.

        While this workflow could be called by importing and evoking its main function, doing so would remove the
        opprotunity to test the 'RUNNING' functionality of getStatus().
        """
        jobstoreName = 'successful-toil-js'
        jobstoreLoc = os.path.join(os.getcwd(), jobstoreName)
        cmd = [
            'python', '-m', 'toil.test.sort.sort', 'file:' + jobstoreName,
            '--clean', 'never'
        ]
        wf = subprocess.Popen(cmd)
        time.sleep(
            2)  # Need to let jobstore be created before checking its contents.
        self.assertEqual(ToilStatus.getStatus(jobstoreLoc), 'RUNNING')
        wf.wait()
        self.assertEqual(ToilStatus.getStatus(jobstoreLoc), 'COMPLETED')
        shutil.rmtree(jobstoreLoc)
Exemple #5
0
    def testGetStatusSuccessfulToilWF(self):
        """
        Test that ToilStatus.getStatus() behaves as expected with a successful Toil workflow.
         While this workflow could be called by importing and evoking its main function, doing so would remove the
        opprotunity to test the 'RUNNING' functionality of getStatus().
        """
        cmd = [
            'python', '-m', 'toil.test.sort.sort', 'file:' + self.toilDir,
            '--clean', 'never'
        ]
        wf = subprocess.Popen(cmd)
        time.sleep(
            2)  # Need to let jobstore be created before checking its contents.
        self.assertEqual('RUNNING', ToilStatus.getStatus(self.toilDir))
        wf.wait()
        self.assertEqual('COMPLETED', ToilStatus.getStatus(self.toilDir))

        for f in ['fileToSort.txt',
                  'sortedFile.txt']:  # This toil WF does not clean these up.
            if os.path.exists(f):
                os.remove(f)
Exemple #6
0
 def testGetStatusFailedCWLWF(self):
     """Test that ToilStatus.getStatus() behaves as expected with a failing CWL workflow."""
     files = [
         'src/toil/test/cwl/sorttool.cwl', 'src/toil/test/cwl/whale.txt'
     ]
     cmd = [
         'toil-cwl-runner', '--jobStore', self.toilDir, '--clean', 'never',
         '--badWorker', '1', files[0], '--reverse', '--input', files[1]
     ]
     wf = subprocess.Popen(cmd)
     wfRun = psutil.Process(pid=wf.pid)
     time.sleep(
         2
     )  # Needed to let the jobstore be created before checking its contents.
     wfRun.suspend(
     )  # This workflow runs so quickly that we need to pause so we can get a 'RUNNING' response.
     self.assertEqual('RUNNING', ToilStatus.getStatus(self.toilDir))
     wfRun.resume()
     wf.wait()
     result = ToilStatus.getStatus(self.toilDir)
     self.assertEqual('ERROR', result)
Exemple #7
0
    def testGetStatusFailedToilWF(self):
        """
        Test that ToilStatus.getStatus() behaves as expected with a failing Toil workflow.

        While this workflow could be called by importing and evoking its main function, doing so would remove the
        opprotunity to test the 'RUNNING' functionality of getStatus().
        """
        jobstoreName = 'failing-toil-js'
        jobstoreLoc = os.path.join(os.getcwd(), jobstoreName)
        # --badWorker is set to force failure.
        cmd = [
            'python', '-m', 'toil.test.sort.sort', 'file:' + jobstoreName,
            '--clean', 'never', '--badWorker', '1'
        ]
        wf = Popen(cmd)
        time.sleep(
            2
        )  # Needed to let the jobstore be created before checking its contents.
        self.assertEqual(ToilStatus.getStatus(jobstoreLoc), 'RUNNING')
        wf.wait()
        self.assertEqual(ToilStatus.getStatus(jobstoreLoc), 'ERROR')
        shutil.rmtree(jobstoreLoc)
Exemple #8
0
 def testGetStatusFailedCWLWF(self):
     """Test that ToilStatus.getStatus() behaves as expected with a failing CWL workflow."""
     files = [
         'src/toil/test/cwl/sorttool.cwl', 'src/toil/test/cwl/whale.txt'
     ]
     jobstoreName = 'failing-cwl-js'
     jobstoreLoc = os.path.join(os.getcwd(), jobstoreName)
     cmd = [
         'toil-cwl-runner', '--jobStore', jobstoreLoc, '--clean', 'never',
         '--badWorker', '1', files[0], '--reverse', '--input', files[1]
     ]
     wf = Popen(cmd)
     wfRun = psutil.Process(pid=wf.pid)
     time.sleep(
         2
     )  # Needed to let the jobstore be created before checking its contents.
     wfRun.suspend(
     )  # This workflow runs so quickly that we need to pause so we can get a 'RUNNING' response.
     self.assertEqual(ToilStatus.getStatus(jobstoreLoc), 'RUNNING')
     wfRun.resume()
     wf.wait()
     self.assertEqual(ToilStatus.getStatus(jobstoreLoc), 'ERROR')
     shutil.rmtree(jobstoreLoc)
Exemple #9
0
    def testGetStatusSuccessfulCWLWF(self):
        """Test that ToilStatus.getStatus() behaves as expected with a successful CWL workflow."""
        # Run a cwl workflow in a subprocess.
        files = [
            'src/toil/test/cwl/sorttool.cwl', 'src/toil/test/cwl/whale.txt'
        ]
        cmd = [
            'toil-cwl-runner', '--jobStore', self.toilDir, '--clean', 'never',
            files[0], '--reverse', '--input', files[1]
        ]
        wf = subprocess.Popen(cmd)
        wfRun = psutil.Process(pid=wf.pid)
        time.sleep(
            2
        )  # Needed to let the jobstore be created before checking its contents.
        wfRun.suspend(
        )  # This workflow runs so quickly that we need to pause so we can get a 'RUNNING' response.
        self.assertEqual('RUNNING', ToilStatus.getStatus(self.toilDir))
        wfRun.resume()
        wf.wait()
        self.assertEqual('COMPLETED', ToilStatus.getStatus(self.toilDir))

        if os.path.exists('output.txt'):  # This CWL WF does not clean this up.
            os.remove('output.txt')