2016-06-20 23:38:29 +03:00
|
|
|
#!/usr/bin/env python3
|
2019-06-20 02:58:25 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2016-06-07 23:01:59 +03:00
|
|
|
#
|
2019-06-20 02:58:25 +03:00
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
2016-06-07 23:01:59 +03:00
|
|
|
|
2018-10-09 23:55:16 +03:00
|
|
|
import os
|
|
|
|
import pathlib
|
|
|
|
import signal
|
|
|
|
import sys
|
2018-10-19 01:09:28 +03:00
|
|
|
import typing
|
2018-10-09 23:55:16 +03:00
|
|
|
|
|
|
|
import pexpect
|
|
|
|
from eden.cli.daemon import wait_for_shutdown
|
|
|
|
|
2016-06-20 23:38:29 +03:00
|
|
|
from .lib import edenclient, testcase
|
2018-10-09 23:55:16 +03:00
|
|
|
from .lib.find_executables import FindExe
|
2018-10-10 00:31:21 +03:00
|
|
|
from .lib.pexpect import PexpectAssertionMixin
|
2018-10-24 00:02:52 +03:00
|
|
|
from .lib.service_test_case import ServiceTestCaseBase, service_test
|
2016-06-07 23:01:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
class HealthTest(testcase.EdenTestCase):
|
2018-04-05 03:31:28 +03:00
|
|
|
def test_is_healthy(self) -> None:
|
2016-07-08 21:25:39 +03:00
|
|
|
self.assertTrue(self.eden.is_healthy())
|
|
|
|
self.eden.shutdown()
|
|
|
|
self.assertFalse(self.eden.is_healthy())
|
2016-06-07 23:01:59 +03:00
|
|
|
|
2018-04-05 03:31:28 +03:00
|
|
|
def test_disconnected_daemon_is_not_healthy(self) -> None:
|
2016-07-08 21:25:39 +03:00
|
|
|
# Create a new edenfs instance that is never started, and make sure
|
|
|
|
# it is not healthy.
|
|
|
|
with edenclient.EdenFS() as client:
|
|
|
|
self.assertFalse(client.is_healthy())
|
2018-10-09 23:55:16 +03:00
|
|
|
|
|
|
|
|
2018-12-07 02:58:09 +03:00
|
|
|
@service_test()
|
2018-12-14 00:47:39 +03:00
|
|
|
class HealthOfFakeEdenFSTest(ServiceTestCaseBase, PexpectAssertionMixin):
|
2018-11-17 06:39:20 +03:00
|
|
|
def setUp(self) -> None:
|
2018-10-09 23:55:16 +03:00
|
|
|
super().setUp()
|
2018-10-18 22:51:14 +03:00
|
|
|
self.temp_dir = pathlib.Path(self.make_temporary_directory())
|
2018-10-09 23:55:16 +03:00
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def test_healthy_daemon_is_healthy(self) -> None:
|
2018-10-24 00:02:52 +03:00
|
|
|
with self.spawn_fake_edenfs(self.temp_dir):
|
2018-10-17 04:40:06 +03:00
|
|
|
status_process = self.spawn_status([])
|
2018-10-09 23:55:16 +03:00
|
|
|
status_process.expect_exact("eden running normally")
|
|
|
|
self.assert_process_succeeds(status_process)
|
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def test_killed_daemon_is_not_running(self) -> None:
|
2018-10-24 00:02:52 +03:00
|
|
|
with self.spawn_fake_edenfs(self.temp_dir) as daemon_pid:
|
2018-10-09 23:55:16 +03:00
|
|
|
os.kill(daemon_pid, signal.SIGKILL)
|
|
|
|
wait_for_shutdown(pid=daemon_pid, timeout=5)
|
|
|
|
|
2018-10-17 04:40:06 +03:00
|
|
|
status_process = self.spawn_status([])
|
2018-10-09 23:55:16 +03:00
|
|
|
status_process.expect_exact("edenfs not running")
|
|
|
|
self.assert_process_fails(status_process, exit_code=1)
|
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def test_hanging_thrift_call_reports_daemon_is_unresponsive(self) -> None:
|
2018-10-24 00:02:52 +03:00
|
|
|
with self.spawn_fake_edenfs(self.temp_dir, ["--sleepBeforeGetPid=5"]):
|
2018-10-17 04:40:06 +03:00
|
|
|
status_process = self.spawn_status(["--timeout", "1"])
|
2018-10-09 23:55:16 +03:00
|
|
|
status_process.expect_exact(
|
|
|
|
"Eden's Thrift server does not appear to be running, but the "
|
|
|
|
"process is still alive"
|
|
|
|
)
|
|
|
|
self.assert_process_fails(status_process, exit_code=1)
|
|
|
|
|
2018-11-17 06:39:20 +03:00
|
|
|
def test_slow_thrift_call_reports_daemon_is_healthy(self) -> None:
|
2018-10-24 00:02:52 +03:00
|
|
|
with self.spawn_fake_edenfs(self.temp_dir, ["--sleepBeforeGetPid=2"]):
|
2018-10-17 04:40:06 +03:00
|
|
|
status_process = self.spawn_status(["--timeout", "10"])
|
2018-10-09 23:55:16 +03:00
|
|
|
status_process.expect_exact("eden running normally")
|
|
|
|
self.assert_process_succeeds(status_process)
|
2018-10-17 04:40:06 +03:00
|
|
|
|
|
|
|
def spawn_status(self, extra_args: typing.List[str]) -> "pexpect.spawn[str]":
|
|
|
|
return pexpect.spawn(
|
|
|
|
FindExe.EDEN_CLI,
|
2018-12-14 00:47:38 +03:00
|
|
|
["--config-dir", str(self.temp_dir)]
|
|
|
|
+ self.get_required_eden_cli_args()
|
|
|
|
+ ["status"]
|
|
|
|
+ extra_args,
|
2018-10-17 04:40:06 +03:00
|
|
|
encoding="utf-8",
|
|
|
|
logfile=sys.stderr,
|
|
|
|
)
|