2015-03-02 04:08:05 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Copyright (c) 2014, Facebook, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This source code is licensed under the BSD-style license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
# osquery-specific testing utils
|
|
|
|
import test_base
|
|
|
|
|
|
|
|
class WatchdogTests(test_base.ProcessGenerator, unittest.TestCase):
|
|
|
|
def test_1_daemon_without_watchdog(self):
|
2015-03-14 01:18:18 +00:00
|
|
|
daemon = self._run_daemon({
|
|
|
|
"disable_watchdog": True,
|
|
|
|
"disable_extensions": True,
|
|
|
|
})
|
2015-03-02 04:08:05 +00:00
|
|
|
self.assertTrue(daemon.isAlive())
|
|
|
|
daemon.kill()
|
|
|
|
|
|
|
|
def test_2_daemon_with_watchdog(self):
|
2015-03-14 01:18:18 +00:00
|
|
|
daemon = self._run_daemon({
|
|
|
|
"disable_watchdog": False,
|
|
|
|
})
|
2015-03-02 04:08:05 +00:00
|
|
|
self.assertTrue(daemon.isAlive())
|
|
|
|
|
|
|
|
# Check that the daemon spawned a child process
|
|
|
|
children = daemon.getChildren()
|
|
|
|
self.assertTrue(len(children) > 0)
|
|
|
|
daemon.kill()
|
|
|
|
|
|
|
|
# This will take a few moments to make sure the client process
|
|
|
|
# dies when the watcher goes away
|
|
|
|
self.assertTrue(daemon.isDead(children[0].pid))
|
|
|
|
|
2015-03-04 01:10:40 +00:00
|
|
|
def test_3_catastrophic_worker_failure(self):
|
2015-03-09 06:05:09 +00:00
|
|
|
### Seems to fail often, disable test
|
2015-03-14 01:18:18 +00:00
|
|
|
daemon = self._run_daemon({
|
|
|
|
"disable_watchdog": False,
|
|
|
|
"database_path": "/tmp/this/does/not/exists.db",
|
|
|
|
})
|
2015-03-04 01:10:40 +00:00
|
|
|
daemon.isAlive(5)
|
|
|
|
self.assertTrue(daemon.isDead(daemon.pid))
|
|
|
|
daemon.kill()
|
2015-03-02 04:08:05 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_base.Tester().run()
|