Пример #1
0
    def runWatchTests(self, config, expect) -> None:
        with WatchmanInstance.Instance(config=config) as inst:
            inst.start()
            client = self.getClient(inst)

            for filetype, name, expect_pass in expect:
                for watch_type in ["watch", "watch-project"]:
                    # encode the test criteria in the dirname so that we can
                    # figure out which test scenario failed more easily
                    d = self.mkdtemp(suffix="-%s-%s-%s-%s" %
                                     (filetype, name, expect_pass, watch_type))
                    if filetype == "directory":
                        os.mkdir(os.path.join(d, name))
                    elif filetype == "file":
                        self.touchRelative(d, name)

                    assert_functions = {
                        (True, "watch"):
                        self.assertWatchSucceeds,
                        (True, "watch-project"):
                        self.assertWatchProjectSucceeds,
                        (False, "watch"):
                        self.assertWatchIsRestricted,
                        (False, "watch-project"):
                        self.assertWatchProjectIsRestricted,
                    }
                    assert_function = assert_functions[(expect_pass,
                                                        watch_type)]
                    assert_function(inst, client, d)
Пример #2
0
 def test_failing_to_start_when_nice(self) -> None:
     inst = WatchmanInstance.Instance()
     stdout, stderr = inst.commandViaCLI(["version"], prefix=["nice"])
     print("stdout", stdout.decode(errors="replace"))
     print("stderr", stderr.decode(errors="replace"))
     stderr = stderr.decode("ascii")
     self.assertEqual(b"", stdout)
     self.assertRegex(stderr, "refusing to start")
Пример #3
0
    def test_spawner(self) -> None:
        config = {"spawn_watchman_service": SITE_SPAWN}

        inst = WatchmanInstance.Instance(config=config)
        stdout, stderr = inst.commandViaCLI(["version"])

        parsed = json.loads(stdout.decode("ascii"))
        self.assertTrue("version" in parsed)

        # Shut down that process, as we have no automatic way to deal with it
        inst.commandViaCLI(["--no-spawn", "--no-local", "shutdown-server"])
Пример #4
0
    def runProjectTests(self,
                        config,
                        expect,
                        touch_watchmanconfig: bool = False) -> None:
        with WatchmanInstance.Instance(config=config) as inst:
            inst.start()
            client = self.getClient(inst)

            for touch, expect_watch, expect_rel, expect_pass in expect:
                # encode the test criteria in the dirname so that we can
                # figure out which test scenario failed more easily

                suffix = "-%s-%s-%s-%s" % (touch, expect_watch, expect_rel,
                                           expect_pass)
                suffix = suffix.replace("/", "Z")
                d = self.mkdtemp(suffix=suffix)

                dir_to_watch = os.path.join(d, "a", "b", "c")
                os.makedirs(dir_to_watch, 0o777)
                dir_to_watch = norm_absolute_path(dir_to_watch)
                self.touchRelative(d, touch)
                if touch_watchmanconfig:
                    make_empty_watchmanconfig(d)

                if expect_watch:
                    expect_watch = os.path.join(d, expect_watch)
                else:
                    expect_watch = d

                if expect_pass:
                    res = client.query("watch-project", dir_to_watch)

                    self.assertEqual(
                        norm_absolute_path(os.path.join(d, expect_watch)),
                        norm_absolute_path(res["watch"]),
                    )
                    if not expect_rel:
                        self.assertEqual(None, res.get("relative_path"))
                    else:
                        self.assertEqual(
                            norm_relative_path(expect_rel),
                            norm_relative_path(res.get("relative_path")),
                        )
                else:
                    with self.assertRaises(pywatchman.WatchmanError) as ctx:
                        client.query("watch-project", dir_to_watch)
                    self.assertIn(
                        ("None of the files listed in global config " +
                         "root_files are present in path `" + dir_to_watch +
                         "` or any of its parent directories.  " +
                         "root_files is defined by the"),
                        str(ctx.exception),
                    )
