Beispiel #1
0
    def test_play_all(self):
        procs = []

        # Launch a bunch of processes
        for i in range(0, 9):
            procs.append(WaitForSignalProcess.new())
            self.manager.start(procs[-1])

        wait_until(procs, ProcessState.WAITING, timeout=1)

        # Check they are all in state we expect
        for p in procs:
            self.assertTrue(p.is_playing(), "state '{}'".format(p.state))

        # Now try and pause them all
        self.manager.pause_all()

        # Check they are all in state we expect
        for p in procs:
            self.assertEqual(p.state, ProcessState.WAITING)
            self.assertFalse(p.is_playing())

        self.manager.play_all()

        for p in procs:
            p.continue_()
        wait_until_stopped(procs)

        for p in procs:
            self.assertEqual(p.state, ProcessState.STOPPED)
            self.manager.shutdown()
            self.assertFalse(p.is_playing())
Beispiel #2
0
    def test_push_over_limit(self):
        with SchedulingExecutor(max_threads=2) as executor:
            procs = (WaitForSignalProcess(), WaitForSignalProcess(),
                     WaitForSignalProcess())

            # Play first two
            executor.play(procs[0])
            executor.play(procs[1])

            # Get first two to the waiting state
            self.assertTrue(
                wait_until((procs[0], procs[1]),
                           ProcessState.WAITING,
                           timeout=2.))

            self.assertTrue(procs[0].is_playing())
            self.assertTrue(procs[1].is_playing())
            self.assertFalse(procs[2].is_playing())

            # Now play third
            executor.play(procs[2])

            # Get third to the waiting state
            self.assertTrue(
                wait_until(procs[2], ProcessState.WAITING, timeout=2.))

            # Now that it's waiting p2 should be pulled and the other two should be playing
            self.assertTrue(procs[2].wait(timeout=2.))

            # Check the final expected state
            # WARNING: The others could not be playing *yet* because it is too early
            time.sleep(0.1)
            self.assertTrue(procs[1].is_playing())
            self.assertFalse(procs[2].is_playing())
            self.assertTrue(procs[0].is_playing())
Beispiel #3
0
    def test_pause(self):
        # Create the process and wait until it is waiting
        p = WaitForSignalProcess.new()
        self.controller.insert_and_play(p)
        wait_until(p, ProcessState.WAITING)
        self.assertTrue(p.is_playing())

        # Send a message asking the process to pause
        self.assertIsNotNone(self.publisher.pause(p.pid, timeout=5.))
        self.assertFalse(p.is_playing())
Beispiel #4
0
 def test_abort_future(self):
     """
     Test aborting a process through the future
     """
     self.assertEqual(self.executor.get_num_processes(), 0)
     proc = WaitForSignalProcess.new()
     future = self.executor.play(proc)
     wait_until(proc, ProcessState.WAITING)
     self.assertTrue(future.abort(timeout=2.))
     self.assertEqual(self.executor.get_num_processes(), 0)
Beispiel #5
0
 def test_abort_interrupt(self):
     """
     Test aborting a process through the process manager
     """
     self.assertEqual(self.executor.get_num_processes(), 0)
     proc = WaitForSignalProcess.new()
     # Start a process and make sure it is waiting
     future = self.executor.play(proc)
     wait_until(proc, ProcessState.WAITING)
     # Then interrupt by aborting
     self.assertTrue(future.abort(timeout=2.))
     self.assertEqual(self.executor.get_num_processes(), 0)
Beispiel #6
0
    def test_wait_pause_play(self):
        p = WaitForSignalProcess.new()
        self.executor.play(p)

        # Wait
        self.assertTrue(wait_until(p, ProcessState.WAITING, timeout=2.))

        # Pause
        self.assertTrue(p.pause(timeout=1.))

        # Play
        self.executor.play(p)
        self.assertTrue(wait_until(p, ProcessState.WAITING, timeout=2.))
Beispiel #7
0
    def test_wait_continue(self):
        p = WaitForSignalProcess.new()
        t = threading.Thread(target=p.play)
        t.start()
        self.assertTrue(wait_until(p, ProcessState.WAITING, 5))
        self.assertEqual(p.state, ProcessState.WAITING)

        self.assertTrue(p.is_playing())
        p.continue_()

        self.assertTrue(wait_until(p, ProcessState.STOPPED, 5))

        self.assertEqual(p.state, ProcessState.STOPPED)
Beispiel #8
0
    def test_pause(self):
        # Create the process and wait until it is waiting
        p = WaitForSignalProcess.new()
        self.manager.start(p)
        wait_until(p, ProcessState.WAITING)
        self.assertTrue(p.is_playing())

        # Send a message asking the process to pause
        self.channel.basic_publish(
            exchange=self.exchange, routing_key='',
            body=action_encode({'pid': p.pid, 'intent': 'pause'}))
        self.controller.poll(time_limit=1)

        self.assertFalse(p.is_playing())
        self.assertTrue(self.manager.abort(p.pid, timeout=10))
