mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
8f5affad76
Summary: spawn_status already sets the log file to stderr. Setting it again is redundant. Delete the dead store. Reviewed By: simpkins Differential Revision: D10434381 fbshipit-source-id: d0e4cfe9dc63ae80fc8a9e621b02a3ac31f8244a
84 lines
3.1 KiB
Python
84 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Copyright (c) 2016-present, 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.
|
|
|
|
import os
|
|
import pathlib
|
|
import signal
|
|
import sys
|
|
import typing
|
|
|
|
import pexpect
|
|
from eden.cli.daemon import wait_for_shutdown
|
|
|
|
from .lib import edenclient, testcase
|
|
from .lib.find_executables import FindExe
|
|
from .lib.pexpect import PexpectAssertionMixin
|
|
from .lib.service_test_case import ServiceTestCaseBase, service_test
|
|
from .lib.temporary_directory import TemporaryDirectoryMixin
|
|
|
|
|
|
class HealthTest(testcase.EdenTestCase):
|
|
def test_is_healthy(self) -> None:
|
|
self.assertTrue(self.eden.is_healthy())
|
|
self.eden.shutdown()
|
|
self.assertFalse(self.eden.is_healthy())
|
|
|
|
def test_disconnected_daemon_is_not_healthy(self) -> None:
|
|
# 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())
|
|
|
|
|
|
@service_test
|
|
class HealthOfFakeEdenFSTest(
|
|
ServiceTestCaseBase, PexpectAssertionMixin, TemporaryDirectoryMixin
|
|
):
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.temp_dir = pathlib.Path(self.make_temporary_directory())
|
|
|
|
def test_healthy_daemon_is_healthy(self):
|
|
with self.spawn_fake_edenfs(self.temp_dir):
|
|
status_process = self.spawn_status([])
|
|
status_process.expect_exact("eden running normally")
|
|
self.assert_process_succeeds(status_process)
|
|
|
|
def test_killed_daemon_is_not_running(self):
|
|
with self.spawn_fake_edenfs(self.temp_dir) as daemon_pid:
|
|
os.kill(daemon_pid, signal.SIGKILL)
|
|
wait_for_shutdown(pid=daemon_pid, timeout=5)
|
|
|
|
status_process = self.spawn_status([])
|
|
status_process.expect_exact("edenfs not running")
|
|
self.assert_process_fails(status_process, exit_code=1)
|
|
|
|
def test_hanging_thrift_call_reports_daemon_is_unresponsive(self):
|
|
with self.spawn_fake_edenfs(self.temp_dir, ["--sleepBeforeGetPid=5"]):
|
|
status_process = self.spawn_status(["--timeout", "1"])
|
|
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)
|
|
|
|
def test_slow_thrift_call_reports_daemon_is_healthy(self):
|
|
with self.spawn_fake_edenfs(self.temp_dir, ["--sleepBeforeGetPid=2"]):
|
|
status_process = self.spawn_status(["--timeout", "10"])
|
|
status_process.expect_exact("eden running normally")
|
|
self.assert_process_succeeds(status_process)
|
|
|
|
def spawn_status(self, extra_args: typing.List[str]) -> "pexpect.spawn[str]":
|
|
return pexpect.spawn(
|
|
FindExe.EDEN_CLI,
|
|
["--config-dir", str(self.temp_dir), "status"] + extra_args,
|
|
encoding="utf-8",
|
|
logfile=sys.stderr,
|
|
)
|