diff --git a/eden/integration/lib/fake_edenfs.py b/eden/integration/lib/fake_edenfs.py index ec7a6dd515..61f55f4791 100644 --- a/eden/integration/lib/fake_edenfs.py +++ b/eden/integration/lib/fake_edenfs.py @@ -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) diff --git a/eden/integration/restart_test.py b/eden/integration/restart_test.py index 585820a8bc..2b4a2e1245 100644 --- a/eden/integration/restart_test.py +++ b/eden/integration/restart_test.py @@ -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)