mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
Refactor RestartTest to set up using 'eden start'
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
This commit is contained in:
parent
d1f1df8178
commit
4f392a403c
@ -20,13 +20,34 @@ from .find_executables import FindExe
|
||||
class FakeEdenFS(typing.ContextManager[int]):
|
||||
"""A running fake_edenfs process."""
|
||||
|
||||
@staticmethod
|
||||
@classmethod
|
||||
def spawn(
|
||||
eden_dir: pathlib.Path, extra_arguments: typing.Sequence[str] = ()
|
||||
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)
|
||||
|
||||
|
@ -8,16 +8,16 @@
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
from typing import Any
|
||||
|
||||
import eden.thrift
|
||||
import eden.thrift.client
|
||||
import pexpect
|
||||
|
||||
from .lib.fake_edenfs import FakeEdenFS
|
||||
from .lib.find_executables import FindExe
|
||||
from .lib.temporary_directory import TemporaryDirectoryMixin
|
||||
|
||||
@ -49,16 +49,21 @@ class RestartTest(unittest.TestCase, TemporaryDirectoryMixin):
|
||||
)
|
||||
|
||||
def _start_fake_edenfs(self) -> int:
|
||||
# Run "eden restart". It should start it without prompting since edenfs is not
|
||||
# already running.
|
||||
daemon = FakeEdenFS.spawn_via_cli(eden_dir=pathlib.Path(self.tmp_dir))
|
||||
return daemon.process_id
|
||||
|
||||
def test_restart_starts_edenfs_if_not_running(self) -> None:
|
||||
"""
|
||||
Run "eden restart". It should start it without prompting since edenfs
|
||||
is not already running.
|
||||
"""
|
||||
p = self._spawn_restart()
|
||||
p.expect_exact("Eden is not currently running. Starting it...")
|
||||
p.expect_exact("Starting fake edenfs daemon")
|
||||
p.expect(r"Started edenfs \(pid ([0-9]+)\)")
|
||||
pid = int(p.match.group(1))
|
||||
int(p.match.group(1))
|
||||
p.wait()
|
||||
self.assertEqual(p.exitstatus, 0)
|
||||
return pid
|
||||
|
||||
def _get_thrift_client(self) -> eden.thrift.EdenClient:
|
||||
return eden.thrift.create_thrift_client(self.tmp_dir)
|
||||
|
Loading…
Reference in New Issue
Block a user