Ejemplo n.º 1
0
 def test_wait(self):
     p = DummyProcess.new()
     self.assertTrue(p.wait(timeout=2.),
                     "Not running process didn't return from wait")
     self.executor.play(p)
     self.assertTrue(p.wait(timeout=2.),
                     "Process failed to return from wait when done")
Ejemplo n.º 2
0
 def test_interrupt(self):
     p = DummyProcess.new()
     w = WaitOnState(p, ProcessState.STOPPED)
     self.assertFalse(w.wait(0.2))
     w.interrupt()
     self.manager.start(p)
     self.assertFalse(w.wait(0.2))
Ejemplo n.º 3
0
 def test_interrupt_not_waiting(self):
     """
     If you interrupt when it's not waiting then nothing happens.
     """
     p = DummyProcess.new()
     waiton = WaitOnProcessState(p, ProcessState.STOPPED)
     waiton.interrupt()
Ejemplo n.º 4
0
 def test_pause_play(self):
     """
     Pausing a process that is not playing should have no effect and next 
     time it is played it should continue normally.
     """
     p = DummyProcess.new()
     self.assertTrue(p.pause(timeout=1.))
     p.play()
     self.assertEqual(p.state, ProcessState.STOPPED)
Ejemplo n.º 5
0
    def test_play(self):
        p = DummyProcess.new()
        self.assertFalse(p.has_finished())

        fut = self.executor.play(p)
        self.assertTrue(fut.wait(timeout=1.))

        self.assertTrue(p.has_terminated())
        self.assertTrue(p.has_finished())
Ejemplo n.º 6
0
    def test_abort(self):
        # Abort a process before it gets started, this will get ignored and the
        # process will run normally
        proc = DummyProcess.new()
        proc.abort()
        proc.play()

        self.assertFalse(proc.has_aborted())
        self.assertEqual(proc.state, ProcessState.STOPPED)
Ejemplo n.º 7
0
    def test_normal_process(self):
        saver = _EventSaver()
        self.emitter.start_listening(saver.event_ocurred, "process.*")

        p = DummyProcess.new()
        preamble = "process.{}.".format(p.pid)
        p.play()

        self.assertEqual(saver.events, [preamble + 'finished', preamble + 'stopped'])
Ejemplo n.º 8
0
    def test_state_messages(self):
        tp = PythonThreadPoolExecutor(max_workers=1)
        for state in (ProcessState.RUNNING, ProcessState.STOPPED):
            p = DummyProcess.new()
            waiton = WaitOnProcessState(p, state)
            future = tp.submit(waiton.wait)
            while not future.running():
                pass

            p.play()
            self.assertTrue(future.result(timeout=2.))
Ejemplo n.º 9
0
    def test_interrupt(self):
        tp = PythonThreadPoolExecutor(max_workers=1)

        p = DummyProcess.new()
        waiton = WaitOnProcessState(p, ProcessState.STOPPED)
        future = tp.submit(waiton.wait)
        while not future.running():
            pass

        with self.assertRaises(Interrupted):
            waiton.interrupt()
            future.result(timeout=2.)
Ejemplo n.º 10
0
    def test_finished_stopped(self):
        for event in ("finished", "stopped"):
            tp = ThreadPoolExecutor(max_workers=1)
            p = DummyProcess.new()

            w = WaitOnProcessEvent(self.emitter, p.pid, event)
            future = tp.submit(w.wait)
            while not future.running():
                pass

            p.play()
            self.assertTrue(future.result(timeout=2.))
Ejemplo n.º 11
0
    def test_spec(self):
        """
        Check that the references to specs are doing the right thing...
        """
        dp = DummyProcess.new()
        self.assertIsNot(DummyProcess.spec(), Process.spec())
        self.assertIs(dp.spec(), DummyProcess.spec())

        class Proc(DummyProcess):
            pass

        self.assertIsNot(Proc.spec(), Process.spec())
        self.assertIsNot(Proc.spec(), DummyProcess.spec())
        p = Proc.new()
        self.assertIs(p.spec(), Proc.spec())
Ejemplo n.º 12
0
 def test_abort(self):
     proc = DummyProcess.new()
     proc.abort()
     self.assertTrue(proc.has_aborted())
     self.assertEqual(proc.state, ProcessState.STOPPED)
Ejemplo n.º 13
0
 def test_start(self):
     p = DummyProcess.new()
     self.assertFalse(p.has_finished())
     self.manager.start(p)
     wait_until_stopped(p, 1)
     self.assertTrue(p.has_finished())
Ejemplo n.º 14
0
 def test_future_pid(self):
     p = DummyProcess.new()
     future = self.manager.start(p)
     self.assertEqual(future.pid, p.pid)
Ejemplo n.º 15
0
 def test_already_in_state(self):
     p = DummyProcess.new()
     self.assertTrue(WaitOnProcessState(p, ProcessState.CREATED).wait(timeout=2.))
Ejemplo n.º 16
0
 def test_future_pid(self):
     p = DummyProcess.new()
     future = self.executor.play(p)
     self.assertEqual(future.pid, p.pid)