예제 #1
0
파일: system.py 프로젝트: rl1987/stem
    def test_daemon_task_when_successful(self):
        """
    Checks a simple, successfully DaemonTask that simply echos a value.
    """

        task = DaemonTask(lambda arg: arg, ('hello world', ))

        self.assertEqual(None, task.result)
        self.assertEqual(State.PENDING, task.status)

        task.run()
        self.assertEqual('hello world', task.join())
        self.assertEqual(State.DONE, task.status)
        self.assertTrue(0 < task.runtime < 1.0)
예제 #2
0
파일: system.py 프로젝트: rl1987/stem
    def test_daemon_task_on_failure(self):
        """
    Checks DaemonTask when an exception is raised.
    """
        def _test_task(arg):
            raise RuntimeError(arg)

        task = DaemonTask(_test_task, ('hello world', ))

        self.assertEqual(None, task.result)
        self.assertEqual(State.PENDING, task.status)

        task.run()
        self.assertRaisesRegexp(RuntimeError, 'hello world', task.join)
        self.assertEqual(State.FAILED, task.status)
        self.assertTrue(0 < task.runtime < 1.0)