Ejemplo n.º 1
0
    def test__run_event_hooks(self):
        """ registration.run_event_hooks: runs the task event methods for
            registered event plugins.
            """
        plugin = MockPlugin()

        # fake event registration for plugin
        for event in ('task_start', 'task_run', 'task_end'):
            registration._event_hooks[event] = [(plugin.name, lambda: plugin)]

            # run event hooks for plugin, check if it works
            registration.run_event_hooks(event, MockTask())

            if event == 'task_start':
                self.assertTrue(hasattr(plugin, 'test__task_started'))

            elif event == 'task_run':
                self.assertTrue(hasattr(plugin, 'test__task_ran'))
                self.assertEqual(plugin.test__task_ran, 1)

            elif event == 'task_end':
                self.assertTrue(hasattr(plugin, 'test__task_ended'))
Ejemplo n.º 2
0
    def _run_events(self, shutdown=False):
        """ Runs event hooks for registered event plugins.

            `shutdown`
                Set to ``True`` to run task_end events;
                otherwise, run task_run events.
            """

        # run task_start events, if not ran already
        if not self._ran_taskstart:
            self._ran_taskstart = True
            registration.run_event_hooks('task_start', self._task)

        # run events
        event = 'task_end' if shutdown else 'task_run'
        registration.run_event_hooks(event, self._task)

        # reclaim any subprocesses plugins may have forked
        try:
            os.waitpid(-1, os.P_NOWAIT)
        except OSError:
            pass
Ejemplo n.º 3
0
    def test__run_event_hooks(self):
        """ registration.run_event_hooks: runs the task event methods for
            registered event plugins.
            """
        plugin = MockPlugin()

        # fake event registration for plugin
        for event in ('task_start', 'task_run', 'task_end'):
            registration._event_hooks[event] = [
                (plugin.name, lambda: plugin)
            ]

            # run event hooks for plugin, check if it works
            registration.run_event_hooks(event, MockTask())

            if event == 'task_start':
                self.assertTrue(hasattr(plugin, 'test__task_started'))

            elif event == 'task_run':
                self.assertTrue(hasattr(plugin, 'test__task_ran'))
                self.assertEqual(plugin.test__task_ran, 1)

            elif event == 'task_end':
                self.assertTrue(hasattr(plugin, 'test__task_ended'))