Esempio n. 1
0
    def execute(self):
        """Run the task."""

        # Ensure that the timeout_maximum is higher than the timeout default.
        if (self.get_options().timeout_maximum is not None
                and self.get_options().timeout_default is not None
                and self.get_options().timeout_maximum <
                self.get_options().timeout_default):
            message = "Error: timeout-default: {} exceeds timeout-maximum: {}".format(
                self.get_options().timeout_maximum,
                self.get_options().timeout_default)
            self.context.log.error(message)
            raise TestFailedTaskError(message)

        if not self.get_options().skip:
            test_targets = self._get_test_targets()
            all_targets = self._get_targets()
            for target in test_targets:
                self._validate_target(target)

            timeout = self._timeout_for_targets(test_targets)

            try:
                with Timeout(timeout,
                             abort_handler=self._timeout_abort_handler):
                    self._execute(all_targets)
            except TimeoutReached as e:
                raise TestFailedTaskError(str(e), failed_targets=test_targets)
Esempio n. 2
0
    def test_timeout_zero(self):
        with Timeout(0,
                     threading_timer=self._make_fake_timer,
                     abort_handler=self._abort_handler):
            self._move_clock_forward(3)

        self.assertFalse(self._aborted)
Esempio n. 3
0
    def test_timeout_success(self):
        with Timeout(2,
                     threading_timer=self._make_fake_timer,
                     abort_handler=self._abort_handler):
            self._move_clock_forward(1)

        self.assertFalse(self._aborted)
Esempio n. 4
0
    def test_timeout_failure(self):
        with self.assertRaises(TimeoutReached):
            with Timeout(2,
                         threading_timer=self._make_fake_timer,
                         abort_handler=self._abort_handler):
                self._move_clock_forward(3)

        self.assertTrue(self._aborted)
Esempio n. 5
0
    def execute(self):
        """Run the task."""

        if not self.get_options().skip:
            test_targets = self._get_test_targets()
            all_targets = self._get_targets()
            for target in test_targets:
                self._validate_target(target)

            timeout = self._timeout_for_targets(test_targets)

            try:
                with Timeout(timeout,
                             abort_handler=self._timeout_abort_handler):
                    self._execute(all_targets)
            except TimeoutReached as e:
                raise TestFailedTaskError(str(e), failed_targets=test_targets)
    def _spawn_and_wait(self, *args, **kwargs):
        """Spawn the actual test runner process, and wait for it to complete."""

        test_targets = self._get_test_targets()
        timeout = self._timeout_for_targets(test_targets)

        process_handler = self._spawn(*args, **kwargs)

        # TODO(sbrenn): We use process_handler.kill here because we want to aggressively terminate the
        # process. It may make sense in the future to do a multi-stage approach
        # where first we do process_handler.terminate to let it die gracefully, and
        # then do process_handler.kill if that doesn't work. It will probably require
        # adding poll() support to ProcessHandler.
        try:
            with Timeout(timeout, abort_handler=process_handler.kill):
                return process_handler.wait()
        except TimeoutReached as e:
            raise TestFailedTaskError(str(e), failed_targets=test_targets)
Esempio n. 7
0
    def _spawn_and_wait(self, *args, **kwargs):
        """Spawn the actual test runner process, and wait for it to complete."""

        test_targets = self._get_test_targets_for_spawn()
        timeout = self._timeout_for_targets(test_targets)

        process_handler = self._spawn(*args, **kwargs)

        def _graceful_terminate(handler, wait_time):
            """
      Returns a function which attempts to terminate the process gracefully.

      If terminate doesn't work after wait_time seconds, do a kill.
      """
            def terminator():
                handler.terminate()

                def kill_if_not_terminated():
                    if handler.poll() is None:
                        # We can't use the context logger because it might not exist.
                        import logging
                        logger = logging.getLogger(__name__)
                        logger.warn(
                            'Timed out test did not terminate gracefully after {} seconds, killing...'
                            .format(wait_time))
                        handler.kill()

                timer = Timer(wait_time, kill_if_not_terminated)
                timer.start()

            return terminator

        try:
            with Timeout(timeout,
                         threading_timer=Timer,
                         abort_handler=_graceful_terminate(
                             process_handler,
                             self.get_options().timeout_terminate_wait)):
                return process_handler.wait()
        except TimeoutReached as e:
            raise ErrorWhileTesting(str(e), failed_targets=test_targets)