Example #1
0
    def complete_before_timeout():
        """Complete opertion before timeout occurs."""
        watchdog.start()
        with watchdog.timeout(10, "complete_before_timeout"):
            time.sleep(0.1)

        sys.exit(ExitCode.OK)
Example #2
0
    def timeout_before_complete():
        """Timeout before operation completes."""
        watchdog.start()
        with watchdog.timeout(1, "timeout_before_complete"):
            time.sleep(2)

        sys.exit(ExitCode.NOT_RESTARTED)
Example #3
0
    def start_then_exit():
        """Start watchdog thread then exit."""
        watchdog.start()

        # Verify that watchdog did start.
        for thread in threading.enumerate():
            if thread.name == 'watchdog':
                sys.exit(ExitCode.OK)

        sys.exit(ExitCode.WATCHDOG_NOT_RUNNING)
    def setupWatchdog(self):
        if self.options.blockingTimeout > 0:
            self.blockingPlugins = watchdog.get_timeout_entries(
                timeout_file=varPath('{}.blocked'.format(self.collectorName)))

            log.info("plugins disabled by watchdog: %r",
                     list(self.blockingPlugins))

            log.info("starting watchdog with %.1fs timeout",
                     self.options.blockingTimeout)

            watchdog.start()
        else:
            self.blockingPlugins = set()
    def setupWatchdog(self):
        if self.options.blockingTimeout > 0:
            self.blockingPlugins = watchdog.get_timeout_entries(
                timeout_file=varPath('{}.blocked'.format(self.collectorName)))

            log.info(
                "plugins disabled by watchdog: %r",
                list(self.blockingPlugins))

            log.info(
                "starting watchdog with %.1fs timeout",
                self.options.blockingTimeout)

            watchdog.start()
        else:
            self.blockingPlugins = set()
    def timeout_file():
        """Validate operation timeout is recorded and we're restarted."""
        timeout_file = os.path.join(tempfile.gettempdir(),
                                    'test_watchdog.timeouts')

        entries = watchdog.get_timeout_entries(timeout_file=timeout_file)
        if os.path.isfile(timeout_file):
            os.unlink(timeout_file)

        if 'timeout_file' in entries:
            sys.exit(ExitCode.OK)
        else:
            watchdog.start()
            with watchdog.timeout(1, 'timeout_file'):
                time.sleep(2)

            sys.exit(ExitCode.NOT_RESTARTED)
    def timeout_file():
        """Validate operation timeout is recorded and we're restarted."""
        timeout_file = os.path.join(
            tempfile.gettempdir(),
            'test_watchdog.timeouts')

        entries = watchdog.get_timeout_entries(timeout_file=timeout_file)
        if os.path.isfile(timeout_file):
            os.unlink(timeout_file)

        if 'timeout_file' in entries:
            sys.exit(ExitCode.OK)
        else:
            watchdog.start()
            with watchdog.timeout(1, 'timeout_file'):
                time.sleep(2)

            sys.exit(ExitCode.NOT_RESTARTED)
Example #8
0
 def start_then_ctrlc():
     """Start the watchdog thread then simulate a CTRL-C."""
     watchdog.start()
     raise KeyboardInterrupt
     sys.exit(ExitCode.OK)