def test_watchdog_restart(self):
        """
        WatchDog restarts processes with the original arguments.
        """
        # Create a WatchDog with a mock process
        process = MockProcess("MyConfig", "MyHostname", foo="bar")
        process_watchdog = ProcessWatchDog("MyProcess", process)  # noqa pylint: disable=E0602

        # Restart the process
        process_watchdog.restart()
        new_process = process_watchdog._process

        # A new process was created with the same attributes
        self.assertNotEquals(process, new_process)
        self.assertEquals(new_process.config, "MyConfig")
        self.assertEquals(new_process.hostname, "MyHostname")
        self.assertEquals(new_process._foo, "bar")
Beispiel #2
0
    def test_watchdog_restart(self):
        """
        WatchDog restarts processes with the original arguments.
        """
        # Create a WatchDog with a mock process
        process = MockProcess("MyConfig", "MyHostname", foo="bar")
        process_watchdog = ProcessWatchDog("MyProcess", process)  # noqa pylint: disable=E0602

        # Restart the process
        process_watchdog.restart()
        new_process = process_watchdog._process

        # A new process was created with the same attributes
        self.assertNotEquals(process, new_process)
        self.assertEquals(new_process.config, "MyConfig")
        self.assertEquals(new_process.hostname, "MyHostname")
        self.assertEquals(new_process._foo, "bar")
    def test_watchdog_max_restarts(self):
        """
        WatchDog does not exceed a maximum number of restarts per timeframe.
        """
        # Limit the restart timeframe for test purpose
        ProcessWatchDog._RESTART_TIMEFRAME = 1  # noqa pylint: disable=E0602

        # Create a WatchDog with a mock process
        process = MockProcess("MyConfig", "MyHostname", foo="bar")
        process_watchdog = ProcessWatchDog("MyProcess", process, max_restarts=2)  # noqa pylint: disable=E0602

        # Can restart 2 times
        for x in xrange(0, 2):
            self.assertTrue(process_watchdog._can_restart())
            process_watchdog.restart()

        # Not 3
        self.assertFalse(process_watchdog._can_restart())

        # Can restart after the timeframe is expired
        time.sleep(1)
        self.assertTrue(process_watchdog._can_restart())
Beispiel #4
0
    def test_watchdog_max_restarts(self):
        """
        WatchDog does not exceed a maximum number of restarts per timeframe.
        """
        # Limit the restart timeframe for test purpose
        ProcessWatchDog._RESTART_TIMEFRAME = 1  # noqa pylint: disable=E0602

        # Create a WatchDog with a mock process
        process = MockProcess("MyConfig", "MyHostname", foo="bar")
        process_watchdog = ProcessWatchDog("MyProcess", process, max_restarts=2)  # noqa pylint: disable=E0602

        # Can restart 2 times
        for x in xrange(0, 2):
            self.assertTrue(process_watchdog._can_restart())
            process_watchdog.restart()

        # Not 3
        self.assertFalse(process_watchdog._can_restart())

        # Can restart after the timeframe is expired
        time.sleep(1)
        self.assertTrue(process_watchdog._can_restart())