Beispiel #9
0
 def test_wait_continue(self):
     p = WaitForSignalProcess.new()
     self.executor.play(p)
     self.assertTrue(wait_until(p, ProcessState.WAITING, timeout=1.))
     p.continue_()
     self.assertTrue(p.wait(timeout=2.))
     self.assertTrue(p.has_finished())
Beispiel #10
0
    def test_abort(self):
        # Create the process and wait until it is waiting
        p = WaitForSignalProcess.new()
        self.manager.start(p)
        wait_until(p, ProcessState.WAITING)
        self.assertTrue(p.is_playing())

        # Send a message asking the process to abort
        self.channel.basic_publish(
            exchange=self.exchange, routing_key='',
            body=action_encode({'pid': p.pid, 'intent': 'abort'}))
        self.controller.poll(time_limit=1)

        self.assertTrue(wait_until(p, ProcessState.STOPPED, 10),
                        "Process did not stop before timeout")
        self.assertTrue(p.has_aborted())
        self.manager.shutdown()
Beispiel #11
0
 def test_play_pause_abort(self):
     procs = []
     for i in range(0, 10):
         procs.append(WaitForSignalProcess.new())
         self.manager.start(procs[-1])
     self.assertTrue(wait_until(procs, ProcessState.WAITING))
     self.assertTrue(self.manager.pause_all(timeout=2))
     self.assertTrue(self.manager.abort_all(timeout=2))
Beispiel #12
0
    def test_simple_queue(self):
        with SchedulingExecutor(max_threads=2) as executor:
            procs = []
            for i in range(10):
                proc = DummyProcess()
                procs.append(proc)
                executor.play(proc)

            self.assertTrue(wait_until(procs, ProcessState.STOPPED,
                                       timeout=2.))
Beispiel #13
0
    def test_abort(self):
        p = WaitForSignalProcess.new()
        t = threading.Thread(target=p.play)

        # Start the process
        t.start()

        # Wait until it is waiting
        wait_until(p, ProcessState.WAITING)
        self.assertEqual(p.state, ProcessState.WAITING)

        # Abort it
        p.abort()

        # Wait until it's completely finished
        wait_until_stopped(p)
        self.assertEqual(p.state, ProcessState.STOPPED)
        self.assertTrue(p.has_aborted())

        self.safe_join(t)
Beispiel #14
0
    def test_wait_pause_play_continue(self):
        p = WaitForSignalProcess.new()

        fut = self.executor.play(p)

        # Wait
        self.assertTrue(wait_until(p, ProcessState.WAITING, 1.))
        self.assertTrue(p.is_playing())

        # Pause
        self.assertTrue(p.pause(timeout=1.))
        self.assertFalse(p.is_playing())

        # Play
        fut.play()
        self.assertEqual(p.state, ProcessState.WAITING)

        # Continue
        p.continue_()
        self.assertTrue(wait_until(p, ProcessState.STOPPED), 1.)
Beispiel #15
0
    def test_wait_pause_play_continue(self):
        p = WaitForSignalProcess.new()

        t = threading.Thread(target=p.play)
        t.start()
        self.assertTrue(wait_until(p, ProcessState.WAITING, 5))

        self.assertTrue(p.is_playing())
        p.pause()
        self.safe_join(t)
        self.assertFalse(p.is_playing())

        t = threading.Thread(target=p.play)
        t.start()
        self.assertEqual(p.state, ProcessState.WAITING)
        p.continue_()

        self.assertTrue(wait_until(p, ProcessState.STOPPED), 5)
        self.safe_join(t, 5)
        self.assertFalse(t.is_alive())
Beispiel #16
0
    def test_future_abort(self):
        p = WaitForSignalProcess.new()
        future = self.executor.play(p)

        # Wait
        self.assertTrue(wait_until(p, ProcessState.WAITING))
        self.assertTrue(p.is_playing())

        # Abort
        self.assertTrue(future.abort(timeout=3.))
        self.assertTrue(p.has_aborted())
Beispiel #17
0
    def test_play_pause_abort(self):
        num_procs = 10
        procs = []
        for i in range(0, num_procs):
            procs.append(WaitForSignalProcess.new())
            self.executor.play(procs[-1])

        # Wait
        self.assertTrue(wait_until(procs, ProcessState.WAITING))

        self.assertEqual(self.executor.pause_all(timeout=3.), num_procs)
Beispiel #18
0
    def test_status(self):
        procs = []
        for i in range(0, 20):
            procs.append(WaitForSignalProcess.new())
        for p in procs:
            self.manager.start(p)
        wait_until(procs, ProcessState.WAITING)

        response = self._send_and_get()
        d = json.loads(response)
        self.assertEqual(len(d), len(procs))
        self.assertSetEqual(set([str(p.pid) for p in procs]), set(d.keys()))

        playing = set([entry['playing'] for entry in d.itervalues()])
        self.assertSetEqual(playing, {True})

        self.assertTrue(self.manager.abort_all(timeout=10),
                        "Couldn't abort all processes in timeout")

        response = self._send_and_get()
        self.assertIsNone(response)
