Esempio n. 1
0
    def _test_watchman_watcher_check(
        self,
        mock_watchman,
        initial_watcher: str,
        new_watcher: Optional[str] = None,
        dry_run: bool = True,
    ) -> Tuple[doctor.ProblemFixer, str]:
        edenfs_path = "/path/to/eden-mount"
        side_effects: List[Dict[str, Any]] = []
        calls = []

        calls.append(call(["watch-project", edenfs_path]))
        side_effects.append({"watch": edenfs_path, "watcher": initial_watcher})

        if initial_watcher != "eden" and not dry_run:
            calls.append(call(["watch-del", edenfs_path]))
            side_effects.append({"watch-del": True, "root": edenfs_path})

            self.assertIsNotNone(
                new_watcher,
                msg='Must specify new_watcher when initial_watcher is "eden".',
            )
            calls.append(call(["watch-project", edenfs_path]))
            side_effects.append({"watch": edenfs_path, "watcher": new_watcher})
        mock_watchman.side_effect = side_effects

        fixer, out = self.create_fixer(dry_run)

        watchman_roots = {edenfs_path}
        watchman_info = check_watchman.WatchmanCheckInfo(watchman_roots, None)
        check_watchman.check_active_mount(fixer, edenfs_path, watchman_info)

        mock_watchman.assert_has_calls(calls)
        return fixer, out.getvalue()
Esempio n. 2
0
    def _test_nuclide_check(
        self,
        mock_watchman,
        dry_run: bool = True,
        include_filewatcher_subscriptions: int = 0,
        include_path_in_nuclide_roots: bool = True,
        include_hg_subscriptions: bool = True,
    ) -> Tuple[doctor.ProblemFixer, str]:
        edenfs_path = "/path/to/eden-mount"
        side_effects: List[Dict[str, Any]] = []
        watchman_calls = []

        if include_path_in_nuclide_roots:
            watchman_calls.append(
                call(["debug-get-subscriptions", edenfs_path]))

        nuclide_root = os.path.join(edenfs_path, "subdirectory")
        # Note that a "filewatcher-" subscription in a subdirectory of the
        # Eden mount should signal that the proper Watchman subscription is
        # set up.
        filewatcher_sub: List[str] = [f"filewatcher-{nuclide_root}"
                                      ] * include_filewatcher_subscriptions

        unrelated_path = "/path/to/non-eden-mount"
        if include_path_in_nuclide_roots:
            nuclide_roots = {nuclide_root, unrelated_path}
        else:
            nuclide_roots = {unrelated_path}

        side_effects.append(
            _create_watchman_subscription(
                filewatcher_subscriptions=filewatcher_sub,
                include_hg_subscriptions=include_hg_subscriptions,
            ))
        mock_watchman.side_effect = side_effects
        watchman_roots = {edenfs_path}

        fixer, out = self.create_fixer(dry_run)
        watchman_info = check_watchman.WatchmanCheckInfo(
            watchman_roots, nuclide_roots)
        check_watchman.check_nuclide_subscriptions(fixer, edenfs_path,
                                                   watchman_info)

        mock_watchman.assert_has_calls(watchman_calls)
        return fixer, out.getvalue()