Exemplo n.º 1
0
    def test_kill(self):
        proc = utils.DummyProcess()

        proc.kill('Farewell!')
        self.assertTrue(proc.killed())
        self.assertEqual(proc.killed_msg(), 'Farewell!')
        self.assertEqual(proc.state, ProcessState.KILLED)
Exemplo n.º 2
0
    def test_spec(self):
        """
        Check that the references to specs are doing the right thing...
        """
        proc = utils.DummyProcess()
        self.assertIsNot(utils.DummyProcess.spec(), Process.spec())
        self.assertIs(proc.spec(), utils.DummyProcess.spec())

        class Proc(utils.DummyProcess):
            pass

        self.assertIsNot(Proc.spec(), Process.spec())
        self.assertIsNot(Proc.spec(), utils.DummyProcess.spec())
        p = Proc()
        self.assertIs(p.spec(), Proc.spec())
Exemplo n.º 3
0
async def test_continue():
    persister = plumpy.InMemoryPersister()
    load_context = plumpy.LoadSaveContext()
    launcher = plumpy.ProcessLauncher(persister=persister,
                                      load_context=load_context)

    process = utils.DummyProcess()
    pid = process.pid
    persister.save_checkpoint(process)
    del process
    process = None

    result = await launcher._continue(
        None,
        **plumpy.create_continue_body(pid)[process_comms.TASK_ARGS])
    assert result == utils.DummyProcess.EXPECTED_OUTPUTS
Exemplo n.º 4
0
    def test_broadcast(self):
        communicator = kiwipy.LocalCommunicator()

        messages = []

        def on_broadcast_receive(_comm, body, sender, subject, correlation_id):
            messages.append({'body': body, 'subject': subject, 'sender': sender, 'correlation_id': correlation_id})

        communicator.add_broadcast_subscriber(on_broadcast_receive)
        proc = utils.DummyProcess(communicator=communicator)
        proc.execute()

        expected_subjects = []
        for i, state in enumerate(utils.DummyProcess.EXPECTED_STATE_SEQUENCE):
            from_state = utils.DummyProcess.EXPECTED_STATE_SEQUENCE[i - 1].value if i != 0 else None
            expected_subjects.append('state_changed.{}.{}'.format(from_state, state.value))

        for i, message in enumerate(messages):
            self.assertEqual(message['subject'], expected_subjects[i])
Exemplo n.º 5
0
 def test_killed(self):
     proc = utils.DummyProcess()
     proc.kill()
     self.assertEqual(proc.state, plumpy.ProcessState.KILLED)
     self._check_round_trip(proc)
Exemplo n.º 6
0
 def test_created_bundle(self):
     """
     Check that the bundle after just creating a process is as we expect
     """
     self._check_round_trip(utils.DummyProcess())
Exemplo n.º 7
0
 def test_execute_twice(self):
     """Test a process that is executed once finished raises a ClosedError"""
     proc = utils.DummyProcess()
     proc.execute()
     with self.assertRaises(plumpy.ClosedError):
         proc.execute()
Exemplo n.º 8
0
 def test_run_done(self):
     proc = utils.DummyProcess()
     proc.execute()
     self.assertTrue(proc.done())