mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
4f392a403c
Summary: RestartTest uses 'eden restart' during setup to start the fake_edenfs process. There are two issues with doing this: * I want to extend the tests in RestartTest so they also tests with an ad-hoc fake_edenfs process (D10414995). Restarting edenfs during setup makes no sense in that context. * I think using 'eden restart' during setup is clunky and unintuitive. 'eden start' is more appropriate. Refactor RestartTest's setup so it uses 'eden start' instead. Also add a test which explicitly verifies that 'eden restart' starts fake_edenfs if no daemon is already running. Reviewed By: chadaustin Differential Revision: D10417304 fbshipit-source-id: 20f8190026cd153dd9b539067f6f63b6bd27abed
65 lines
1.9 KiB
Python
65 lines
1.9 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 contextlib
|
|
import os
|
|
import pathlib
|
|
import signal
|
|
import subprocess
|
|
import typing
|
|
|
|
from .find_executables import FindExe
|
|
|
|
|
|
class FakeEdenFS(typing.ContextManager[int]):
|
|
"""A running fake_edenfs process."""
|
|
|
|
@classmethod
|
|
def spawn(
|
|
cls, eden_dir: pathlib.Path, extra_arguments: typing.Sequence[str] = ()
|
|
) -> "FakeEdenFS":
|
|
command = [FindExe.FAKE_EDENFS, "--edenDir", str(eden_dir)]
|
|
command.extend(extra_arguments)
|
|
subprocess.check_call(command)
|
|
return cls.from_existing_process(eden_dir=eden_dir)
|
|
|
|
@classmethod
|
|
def spawn_via_cli(
|
|
cls, eden_dir: pathlib.Path, extra_arguments: typing.Sequence[str] = ()
|
|
) -> "FakeEdenFS":
|
|
command = [
|
|
FindExe.EDEN_CLI,
|
|
"--config-dir",
|
|
str(eden_dir),
|
|
"start",
|
|
"--daemon-binary",
|
|
FindExe.FAKE_EDENFS,
|
|
"--",
|
|
]
|
|
command.extend(extra_arguments)
|
|
subprocess.check_call(command)
|
|
return cls.from_existing_process(eden_dir=eden_dir)
|
|
|
|
@staticmethod
|
|
def from_existing_process(eden_dir: pathlib.Path) -> "FakeEdenFS":
|
|
edenfs_pid = int((eden_dir / "lock").read_text())
|
|
return FakeEdenFS(process_id=edenfs_pid)
|
|
|
|
def __init__(self, process_id: int) -> None:
|
|
super().__init__()
|
|
self.process_id = process_id
|
|
|
|
def __enter__(self) -> int:
|
|
return self.process_id
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
with contextlib.suppress(ProcessLookupError):
|
|
os.kill(self.process_id, signal.SIGTERM)
|
|
return None
|