mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
c13f0ac5f7
Summary: Update the integration test code that uses pexpect to use the more modern pexpect APIs. The top-level `pexpect.spawn()` function is considered legacy now, and is only provided for backwards compatibility on Unix platforms. Reviewed By: wez Differential Revision: D21214640 fbshipit-source-id: 941da5435c4f8afaf22e8053f4c344175d7b1a7f
81 lines
3.0 KiB
Python
81 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2.
|
|
|
|
import os
|
|
import pathlib
|
|
import signal
|
|
import sys
|
|
import typing
|
|
|
|
import pexpect
|
|
from eden.fs.cli.daemon import wait_for_shutdown
|
|
|
|
from .lib import edenclient, testcase
|
|
from .lib.find_executables import FindExe
|
|
from .lib.pexpect import PexpectAssertionMixin, PexpectSpawnType, pexpect_spawn
|
|
from .lib.service_test_case import ServiceTestCaseBase, service_test
|
|
|
|
|
|
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):
|
|
def setUp(self) -> None:
|
|
super().setUp()
|
|
self.temp_dir = self.make_temp_dir()
|
|
|
|
def test_healthy_daemon_is_healthy(self) -> None:
|
|
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) -> None:
|
|
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) -> None:
|
|
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) -> None:
|
|
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]) -> PexpectSpawnType:
|
|
return pexpect_spawn(
|
|
FindExe.EDEN_CLI,
|
|
["--config-dir", str(self.temp_dir)]
|
|
+ self.get_required_eden_cli_args()
|
|
+ ["status"]
|
|
+ extra_args,
|
|
encoding="utf-8",
|
|
logfile=sys.stderr,
|
|
)
|