Exemple #1
0
    def test_different_parents(self) -> None:
        mount_path = Path(self.mount)

        # set eden to point at the first commit, while keeping mercurial at the
        # second commit
        parents = WorkingDirectoryParents(parent1=self.commit1.encode("utf-8"))
        params = ResetParentCommitsParams()
        with self.eden.get_thrift_client_legacy() as client:
            client.resetParentCommits(mountPoint=bytes(mount_path),
                                      parents=parents,
                                      params=params)

        output = self.eden.run_cmd("debug", "parents",
                                   cwd=self.mount).strip("\n")
        self.assertEqual(output, self.commit1)

        output_hg = self.eden.run_cmd("debug",
                                      "parents",
                                      "--hg",
                                      cwd=self.mount)
        expected = "Mercurial p0: %s\nEdenFS snapshot: %s\n" % (
            self.commit2,
            self.commit1,
        )
        self.assertEqual(output_hg, expected)
Exemple #2
0
    def _assert_thrift_calls_fail_during_mount_init(
            self, client: EdenClient) -> None:
        error_regex = "mount point .* is still initializing"
        mount_path = Path(self.mount)
        null_commit = b"\00" * 20

        with self.assertRaisesRegex(EdenError, error_regex) as ctx:
            client.getFileInformation(mountPoint=bytes(mount_path),
                                      paths=[b""],
                                      sync=SyncBehavior())
        self.assertEqual(EdenErrorType.POSIX_ERROR, ctx.exception.errorType)

        with self.assertRaisesRegex(EdenError, error_regex) as ctx:
            client.getScmStatus(mountPoint=bytes(mount_path),
                                listIgnored=False,
                                commit=null_commit)
        self.assertEqual(EdenErrorType.POSIX_ERROR, ctx.exception.errorType)

        parents = WorkingDirectoryParents(parent1=null_commit)
        params = ResetParentCommitsParams()
        with self.assertRaisesRegex(EdenError, error_regex) as ctx:
            client.resetParentCommits(mountPoint=bytes(mount_path),
                                      parents=parents,
                                      params=params)
        self.assertEqual(EdenErrorType.POSIX_ERROR, ctx.exception.errorType)
Exemple #3
0
    def _assert_thrift_calls_fail_during_mount_init(self, client: EdenClient) -> None:
        error_regex = "mount point .* is still initializing"
        mount_path = Path(self.mount)
        null_commit = b"\00" * 20

        with self.assertRaisesRegex(EdenError, error_regex):
            client.getFileInformation(mountPoint=bytes(mount_path), paths=[b""])

        with self.assertRaisesRegex(EdenError, error_regex):
            client.getScmStatus(
                mountPoint=bytes(mount_path), listIgnored=False, commit=null_commit
            )

        parents = WorkingDirectoryParents(parent1=null_commit)
        with self.assertRaisesRegex(EdenError, error_regex):
            client.resetParentCommits(mountPoint=bytes(mount_path), parents=parents)
Exemple #4
0
    def test_eden_doctor_fixes_invalid_mismatched_parents(self) -> None:
        # this specifically tests when EdenFS and Mercurial are out of sync,
        # but Mercurial does not know about Eden's WCP

        mount_path = Path(self.mount)

        corrupt_commit = b"9" * 40
        parents = WorkingDirectoryParents(parent1=corrupt_commit)

        # point eden to a random commit
        with self.eden.get_thrift_client() as client:
            client.resetParentCommits(mountPoint=bytes(mount_path),
                                      parents=parents)

        with self.assertRaises(hgrepo.HgError) as status_context:
            self.repo.status()

        self.assertIn(b"requested parent commit is out-of-date",
                      status_context.exception.stderr)

        # hg whereami reads eden's SNAPSHOT file
        eden_parent = self.hg("whereami").strip("\n")
        hg_parent = self.hg("log", "-r.", "-T{node}")

        # make sure that eden and mercurial are out of sync
        self.assertNotEqual(eden_parent, hg_parent)

        cmd_result = self.eden.run_unchecked("doctor",
                                             "-n",
                                             stdout=subprocess.PIPE)
        self.assertIn(b"Eden's snapshot file points to a bad commit",
                      cmd_result.stdout)

        # run eden doctor and make sure eden and mercurial are in sync again
        fixed_result = self.eden.run_unchecked("doctor",
                                               stdout=subprocess.PIPE)
        self.assertIn(b"Successfully fixed 1 problem", fixed_result.stdout)

        eden_parent_fixed = self.hg("whereami").strip("\n")
        hg_parent_fixed = self.hg("log", "-r.", "-T{node}")
        self.assertEqual(eden_parent_fixed, hg_parent_fixed)

        # Since Eden's snapshot file pointed to a bad commit, it should pick
        # mercurial's parent as the new parent
        self.assertEqual(hg_parent, hg_parent_fixed)
Exemple #5
0
    def test_eden_doctor_fixes_valid_mismatched_parents(self) -> None:
        # this specifically tests when EdenFS and Mercurial are out of sync,
        # but and mercurial does know about EdenFS's WCP
        mount_path = Path(self.mount)

        # set eden to point at the first commit, while keeping mercurial at the
        # second commit
        parents = WorkingDirectoryParents(parent1=self.commit1.encode("utf-8"))
        with self.eden.get_thrift_client() as client:
            client.resetParentCommits(mountPoint=bytes(mount_path),
                                      parents=parents)

        with self.assertRaises(hgrepo.HgError) as status_context:
            self.repo.status()

        self.assertIn(b"requested parent commit is out-of-date",
                      status_context.exception.stderr)

        # hg whereami reads eden's SNAPSHOT file
        eden_parent = self.hg("whereami").strip("\n")
        hg_parent = self.hg("log", "-r.", "-T{node}")

        # make sure that eden and mercurial are out of sync
        self.assertNotEqual(eden_parent, hg_parent)

        cmd_result = self.eden.run_unchecked("doctor",
                                             "-n",
                                             stdout=subprocess.PIPE)
        error_msg = (
            "mercurial's parent commit is %s, but Eden's internal parent commit is %s"
            % (self.commit2, self.commit1))
        self.assertIn(error_msg.encode("utf-8"), cmd_result.stdout)

        # run eden doctor and make sure eden and mercurial are in sync again
        fixed_result = self.eden.run_unchecked("doctor",
                                               stdout=subprocess.PIPE)
        self.assertIn(b"Successfully fixed 1 problem", fixed_result.stdout)

        eden_parent_fixed = self.hg("whereami").strip("\n")
        hg_parent_fixed = self.hg("log", "-r.", "-T{node}")
        self.assertEqual(eden_parent_fixed, hg_parent_fixed)

        # Since Eden's snapshot file pointed to a known commit, it should pick
        # Eden's parent as the new parent
        self.assertEqual(eden_parent, hg_parent_fixed)