Beispiel #19
0
    def test_simple_push_over_limit(self):
        with SchedulingExecutor(max_threads=1) as executor:
            p1 = WaitForSignalProcess()
            p2 = WaitForSignalProcess()

            f1 = executor.play(p1)
            self.assertTrue(wait_until(p1, ProcessState.WAITING, timeout=2.))

            # This should push of P1
            f2 = executor.play(p2)
            self.assertTrue(p1.wait(timeout=1.))
            self.assertTrue(wait_until(p2, ProcessState.WAITING, timeout=2.))

            # Now P2 should be paused and P1 running again
            self.assertTrue(p2.wait(timeout=1.))

            # Finish p1
            p1.continue_()
            self.assertTrue(f1.wait(timeout=1.))

            # Now P2 should be running again
            p2.continue_()
            self.assertTrue(f2.wait(timeout=1.))
Beispiel #20
0
    def test_abort(self):
        # Create the process and wait until it is waiting
        p = WaitForSignalProcess.new()
        self.controller.insert_and_play(p)
        self.assertTrue(wait_until(p, ProcessState.WAITING, timeout=2.))
        self.assertTrue(p.is_playing())

        # Send a message asking the process to abort
        self.assertIsNotNone(
            self.publisher.abort(p.pid, msg='Farewell', timeout=5.))
        self.assertTrue(p.wait(timeout=2.), "Process failed to stop running")
        self.assertFalse(p.is_playing())
        self.assertTrue(p.has_aborted())
        self.assertEqual(p.get_abort_msg(), 'Farewell')
Beispiel #21
0
    def test_future_pause_play(self):
        p = WaitForSignalProcess.new()
        future = self.executor.play(p)

        # Wait
        self.assertTrue(wait_until(p, ProcessState.WAITING))
        self.assertTrue(p.is_playing())

        # Pause
        self.assertTrue(future.pause(timeout=3.))
        self.assertFalse(p.is_playing())

        # Play
        future.play()
        p.continue_()
        self.assertTrue(future.wait(timeout=1.))
Beispiel #22
0
    def test_restart(self):
        p = _RestartProcess.new()

        future = self.executor.play(p)
        self.assertTrue(wait_until(p, ProcessState.WAITING, timeout=2.))

        # Save the state of the process
        bundle = Bundle()
        p.save_instance_state(bundle)
        self.assertTrue(future.abort(timeout=2.))

        # Load a process from the saved state
        p = _RestartProcess.create_from(bundle)
        self.assertEqual(p.state, ProcessState.WAITING)

        # Now play it
        future = self.executor.play(p)
        p.continue_()
        self.assertEqual(future.result(timeout=1.0), {'finished': True})
Beispiel #23
0
    def test_wait_pause_continue_play(self):
        p = WaitForSignalProcess.new()

        # Play the process and wait until it is waiting
        self.executor.play(p)

        # Wait
        self.assertTrue(wait_until(p, ProcessState.WAITING, 1.))

        # Pause
        self.assertTrue(p.pause(timeout=1.))

        # Continue
        p.continue_()

        # Play
        p.play()

        self.assertTrue(p.wait(timeout=1.))
        self.assertEqual(p.state, ProcessState.STOPPED)
Beispiel #24
0
    def test_pause_all(self):
        procs = []

        # Launch a bunch of processes
        for i in range(0, 9):
            procs.append(WaitForSignalProcess.new())
            self.manager.start(procs[-1])

        self.assertTrue(wait_until(procs, ProcessState.WAITING, timeout=5))

        # Check they are all in state we expect
        for p in procs:
            self.assertTrue(p.is_playing())

        # Now try and pause them all
        self.manager.pause_all()

        # Check they are all in state we expect
        for p in procs:
            self.assertEqual(p.state, ProcessState.WAITING)
            self.assertFalse(p.is_playing())
Beispiel #25
0
    def test_status(self):
        procs = []
        for i in range(0, 20):
            p = WaitForSignalProcess.new()
            procs.append(p)
            self.controller.insert_and_play(p)

        self.assertTrue(wait_until(procs, ProcessState.WAITING, timeout=2.))

        procs_dict = status_decode(self._send_and_get())[status.PROCS_KEY]
        self.assertEqual(len(procs_dict), len(procs))
        self.assertSetEqual(set([p.pid for p in procs]),
                            set(procs_dict.keys()))

        playing = set([entry['playing'] for entry in procs_dict.itervalues()])
        self.assertSetEqual(playing, {True})

        self.assertTrue(self.controller.abort_all(timeout=5.),
                        "Couldn't abort all processes in timeout")

        self.controller.remove_all()

        response = status_decode(self._send_and_get())
        self.assertEqual(len(response[status.PROCS_KEY]), 0)
Beispiel #26
0
 def test_wait_until(self):
     p = WaitForSignalProcess.new()
     self.executor.play(p)
     self.assertTrue(wait_until(p, ProcessState.WAITING, timeout=1.))