예제 #1
0
    def test_job_run_many(self):
        """ Run a bunch of jobs concurrently via the same job service.
        """
        num_jobs = 32
        jobs = list()
        try:
            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['30']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            for _ in range(0, num_jobs):
                j = self.js.create_job(jd)
                jobs.append(j)

            # start all jobs
            for job in jobs:
                job.run()

            for job in jobs:
                job.cancel()
                assert job.state == rs.job.CANCELED

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(jobs)
예제 #2
0
    def test_job_suspend_resume(self):
        """ Test job.suspend()/resume() - expecting state: SUSPENDED/RUNNING
        """
        j = None
        try:
            jd = rs.job.Description()
            jd.executable = '/bin/sleep'
            jd.arguments = ['20']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()
            j.suspend()

            assert j.state == rs.job.SUSPENDED
            assert j.state == j.get_state()

            j.resume()
            assert j.state == rs.job.RUNNING
            assert j.state == j.get_state()

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
예제 #3
0
    def test_job_multiline_run(self):
        """ Test job.run() with multiline command
        """
        j = None
        try:
            jd = rs.job.Description()
            jd.executable = '/bin/sh'
            jd.arguments = [
                """-c "python -c '
import time
if True:
  if 1:
    time.sleep(3)
' " """
            ]

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()

            assert (j.state in [rs.job.RUNNING, rs.job.PENDING])
            j.wait()
            assert (j.state in [rs.job.DONE])

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
예제 #4
0
    def test_get_id(self):
        """ Test job.get_id() / job.id
        """

        j = None
        try:

            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()

            assert j.id is not None
            assert j.id == j.get_id()

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
예제 #5
0
    def test_job_wait(self):
        """
        Test job.wait() - expecting state: DONE
        """

        j = None
        try:
            t_min = time.time()
            time.sleep(0.1)

            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments  = ['2']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()
            j.wait()

            time.sleep(0.5)
            t_max = time.time()

            # assert success
            assert(j.state == rs.job.DONE), "%s != %s" % (j.state, rs.job.DONE)

            print t_min
            print j.created
            print j.started
            print j.finished
            print t_max

            # expect job time information is be reported in seconds since epoch
            assert(int(t_min) <= int(j.created ) <= int(t_max))
            assert(int(t_min) <= int(j.started ) <= int(t_max))
            assert(int(t_min) <= int(j.finished) <= int(t_max))

            assert(int(j.created) <= int(j.started))
            assert(int(j.started) <= int(j.finished))

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
예제 #6
0
    def test_get_service_url(self):
        """ Test if job.service_url == Service.url
        """
        j = None
        try:
            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)

            assert j.service_url == self.js.url

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
예제 #7
0
    def test_job_service_create(self):
        """ Test service.create_job() - expecting state 'NEW'
        """
        j = None
        try:
            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            assert j.state == j.get_state()
            assert j.state == rs.job.NEW

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
예제 #8
0
    def test_get_exit_code(self):
        """ Test job.exit_code
        """
        j = None
        try:
            jd = rs.job.Description()
            jd.executable = "/bin/sleep"

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()
            j.wait()

            ec = j.exit_code
            assert ec == 1, "%s != 1" % ec

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
예제 #9
0
    def test_job_cancel(self):
        """ Test job.cancel() - expecting state: CANCELED
        """
        j = None
        try:
            jd = rs.job.Description()
            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)

            j.run()
            j.cancel()
            assert j.state == rs.job.CANCELED

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
예제 #10
0
    def test_job_run(self):
        """ Test job.run() - expecting state: RUNNING/PENDING
        """
        j = None
        try:
            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()

            assert (j.state in [rs.job.RUNNING, rs.job.PENDING])

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)