Пример #5
0
    def test_bulkstat_off(self) -> None:
        config = {"_use_bulkstat": False}
        with WatchmanInstance.Instance(config=config) as inst:
            inst.start()
            self.getClient(inst, replace_cached=True)

            root = self.mkdtemp()
            # pyre-fixme[16]: `TestBulkStat` has no attribute `client`.
            self.client.query("watch", root)

            self.touchRelative(root, "foo")
            self.touchRelative(root, "bar")
            self.assertFileList(root, ["foo", "bar"])
Пример #6
0
    def test_no_site_spawner(self) -> None:
        """With a site spawner configured to otherwise fail, pass
        `--no-site-spawner` and ensure that a failure didn't occur."""
        config = {"spawn_watchman_service": SITE_SPAWN_FAIL}

        inst = WatchmanInstance.Instance(config=config)
        stdout, stderr = inst.commandViaCLI(["version", "--no-site-spawner"])

        print(stdout, stderr.decode("ascii"))
        parsed = json.loads(stdout.decode("ascii"))
        self.assertTrue("version" in parsed)

        inst.commandViaCLI(["--no-spawn", "--no-local", "shutdown-server"])
Пример #7
0
    def test_failingSpawner(self) -> None:
        config = {"spawn_watchman_service": SITE_SPAWN_FAIL}

        inst = WatchmanInstance.Instance(config=config)
        stdout, stderr = inst.commandViaCLI(["version"])
        sys.stdout.buffer.write(b"stdout:\n")
        sys.stdout.buffer.write(stdout)
        sys.stdout.buffer.write(b"stderr:\n")
        sys.stdout.buffer.write(stderr)
        stderr = stderr.decode("ascii")
        self.assertEqual(b"", stdout)
        self.assertRegex(stderr, "failed to start\n")
        self.assertRegex(stderr, "site_spawn_fail.py: exited with status 1")
Пример #8
0
    def test_shutdown_and_restart(self) -> None:
        def populate(repo: hgrepo.HgRepository) -> None:
            repo.write_file("hello", "hola\n")
            repo.commit("initial commit.")

        root = self.makeEdenMount(populate)

        inst = WatchmanInstance.Instance()
        _, stderr = inst.commandViaCLI(["watch", root])
        self.assertEqual(stderr, b"")
        _, stderr = inst.commandViaCLI(["shutdown-server"])
        self.assertEqual(stderr, b"")
        _, stderr = inst.commandViaCLI(["get-sockname"])
        self.assertEqual(stderr, b"")
Пример #9
0
    def test_failing_to_start_when_nice_foreground(self) -> None:
        inst = WatchmanInstance.Instance()
        stdout, stderr = inst.commandViaCLI(["--foreground", "version"],
                                            prefix=["nice"])
        print("stdout", stdout)
        print("stderr", stderr)

        output = stderr.decode("ascii")
        try:
            output += inst.getServerLogContents()
        except IOError:
            # on macos, we may not have gotten as far
            # as creating the log file when the error
            # triggers, so we're fine with passing
            # on io errors here
            pass
        self.assertRegex(output, "refusing to start")
Пример #10
0
    def test_Illegal(self) -> None:
        config = {
            "illegal_fstypes": [
                # This should include any/all fs types. If this test fails on
                # your platform, look in /tmp/watchman-test.log for a line like:
                # "path /var/tmp/a3osdzvzqnco0sok is on filesystem type zfs"
                # then add the type name to this list, in sorted order
                "NTFS",
                "apfs",
                "btrfs",
                "cifs",
                "ext2",
                "ext3",
                "ext4",
                "fuse",
                "hfs",
                "msdos",
                "nfs",
                "smb",
                "tmpfs",
                "ufs",
                "unknown",
                "xfs",
                "zfs",
            ],
            "illegal_fstypes_advice":
            "just cos",
        }

        with WatchmanInstance.Instance(config=config) as inst:
            inst.start()
            client = self.getClient(inst)

            d = self.mkdtemp()
            with self.assertRaises(pywatchman.WatchmanError) as ctx:
                client.query("watch", d)
            self.assertIn(
                ("filesystem and is disallowed by global config" +
                 " illegal_fstypes: just cos"),
                str(ctx.exception),
            )