示例#1
0
 def test_run_proc(self):
     """Check that LocalRunner jobs from other processes are checked"""
     p = subprocess.Popen('/bin/sleep 60', shell=True)
     pid = str(p.pid)
     self.assertEqual(LocalRunner._check_completed(pid, ''), False)
     os.kill(int(pid), signal.SIGTERM)
     p.wait()
     self.assertEqual(LocalRunner._check_completed(pid, ''), True)
示例#2
0
 def test_run_proc(self):
     """Check that LocalRunner jobs from other processes are checked"""
     p = subprocess.Popen('/bin/sleep 60', shell=True)
     pid = str(p.pid)
     self.assertEqual(LocalRunner._check_completed(pid, ''), False)
     os.kill(int(pid), signal.SIGTERM)
     p.wait()
     self.assertEqual(LocalRunner._check_completed(pid, ''), True)
示例#3
0
    def test_run_wait(self):
        """Check that LocalRunner runs and waits for processes successfully"""
        ws = DummyWebService()
        r = LocalRunner(['/bin/sleep', '60'])
        pid = r._run(ws)
        self.assert_(isinstance(pid, str))
        # Give the waiter thread enough time to start up
        for i in range(20):
            if pid in LocalRunner._waited_jobs:
                break
            time.sleep(0.05)
        self.assertEqual(LocalRunner._check_completed(pid, ''), False)
        self.assertEqual(pid in LocalRunner._waited_jobs, True)
        os.kill(int(pid), signal.SIGTERM)
        # Give the waiter thread enough time to close down
        for i in range(20):
            if pid not in LocalRunner._waited_jobs:
                break
            time.sleep(0.05)
        self.assertEqual(pid in LocalRunner._waited_jobs, False)
        # Make sure that non-zero return code causes a job failure
        event = ws._event_queue.get(timeout=0)
        event.process()
        self.assert_(isinstance(ws._exception, OSError))
        ws._exception = None

        # Check successful completion
        r1 = LocalRunner(['/bin/echo', 'foo'])
        r2 = LocalRunner(['/bin/echo', 'bar'])
        pid1 = r1._run(ws)
        pid2 = r2._run(ws)
        event1 = ws._event_queue.get()
        event2 = ws._event_queue.get()
        if event1.runid == pid1:
            self.assertEqual(event1.runid, pid1)
            self.assertEqual(event2.runid, pid2)
        else:
            self.assertEqual(event1.runid, pid2)
            self.assertEqual(event2.runid, pid1)
        self.assertEqual(type(event1.runner), LocalRunner)
        self.assertEqual(type(event2.runner), LocalRunner)
        self.assertEqual(ws._exception, None)
示例#4
0
    def test_run_wait(self):
        """Check that LocalRunner runs and waits for processes successfully"""
        ws = DummyWebService()
        r = LocalRunner(['/bin/sleep', '60'])
        pid = r._run(ws)
        self.assert_(isinstance(pid, str))
        # Give the waiter thread enough time to start up
        for i in range(20):
            if pid in LocalRunner._waited_jobs:
                break
            time.sleep(0.05)
        self.assertEqual(LocalRunner._check_completed(pid, ''), False)
        self.assertEqual(pid in LocalRunner._waited_jobs, True)
        os.kill(int(pid), signal.SIGTERM)
        # Give the waiter thread enough time to close down
        for i in range(20):
            if pid not in LocalRunner._waited_jobs:
                break
            time.sleep(0.05)
        self.assertEqual(pid in LocalRunner._waited_jobs, False)
        # Make sure that non-zero return code causes a job failure
        event = ws._event_queue.get(timeout=0)
        event.process()
        self.assert_(isinstance(ws._exception, OSError))
        ws._exception = None

        # Check successful completion
        r1 = LocalRunner(['/bin/echo', 'foo'])
        r2 = LocalRunner(['/bin/echo', 'bar'])
        pid1 = r1._run(ws)
        pid2 = r2._run(ws)
        event1 = ws._event_queue.get()
        event2 = ws._event_queue.get()
        if event1.runid == pid1:
            self.assertEqual(event1.runid, pid1)
            self.assertEqual(event2.runid, pid2)
        else:
            self.assertEqual(event1.runid, pid2)
            self.assertEqual(event2.runid, pid1)
        self.assertEqual(type(event1.runner), LocalRunner)
        self.assertEqual(type(event2.runner), LocalRunner)
        self.assertEqual(ws._exception, None)