예제 #1
0
    def test_heartbeat_to_end(self):
        testTask = Task()

        # test heartbeat after start
        testTask.start() 
        testTask.heartbeat(None) 
        testTask.heartbeat(None) 
        testTask.heartbeat(None) 
        testTask.end(None)
예제 #2
0
    def test_heartbeat(self):
        testTask = Task()
        # Test failure to heartbeat before start, Illegal chage out of PENDING
        cur_progress = None
        with self.assertRaises(IllegalTransitionException):
            testTask.heartbeat(cur_progress)

        # test heartbeat after start
        testTask.start() 
        testTask.heartbeat(cur_progress) 
         
        testTask.end(None)
        with self.assertRaises(IllegalTransitionException):
            testTask.heartbeat(cur_progress) 
예제 #3
0
    def test_events(self):
        '''Test event delivery.'''

        eventqueue = conveyor.event.geteventqueue()
        task = Task()

        startcallback = conveyor.event.Callback()
        task.startevent.attach(startcallback)

        heartbeatcallback = conveyor.event.Callback()
        task.heartbeatevent.attach(heartbeatcallback)

        endcallback = conveyor.event.Callback()
        task.endevent.attach(endcallback)

        failcallback = conveyor.event.Callback()
        task.failevent.attach(failcallback)

        cancelcallback = conveyor.event.Callback()
        task.cancelevent.attach(cancelcallback)

        runningcallback = conveyor.event.Callback()
        task.runningevent.attach(runningcallback)

        stoppedcallback = conveyor.event.Callback()
        task.stoppedevent.attach(stoppedcallback)

        callbacks = (
            startcallback, heartbeatcallback, endcallback, failcallback,
            cancelcallback, runningcallback, stoppedcallback)

        self.assertFalse(startcallback.delivered)
        self.assertFalse(heartbeatcallback.delivered)
        self.assertFalse(endcallback.delivered)
        self.assertFalse(failcallback.delivered)
        self.assertFalse(cancelcallback.delivered)
        self.assertFalse(runningcallback.delivered)
        self.assertFalse(stoppedcallback.delivered)

        task.start()
        self._runeventqueue(eventqueue)
        self.assertEqual(TaskState.RUNNING, task.state)
        self.assertTrue(startcallback.delivered)
        self.assertFalse(heartbeatcallback.delivered)
        self.assertFalse(endcallback.delivered)
        self.assertFalse(failcallback.delivered)
        self.assertFalse(cancelcallback.delivered)
        self.assertTrue(runningcallback.delivered)
        self.assertFalse(stoppedcallback.delivered)

        self._reset(callbacks)
        task.progress = None
        task.result = None
        task.failure = None
        task.heartbeat('progress')
        self._runeventqueue(eventqueue)
        self.assertEqual(TaskState.RUNNING, task.state)
        self.assertEqual('progress', task.progress)
        self.assertIsNone(task.result)
        self.assertIsNone(task.failure)
        self.assertFalse(startcallback.delivered)
        self.assertTrue(heartbeatcallback.delivered)
        self.assertFalse(endcallback.delivered)
        self.assertFalse(failcallback.delivered)
        self.assertFalse(cancelcallback.delivered)
        self.assertFalse(runningcallback.delivered)
        self.assertFalse(stoppedcallback.delivered)

        self._reset(callbacks)
        task.progress = None
        task.result = None
        task.failure = None
        task.end('result')
        self._runeventqueue(eventqueue)
        self.assertEqual(TaskState.STOPPED, task.state)
        self.assertIsNone(task.progress)
        self.assertEqual('result', task.result)
        self.assertIsNone(task.failure)
        self.assertFalse(startcallback.delivered)
        self.assertFalse(heartbeatcallback.delivered)
        self.assertTrue(endcallback.delivered)
        self.assertFalse(failcallback.delivered)
        self.assertFalse(cancelcallback.delivered)
        self.assertFalse(runningcallback.delivered)
        self.assertTrue(stoppedcallback.delivered)

        self._reset(callbacks)
        task.progress = None
        task.result = None
        task.failure = None
        task.state = TaskState.RUNNING
        task.fail('failure')
        self._runeventqueue(eventqueue)
        self.assertEqual(TaskState.STOPPED, task.state)
        self.assertIsNone(task.progress)
        self.assertIsNone(task.result)
        self.assertEqual('failure', task.failure)
        self.assertFalse(startcallback.delivered)
        self.assertFalse(heartbeatcallback.delivered)
        self.assertFalse(endcallback.delivered)
        self.assertTrue(failcallback.delivered)
        self.assertFalse(cancelcallback.delivered)
        self.assertFalse(runningcallback.delivered)
        self.assertTrue(stoppedcallback.delivered)

        self._reset(callbacks)
        task.progress = None
        task.result = None
        task.failure = None
        task.state = TaskState.PENDING
        task.cancel()
        self._runeventqueue(eventqueue)
        self.assertEqual(TaskState.STOPPED, task.state)
        self.assertIsNone(task.progress)
        self.assertIsNone(task.result)
        self.assertIsNone(task.failure)
        self.assertFalse(startcallback.delivered)
        self.assertFalse(heartbeatcallback.delivered)
        self.assertFalse(endcallback.delivered)
        self.assertFalse(failcallback.delivered)
        self.assertTrue(cancelcallback.delivered)
        self.assertFalse(runningcallback.delivered)
        self.assertTrue(stoppedcallback.delivered)

        self._reset(callbacks)
        task.progress = None
        task.result = None
        task.failure = None
        task.state = TaskState.RUNNING
        task.cancel()
        self._runeventqueue(eventqueue)
        self.assertEqual(TaskState.STOPPED, task.state)
        self.assertIsNone(task.progress)
        self.assertIsNone(task.result)
        self.assertIsNone(task.failure)
        self.assertFalse(startcallback.delivered)
        self.assertFalse(heartbeatcallback.delivered)
        self.assertFalse(endcallback.delivered)
        self.assertFalse(failcallback.delivered)
        self.assertTrue(cancelcallback.delivered)
        self.assertFalse(runningcallback.delivered)
        self.assertTrue(stoppedcallback.delivered)