Exemple #1
0
    def test_play_all(self):
        """Test pausing all processes on a communicator"""
        procs = []
        for _ in range(10):
            proc = test_utils.WaitForSignalProcess(communicator=self.communicator)
            procs.append(proc)
            proc.pause('hold tight')

        self.assertTrue(all([proc.paused for proc in procs]))
        self.process_controller.play_all()
        # Wait until they are all paused
        yield utils.wait_util(lambda: all([not proc.paused for proc in procs]))
Exemple #2
0
    def test_play(self):
        proc = test_utils.WaitForSignalProcess(communicator=self.communicator)
        self.assertTrue(proc.pause())

        # Send a play message
        play_future = self.process_controller.pause_process(proc.pid)
        # Allow the process to respond to the request
        result = yield play_future

        # Check that all is as we expect
        self.assertTrue(result)
        self.assertEqual(proc.state, plumpy.ProcessState.CREATED)
    def test_kill_all(self):
        """Test pausing all processes on a communicator"""
        procs = []
        for _ in range(10):
            procs.append(
                test_utils.WaitForSignalProcess(
                    communicator=self.communicator))

        self.process_controller.kill_all('bang bang, I shot you down')
        yield utils.wait_util(lambda: all([proc.killed() for proc in procs]))
        self.assertTrue(
            all([proc.state == plumpy.ProcessState.KILLED for proc in procs]))
Exemple #4
0
    def test_play(self):
        proc = test_utils.WaitForSignalProcess(communicator=self.communicator)
        # Run the process in the background
        proc.loop().add_callback(proc.step_until_terminated)
        self.assertTrue(proc.pause())

        # Send a play message
        result = yield self.process_controller.play_process(proc.pid)

        # Check that all is as we expect
        self.assertTrue(result)
        self.assertEqual(proc.state, plumpy.ProcessState.WAITING)
    def test_kill(self):
        proc = test_utils.WaitForSignalProcess(communicator=self.communicator)

        # Send a kill message
        kill_future = yield self.process_controller.kill_process(proc.pid)
        # Allow the process to respond to the request
        result = yield kill_future

        # Check the outcome
        self.assertTrue(result)
        # Occasionally fail
        self.assertEqual(proc.state, plumpy.ProcessState.KILLED)
Exemple #6
0
    def test_wait_continue(self):
        proc = test_utils.WaitForSignalProcess()
        # Wait - Execute the process and wait until it is waiting

        listener = plumpy.ProcessListener()
        listener.on_process_waiting = lambda proc: proc.resume()

        proc.add_process_listener(listener)
        self.loop.run_sync(proc.step_until_terminated)

        # Check it's done
        self.assertTrue(proc.done())
        self.assertEqual(proc.state, ProcessState.FINISHED)
Exemple #7
0
    def test_wait_save_continue(self):
        """ Test that process saved while in WAITING state restarts correctly when loaded """
        proc = test_utils.WaitForSignalProcess()
        self.loop.add_callback(proc.step_until_terminated)

        yield test_utils.run_until_waiting(proc)

        saved_state = plumpy.Bundle(proc)

        # Run the process to the end
        proc.resume()
        result1 = yield proc.future()

        # Load from saved state and run again
        proc2 = saved_state.unbundle(plumpy.LoadSaveContext(loop=self.loop))
        self.loop.add_callback(proc2.step_until_terminated)
        proc2.resume()
        result2 = yield proc2.future()

        # Check results match
        self.assertEqual(result1, result2)
Exemple #8
0
    def test_pause_play_status_messaging(self):
        """
        Test the setting of a processes' status through pause and play works correctly.

        Any process can have its status set to a given message. When pausing, a pause message can be set for the
        status, which should store the current status, which should be restored, once the process is played again.
        """
        PLAY_STATUS = 'process was played by Hans Klok'
        PAUSE_STATUS = 'process was paused by Evel Knievel'

        proc = test_utils.WaitForSignalProcess()
        proc.set_status(PLAY_STATUS)
        loop = self.loop
        loop.add_callback(proc.step_until_terminated)

        @gen.coroutine
        def async_test():
            yield test_utils.run_until_waiting(proc)
            self.assertEqual(proc.state, ProcessState.WAITING)

            result = yield proc.pause(PAUSE_STATUS)
            self.assertTrue(result)
            self.assertTrue(proc.paused)
            self.assertEqual(proc.status, PAUSE_STATUS)

            result = proc.play()
            self.assertEqual(proc.status, PLAY_STATUS)
            self.assertIsNone(proc._pre_paused_status)

            proc.resume()
            # Wait until the process is terminated
            yield proc.future()

            # Check it's done
            self.assertTrue(proc.done())
            self.assertEqual(proc.state, ProcessState.FINISHED)

        loop.run_sync(async_test)
Exemple #9
0
    def test_kill_when_paused(self):
        proc = test_utils.WaitForSignalProcess()

        @gen.coroutine
        def run_async(proc):
            yield test_utils.run_until_waiting(proc)

            saved_state = plumpy.Bundle(proc)

            result = yield proc.pause()
            self.assertTrue(result)
            self.assertTrue(proc.paused)

            # Kill the process
            proc.kill()

            with self.assertRaises(plumpy.KilledError):
                result = yield proc.future()

            self.assertEqual(proc.state, ProcessState.KILLED)

        self.loop.add_callback(proc.step_until_terminated)
        self.loop.run_sync(lambda: run_async(proc))