def test_measure_processing3(self):
        """ Test the processing of a measure failing the tests.

        Not terribly interesting just increase coverage but does not allow
        any true check.
        """
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        measure = self._create_measure(plugin)
        measure.root_task.default_path = ''

        core = self.workbench.get_plugin('enaml.workbench.core')
        cmd = 'hqc_meas.dependencies.collect_dependencies'
        _, b_deps = core.invoke_command(cmd, {'obj': measure.root_task,
                                              'dependencies': ['build']})

        engine = ProcessEngine(workbench=self.workbench)
        engine.prepare_to_run('test', measure.root_task,
                              measure.collect_entries_to_observe(), b_deps)

        # Check engine state.
        assert_true(engine._temp)
        assert_false(engine._meas_stop.is_set())
        assert_false(engine._stop.is_set())
        assert_false(engine._force_stop.is_set())
        assert_true(engine._process and engine._process.daemon)
        assert_true(engine._pipe)
        assert_true(engine._monitor_thread and engine._monitor_thread.daemon)
        assert_true(engine._log_thread and engine._log_thread.daemon)

        # Start the measure.
        engine.run()
        sleep(2)

        engine.exit()
    def test_measure_processing3(self):
        """ Test the processing of a measure failing the tests.

        Not terribly interesting just increase coverage but does not allow
        any true check.
        """
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        measure = self._create_measure(plugin)
        measure.root_task.default_path = ''

        core = self.workbench.get_plugin('enaml.workbench.core')
        cmd = 'hqc_meas.dependencies.collect_dependencies'
        _, b_deps = core.invoke_command(cmd, {
            'obj': measure.root_task,
            'dependencies': ['build']
        })

        engine = ProcessEngine(workbench=self.workbench)
        engine.prepare_to_run('test', measure.root_task,
                              measure.collect_entries_to_observe(), b_deps)

        # Check engine state.
        assert_true(engine._temp)
        assert_false(engine._meas_stop.is_set())
        assert_false(engine._stop.is_set())
        assert_false(engine._force_stop.is_set())
        assert_true(engine._process and engine._process.daemon)
        assert_true(engine._pipe)
        assert_true(engine._monitor_thread and engine._monitor_thread.daemon)
        assert_true(engine._log_thread and engine._log_thread.daemon)

        # Start the measure.
        engine.run()
        sleep(2)

        engine.exit()
    def test_measure_processing2(self):
        """ Test the processing of a single measure (not using the plugin).


        Test the communication with the monitors (skip plugin tests) and with
        the log.

        """
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        measure = self._create_measure(plugin)
        monitor = measure.monitors.values()[0]

        core = self.workbench.get_plugin('enaml.workbench.core')
        cmd = 'hqc_meas.dependencies.collect_dependencies'
        _, b_deps = core.invoke_command(cmd, {
            'obj': measure.root_task,
            'dependencies': ['build']
        })

        engine = ProcessEngine(workbench=self.workbench)
        engine.observe('news', measure.monitors.values()[0].process_news)

        engine.prepare_to_run('test', measure.root_task,
                              measure.collect_entries_to_observe(), b_deps)

        monitor.start(None)

        # Check engine state.
        assert_true(engine._temp)
        assert_false(engine._meas_stop.is_set())
        assert_false(engine._stop.is_set())
        assert_false(engine._force_stop.is_set())
        assert_true(engine._process and engine._process.daemon)
        assert_true(engine._pipe)
        assert_true(engine._monitor_thread and engine._monitor_thread.daemon)
        assert_true(engine._log_thread and engine._log_thread.daemon)

        # Start the measure.
        engine.run()

        assert_true(engine.active)
        i = 0
        while not engine._processing.is_set():
            sleep(0.1)
            i += 1
            if i > 100:
                raise Exception('Engine took too long to start.')

        while i != 0 and engine._processing.is_set():
            sleep(0.1)
            i += 1
            if i > 200:
                raise Exception('Task took too long to complete.')

        engine.exit()

        while engine.active:
            sleep(0.1)
            i += 1
            if i > 300:
                raise Exception('Engine took too long to exit.')

        # Check the monitor and log received the notifications.
        assert_in('root/print_message', monitor.engine_news)
        assert_equal(monitor.engine_news['root/print_message'], 'test')
    def test_measure_processing2(self):
        """ Test the processing of a single measure (not using the plugin).


        Test the communication with the monitors (skip plugin tests) and with
        the log.

        """
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        measure = self._create_measure(plugin)
        monitor = measure.monitors.values()[0]

        core = self.workbench.get_plugin('enaml.workbench.core')
        cmd = 'hqc_meas.dependencies.collect_dependencies'
        _, b_deps = core.invoke_command(cmd, {'obj': measure.root_task,
                                              'dependencies': ['build']})

        engine = ProcessEngine(workbench=self.workbench)
        engine.observe('news', measure.monitors.values()[0].process_news)

        engine.prepare_to_run('test', measure.root_task,
                              measure.collect_entries_to_observe(), b_deps)

        monitor.start(None)

        # Check engine state.
        assert_true(engine._temp)
        assert_false(engine._meas_stop.is_set())
        assert_false(engine._stop.is_set())
        assert_false(engine._force_stop.is_set())
        assert_true(engine._process and engine._process.daemon)
        assert_true(engine._pipe)
        assert_true(engine._monitor_thread and engine._monitor_thread.daemon)
        assert_true(engine._log_thread and engine._log_thread.daemon)

        # Start the measure.
        engine.run()

        assert_true(engine.active)
        i = 0
        while not engine._processing.is_set():
            sleep(0.1)
            i += 1
            if i > 100:
                raise Exception('Engine took too long to start.')

        while i != 0 and engine._processing.is_set():
            sleep(0.1)
            i += 1
            if i > 200:
                raise Exception('Task took too long to complete.')

        engine.exit()

        while engine.active:
            sleep(0.1)
            i += 1
            if i > 300:
                raise Exception('Engine took too long to exit.')

        # Check the monitor and log received the notifications.
        assert_in('root/print_message', monitor.engine_news)
        assert_equal(monitor.engine_news['root/print_message'], 'test')