Example #1
0
    def runTest(self):
        env = os.environ.copy()
        env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath()
        dotted = os.path.normpath(self.id()).replace(os.sep, '.').replace(
            'tests.integration.', '').replace('.php', '')
        env['TMPDIR'] = os.path.join(TempDir.get_temp_dir().get_dir(), dotted)
        os.mkdir(env['TMPDIR'])

        # build the node module with npm
        node_dir = os.path.join(env['TMPDIR'], 'fb-watchman')
        shutil.copytree(os.path.join(WATCHMAN_SRC_DIR, 'node'), node_dir)
        subprocess.check_call(['npm', 'install'], cwd=node_dir)

        env['TMP'] = env['TMPDIR']
        env['TEMP'] = env['TMPDIR']
        env['IN_PYTHON_HARNESS'] = '1'
        env['NODE_PATH'] = '%s:%s' % (env['TMPDIR'], env.get('NODE_PATH', ''))
        proc = subprocess.Popen(
            self.getCommandArgs(),
            env=env,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail('Interrupted by SIGINT')
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" %
                      (status, stdout.decode('utf-8'), stderr.decode('utf-8')))
            return
        self.assertTrue(True, self.getCommandArgs())
Example #2
0
    def runTest(self):
        env = os.environ.copy()
        env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance(
        ).getSockPath()
        dotted = os.path.normpath(self.id()).replace(os.sep, '.').replace(
            'tests.integration.', '').replace('.php', '')
        env['TMPDIR'] = os.path.join(tempfile.tempdir, dotted)
        os.mkdir(env['TMPDIR'])
        env['TMP'] = env['TMPDIR']
        env['TEMP'] = env['TMPDIR']
        env['IN_PYTHON_HARNESS'] = '1'
        proc = subprocess.Popen(self.getCommandArgs(),
                                env=env,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail('Interrupted by SIGINT')
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" % (status, stdout, stderr))
            return
        self.assertTrue(True, self.jsfile)
Example #3
0
    def runTest(self):
        env = os.environ.copy()
        env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance(
        ).getSockPath()
        env["TMPDIR"] = self.tempdir

        # build the node module with npm
        node_dir = os.path.join(env["TMPDIR"], "fb-watchman")
        shutil.copytree(os.path.join(WATCHMAN_SRC_DIR, "node"), node_dir)
        subprocess.check_call(["npm", "install"], cwd=node_dir)

        env["TMP"] = env["TMPDIR"]
        env["TEMP"] = env["TMPDIR"]
        env["IN_PYTHON_HARNESS"] = "1"
        env["NODE_PATH"] = "%s:%s" % (env["TMPDIR"], env.get("NODE_PATH", ""))
        proc = subprocess.Popen(
            self.getCommandArgs(),
            env=env,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail("Interrupted by SIGINT")
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" %
                      (status, stdout.decode("utf-8"), stderr.decode("utf-8")))
            return
        self.assertTrue(True, self.getCommandArgs())
Example #4
0
 def getServerLogContents(self):
     """
     Returns the contents of the server log file as an array
     that has already been split by line.
     """
     return WatchmanInstance.getSharedInstance().getServerLogContents(
     ).split("\n")
Example #5
0
    def test_wait(self):

        root = self.mkdtemp()
        self.touchRelative(root, 'foo')
        a_dir = os.path.join(root, 'a')
        os.mkdir(a_dir)
        self.touchRelative(a_dir, 'foo')

        wi = WatchmanWaitInstance.Instance(
            sock_path=WatchmanInstance.getSharedInstance().getSockPath()
        )
        wi.start(paths=[root], cmdArgs=['--relative', root])
        self.assertSyncWatchmanWait(wi, root)

        self.touchRelative(root, 'bar')
        self.removeRelative(root, 'foo')
        self.assertWaitedFileList(wi, ['foo', 'bar'], msg="wait, create files")

        self.touchRelative(a_dir, 'bar')
        self.removeRelative(a_dir, 'foo')
        self.assertWaitedFileList(
            wi, ['a/bar', 'a/foo', 'a'], msg="wait, create dir")

        b_dir = os.path.join(root, 'b')
        os.mkdir(b_dir)
        self.touchRelative(b_dir, 'foo')
        self.assertWaitedFileList(wi, ['b', 'b/foo'], msg=None)
Example #6
0
 def test_sock_name(self):
     resp = self.watchmanCommand("get-sockname")
     self.assertEqual(
         resp["sockname"],
         WatchmanInstance.getSharedInstance().getSockPath().legacy_sockpath(
         ),
     )
Example #7
0
    def test_scmHgRequestId(self):
        if not is_hg_installed():
            self.skipTest("Hg not installed")
        self.skipIfNoHgRequestIdSupport()

        root = self.mkdtemp()

        # In this test, the repo does not necessarily need fsmonitor enabled,
        # since watchman calls HGREQUESTID=... hg status and that would also
        # have request_id logged without fsmonitor.
        env = os.environ.copy()
        env["HGPLAIN"] = "1"
        env["WATCHMAN_SOCK"] = (WatchmanInstance.getSharedInstance().
                                getSockPath().legacy_sockpath())
        subprocess.call(["hg", "init"], env=env, cwd=root)
        subprocess.call(
            [
                "hg",
                "commit",
                "-mempty",
                "-utest",
                "-d0 0",
                "--config=ui.allowemptycommit=1",
            ],
            env=env,
            cwd=root,
        )
        commit_hash = subprocess.check_output(["hg", "log", "-r.", "-T{node}"],
                                              env=env,
                                              cwd=root).decode("utf-8")

        # Must watch the directory after it's an HG repo to perform scm-aware
        # queries.
        self.watchmanCommand("watch", root)
        request_id = "4c05a798ea1acc7c97b75e61fec5f640d90f8209"

        params = {
            "fields": ["name"],
            "request_id": request_id,
            "since": {
                "scm": {
                    "mergebase-with": commit_hash
                }
            },
        }
        self.watchmanCommand("query", root, params)

        blackbox_path = os.path.join(root, ".hg", "blackbox.log")

        def try_read_blackbox():
            try:
                with open(blackbox_path) as f:
                    return f.read()
            except IOError:
                return ""

        self.assertWaitFor(
            lambda: request_id in try_read_blackbox(),
            message="request_id passed to and logged by hg",
        )
Example #8
0
    def hg(self, args, cwd=None):
        env = dict(os.environ)
        env["HGPLAIN"] = "1"
        env["HGUSER"] = "******"
        env["NOSCMLOG"] = "1"  # disable some instrumentation at FB
        sockpath = WatchmanInstance.getSharedInstance().getSockPath()
        env["WATCHMAN_SOCK"] = sockpath.legacy_sockpath()
        p = subprocess.Popen(
            [
                env.get("EDEN_HG_BINARY", "hg"),
                # we force the extension on.  This is a soft error for
                # mercurial if it is not available, so we also employ
                # the skipIfNoFSMonitor() test above to make sure the
                # environment is sane.
                "--config",
                "extensions.fsmonitor=",
                # Deployed versions of mercurial regressed and stopped
                # respecting the WATCHMAN_SOCK environment override, so
                # we have to reach in and force their hardcoded sockpath here.
                "--config",
                "fsmonitor.sockpath=%s" % sockpath.legacy_sockpath(),
            ] + args,
            env=env,
            cwd=cwd,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception("hg %r failed: %s, %s" % (args, out, err))

        return out, err
Example #9
0
    def runTest(self):
        env = os.environ.copy()
        env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance(
        ).getSockPath()
        dotted = os.path.normpath(self.id()).replace(os.sep, '.').replace(
            'tests.integration.', '').replace('.php', '')
        env['TMPDIR'] = os.path.join(tempfile.tempdir, dotted)
        os.mkdir(env['TMPDIR'])

        # build the node module with npm
        node_dir = os.path.join(env['TMPDIR'], 'fb-watchman')
        shutil.copytree('node', node_dir)
        subprocess.check_call(['npm', 'install'], cwd=node_dir)

        env['TMP'] = env['TMPDIR']
        env['TEMP'] = env['TMPDIR']
        env['IN_PYTHON_HARNESS'] = '1'
        env['NODE_PATH'] = '%s:%s' % (env['TMPDIR'], env.get('NODE_PATH', ''))
        proc = subprocess.Popen(self.getCommandArgs(),
                                env=env,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail('Interrupted by SIGINT')
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" %
                      (status, stdout.decode('utf-8'), stderr.decode('utf-8')))
            return
        self.assertTrue(True, self.jsfile)
Example #10
0
    def hg(self, args=None, cwd=None):
        env = dict(os.environ)
        env["HGPLAIN"] = "1"
        env["HGUSER"] = "******"
        env["NOSCMLOG"] = "1"  # disable some instrumentation at FB
        env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance(
        ).getSockPath()
        p = subprocess.Popen(
            # we force the extension on.  This is a soft error for
            # mercurial if it is not available, so we also employ
            # the skipIfNoFSMonitor() test above to make sure the
            # environment is sane.
            [
                env.get("EDEN_HG_BINARY", "hg"), "--config",
                "extensions.fsmonitor="
            ] + args,
            env=env,
            cwd=cwd,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception("hg %r failed: %s, %s" % (args, out, err))

        return out, err
Example #11
0
    def test_cppclient(self):
        env = os.environ.copy()
        env["WATCHMAN_SOCK"] = (WatchmanInstance.getSharedInstance().
                                getSockPath().legacy_sockpath())
        proc = subprocess.Popen(
            TEST_BINARY,
            env=env,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=self.tmpDir,
        )
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail("Interrupted by SIGINT")
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" %
                      (status, stdout.decode("utf-8"), stderr.decode("utf-8")))
            return

        self.assertTrue(True, TEST_BINARY)
Example #12
0
    def runTest(self):
        env = os.environ.copy()
        env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath()
        dotted = os.path.normpath(self.id()).replace(os.sep, '.').replace(
            'tests.integration.', '').replace('.php', '')
        env['TMPDIR'] = os.path.join(tempfile.tempdir, dotted)
        os.mkdir(env['TMPDIR'])
        env['TMP'] = env['TMPDIR']
        env['TEMP'] = env['TMPDIR']
        env['IN_PYTHON_HARNESS'] = '1'
        proc = subprocess.Popen(
            self.getCommandArgs(),
            env=env,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail('Interrupted by SIGINT')
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" %
                      (status, stdout.decode('utf-8'), stderr.decode('utf-8')))
            return
        self.assertTrue(True, self.jsfile)
Example #13
0
    def test_rel_root(self):
        root = self.mkdtemp()

        a_dir = os.path.join(root, 'a')
        os.mkdir(a_dir)
        b_dir = os.path.join(root, 'b')
        os.mkdir(b_dir)

        wi = WatchmanWaitInstance.Instance(
            sock_path=WatchmanInstance.getSharedInstance().getSockPath()
        )
        wi.start(paths=[a_dir, b_dir], cmdArgs=['--relative', b_dir])

        self.assertSyncWatchmanWait(wi, a_dir)
        self.touchRelative(a_dir, 'afoo')
        self.touchRelative(b_dir, 'bfoo')
        self.assertWaitedFileList(
            wi, ['../a/afoo', 'bfoo'], msg="wait, relative create files")

        a_sub_dir = os.path.join(a_dir, 'asub')
        os.mkdir(a_sub_dir)
        b_sub_dir = os.path.join(b_dir, 'bsub')
        os.mkdir(b_sub_dir)
        self.assertWaitedFileList(
            wi, ['../a/asub', 'bsub'], msg="wait, relative create directories")
Example #14
0
 def getServerLogContents(self):
     '''
     Returns the contents of the server log file as an array
     that has already been split by line.
     '''
     return WatchmanInstance.getSharedInstance().\
         getServerLogContents().split('\n')
Example #15
0
    def runTest(self):
        env = os.environ.copy()
        env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance().getSockPath()
        env["TMPDIR"] = self.tempdir

        # build the node module with npm
        node_dir = os.path.join(env["TMPDIR"], "fb-watchman")
        shutil.copytree(os.path.join(WATCHMAN_SRC_DIR, "node"), node_dir)
        subprocess.check_call(["npm", "install"], cwd=node_dir)

        env["TMP"] = env["TMPDIR"]
        env["TEMP"] = env["TMPDIR"]
        env["IN_PYTHON_HARNESS"] = "1"
        env["NODE_PATH"] = "%s:%s" % (env["TMPDIR"], env.get("NODE_PATH", ""))
        proc = subprocess.Popen(
            self.getCommandArgs(),
            env=env,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail("Interrupted by SIGINT")
            return

        if status != 0:
            self.fail(
                "Exit status %d\n%s\n%s\n"
                % (status, stdout.decode("utf-8"), stderr.decode("utf-8"))
            )
            return
        self.assertTrue(True, self.getCommandArgs())
Example #16
0
 def getClient(self):
     if not hasattr(self, 'client'):
         self.client = pywatchman.client(
             transport=self.transport,
             sendEncoding=self.encoding,
             recvEncoding=self.encoding,
             sockpath=WatchmanInstance.getSharedInstance().getSockPath())
     return self.client
Example #17
0
 def getClient(self):
     if not hasattr(self, 'client'):
         self.client = pywatchman.client(
             transport=self.transport,
             sendEncoding=self.encoding,
             recvEncoding=self.encoding,
             sockpath=WatchmanInstance.getSharedInstance().getSockPath())
     return self.client
Example #18
0
    def dumpLogs(self):
        ''' used in travis CI to show the hopefully relevant log snippets '''
        inst = WatchmanInstance.getSharedInstance()

        def tail(logstr, n):
            lines = logstr.split('\n')[-n:]
            return '\n'.join(lines)

        print(self.getLogSample())
Example #19
0
    def dumpLogs(self):
        ''' used in travis CI to show the hopefully relevant log snippets '''
        inst = WatchmanInstance.getSharedInstance()

        def tail(logstr, n):
            lines = logstr.split('\n')[-n:]
            return '\n'.join(lines)

        print(self.getLogSample())
Example #20
0
 def getClient(self):
     if not hasattr(self, 'client'):
         self.client = pywatchman.client(
             # ASAN-enabled builds can be slower enough that we hit timeouts
             # with the default of 1 second
             timeout=3.0,
             transport=self.transport,
             sendEncoding=self.encoding,
             recvEncoding=self.encoding,
             sockpath=WatchmanInstance.getSharedInstance().getSockPath())
     return self.client
    def dumpLogs(self):
        ''' used in travis CI to show the hopefully relevant log snippets '''
        inst = WatchmanInstance.getSharedInstance()

        def tail(logstr, n):
            lines = logstr.split('\n')[-n:]
            return '\n'.join(lines)

        print('CLI logs')
        print(tail(inst.getCLILogContents(), 500))
        print('Server logs')
        print(tail(inst.getServerLogContents(), 500))
Example #22
0
    def runTest(self):
        env = os.environ.copy()
        env["WATCHMAN_SOCK"] = (
            WatchmanInstance.getSharedInstance().getSockPath().legacy_sockpath()
        )
        env["TMPDIR"] = self.tempdir

        offline_mirror = env.get("YARN_OFFLINE_MIRROR_PATH_POINTER", None)
        if offline_mirror:
            with open(offline_mirror, "r") as f:
                mirror = f.read().strip()
                env["YARN_YARN_OFFLINE_MIRROR"] = mirror
        offline = "YARN_YARN_OFFLINE_MIRROR" in env

        # build the node module with yarn
        node_dir = os.path.join(env["TMPDIR"], "fb-watchman")
        shutil.copytree(os.path.join(WATCHMAN_SRC_DIR, "node"), node_dir)

        install_args = [yarn_bin, "install"]
        if offline:
            install_args.append("--offline")

        bser_dir = os.path.join(node_dir, "bser")
        subprocess.check_call(install_args, cwd=bser_dir, env=env)

        env["TMP"] = env["TMPDIR"]
        env["TEMP"] = env["TMPDIR"]
        env["IN_PYTHON_HARNESS"] = "1"
        env["NODE_PATH"] = "%s:%s" % (node_dir, env["TMPDIR"])
        proc = subprocess.Popen(
            self.getCommandArgs(),
            env=env,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail("Interrupted by SIGINT")
            return

        if status != 0:
            self.fail(
                "Exit status %d\n%s\n%s\n"
                % (status, stdout.decode("utf-8"), stderr.decode("utf-8"))
            )
            return
        self.assertTrue(True, self.getCommandArgs())
Example #23
0
 def getClient(self, inst=None, replace_cached=False, no_cache=False):
     if inst or not hasattr(self, "client") or no_cache:
         client = pywatchman.client(
             timeout=self.socketTimeout,
             transport=self.transport,
             sendEncoding=self.encoding,
             recvEncoding=self.encoding,
             sockpath=(inst or WatchmanInstance.getSharedInstance()).getSockPath(),
         )
         if (not inst or replace_cached) and not no_cache:
             # only cache the client if it points to the shared instance
             self.client = client
         return client
     return self.client
Example #24
0
    def getLogSample(self):
        ''' used in CI to show the hopefully relevant log snippets '''
        inst = WatchmanInstance.getSharedInstance()

        def tail(logstr, n):
            lines = logstr.split('\n')[-n:]
            return '\n'.join(lines)

        return '\n'.join([
            'CLI logs',
            tail(inst.getCLILogContents(), 500),
            'Server logs',
            tail(inst.getServerLogContents(), 500),
        ])
Example #25
0
    def getLogSample(self):
        ''' used in CI to show the hopefully relevant log snippets '''
        inst = WatchmanInstance.getSharedInstance()

        def tail(logstr, n):
            lines = logstr.split('\n')[-n:]
            return '\n'.join(lines)

        return '\n'.join([
            'CLI logs',
            tail(inst.getCLILogContents(), 500),
            'Server logs',
            tail(inst.getServerLogContents(), 500),
        ])
Example #26
0
    def getLogSample(self):
        """ used in CI to show the hopefully relevant log snippets """
        inst = WatchmanInstance.getSharedInstance()

        def tail(logstr, n):
            lines = logstr.split("\n")[-n:]
            return "\n".join(lines)

        return "\n".join([
            "CLI logs",
            tail(inst.getCLILogContents(), 500),
            "Server logs",
            tail(inst.getServerLogContents(), 500),
        ])
Example #27
0
 def getClient(self, inst=None, replace_cached=False, no_cache=False):
     if inst or not hasattr(self, "client") or no_cache:
         client = pywatchman.client(
             timeout=self.socketTimeout,
             transport=self.transport,
             sendEncoding=self.encoding,
             recvEncoding=self.encoding,
             sockpath=(inst or WatchmanInstance.getSharedInstance()).getSockPath(),
         )
         if (not inst or replace_cached) and not no_cache:
             # only cache the client if it points to the shared instance
             self.client = client
             self.addCleanup(lambda: self.__clearClient())
         return client
     return self.client
Example #28
0
 def getClient(self, inst=None):
     if inst or not hasattr(self, 'client'):
         client = pywatchman.client(
             # ASAN-enabled builds can be slower enough that we hit timeouts
             # with the default of 1 second
             timeout=3.0,
             transport=self.transport,
             sendEncoding=self.encoding,
             recvEncoding=self.encoding,
             sockpath=(inst or
                       WatchmanInstance.getSharedInstance()).getSockPath())
         if not inst:
             # only cache the client if it points to the shared instance
             self.client = client
         return client
     return self.client
Example #29
0
    def getLogSample(self):
        """ used in CI to show the hopefully relevant log snippets """
        inst = WatchmanInstance.getSharedInstance()

        def tail(logstr, n):
            lines = logstr.split("\n")[-n:]
            return "\n".join(lines)

        return "\n".join(
            [
                "CLI logs",
                tail(inst.getCLILogContents(), 500),
                "Server logs",
                tail(inst.getServerLogContents(), 500),
            ]
        )
Example #30
0
 def getClient(self, inst=None):
     if inst or not hasattr(self, 'client'):
         client = pywatchman.client(
             # ASAN-enabled builds can be slower enough that we hit timeouts
             # with the default of 1 second
             timeout=3.0,
             transport=self.transport,
             sendEncoding=self.encoding,
             recvEncoding=self.encoding,
             sockpath=(inst or
                       WatchmanInstance.getSharedInstance()).getSockPath())
         if not inst:
             # only cache the client if it points to the shared instance
             self.client = client
         return client
     return self.client
Example #31
0
def is_hg_installed():
    with open(os.devnull, "wb") as devnull:
        try:
            env = os.environ.copy()
            env["HGPLAIN"] = "1"
            env["WATCHMAN_SOCK"] = (
                WatchmanInstance.getSharedInstance().getSockPath().legacy_sockpath()
            )

            exit_code = subprocess.call(
                ["hg", "--version"], stdout=devnull, stderr=devnull, env=env
            )
            return exit_code == 0
        except OSError as e:
            if e.errno == errno.ENOENT:
                return False
            raise
Example #32
0
    def spawnWatchmanWait(self, cmdArgs):
        wait_script = os.environ.get("WATCHMAN_WAIT_PATH")
        if wait_script:
            args = [wait_script]
        else:
            args = [
                sys.executable,
                os.path.join(os.environ["WATCHMAN_PYTHON_BIN"], "watchman-wait"),
            ]
        args.extend(cmdArgs)

        env = os.environ.copy()
        sock_path = WatchmanInstance.getSharedInstance().getSockPath()
        env["WATCHMAN_SOCK"] = sock_path
        env["PYTHONPATH"] = env["PYWATCHMAN_PATH"]
        return subprocess.Popen(
            args, env=env, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )
Example #33
0
    def spawnWatchmanWait(self, cmdArgs):
        wait_script = os.environ.get("WATCHMAN_WAIT_PATH")
        if wait_script:
            args = [wait_script]
        else:
            args = [
                sys.executable,
                os.path.join(os.environ["WATCHMAN_PYTHON_BIN"], "watchman-wait"),
            ]
        args.extend(cmdArgs)

        env = os.environ.copy()
        sock_path = WatchmanInstance.getSharedInstance().getSockPath()
        env["WATCHMAN_SOCK"] = sock_path
        env["PYTHONPATH"] = env["PYWATCHMAN_PATH"]
        return subprocess.Popen(
            args, env=env, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )
Example #34
0
    def skipIfNoHgRequestIdSupport(self):
        root = self.mkdtemp()
        request_id = "bf8a47014bd1b66103a8ab0aece4be7ada871660"

        env = os.environ.copy()
        env["HGPLAIN"] = "1"
        env["HGREQUESTID"] = request_id
        env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance(
        ).getSockPath()

        subprocess.call(["hg", "init"], env=env, cwd=root)
        subprocess.call(["hg", "log"], env=env, cwd=root)

        try:
            with open(os.path.join(root, ".hg/blackbox.log")) as f:
                if request_id in f.read():
                    return
        except IOError:
            pass

        self.skipTest("HGREQUESTID is not supported")
Example #35
0
    def test_cppclient(self):
        env = os.environ.copy()
        env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance().getSockPath()
        proc = subprocess.Popen(
            TEST_BINARY, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail("Interrupted by SIGINT")
            return

        if status != 0:
            self.fail(
                "Exit status %d\n%s\n%s\n"
                % (status, stdout.decode("utf-8"), stderr.decode("utf-8"))
            )
            return

        self.assertTrue(True, TEST_BINARY)
Example #36
0
    def hg(self, args=None, cwd=None):
        env = dict(os.environ)
        env['HGPLAIN'] = '1'
        env['HGUSER'] = '******'
        env['NOSCMLOG'] = '1'  # disable some instrumentation at FB
        env['WATCHMAN_SOCK'] = \
                WatchmanInstance.getSharedInstance().getSockPath()
        p = subprocess.Popen(
            # we force the extension on.  This is a soft error for
            # mercurial if it is not available, so we also employ
            # the skipIfNoFSMonitor() test above to make sure the
            # environment is sane.
            ['hg', '--config', 'extensions.fsmonitor='] + args,
            env=env,
            cwd=cwd,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception("hg %r failed: %s, %s" % (args, out, err))

        return out, err
Example #37
0
    def hg(self, args=None, cwd=None):
        env = dict(os.environ)
        env['HGPLAIN'] = '1'
        env['HGUSER'] = '******'
        env['NOSCMLOG'] = '1'  # disable some instrumentation at FB
        env['WATCHMAN_SOCK'] = \
                WatchmanInstance.getSharedInstance().getSockPath()
        p = subprocess.Popen(
            # we force the extension on.  This is a soft error for
            # mercurial if it is not available, so we also employ
            # the skipIfNoFSMonitor() test above to make sure the
            # environment is sane.
            ['hg', '--config', 'extensions.fsmonitor='] + args,
            env=env,
            cwd=cwd,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception("hg %r failed: %s, %s" % (args, out, err))

        return out, err
Example #38
0
    def hg(self, args=None, cwd=None):
        env = dict(os.environ)
        env["HGPLAIN"] = "1"
        env["HGUSER"] = "******"
        env["NOSCMLOG"] = "1"  # disable some instrumentation at FB
        env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance().getSockPath()
        p = subprocess.Popen(
            # we force the extension on.  This is a soft error for
            # mercurial if it is not available, so we also employ
            # the skipIfNoFSMonitor() test above to make sure the
            # environment is sane.
            [env.get("EDEN_HG_BINARY", "hg"), "--config", "extensions.fsmonitor="]
            + args,
            env=env,
            cwd=cwd,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception("hg %r failed: %s, %s" % (args, out, err))

        return out, err
Example #39
0
 def resumeWatchman(self):
     WatchmanInstance.getSharedInstance().resume()
Example #40
0
 def setUp(self):
     self.loop = asyncio.get_event_loop()
     sockpath = WatchmanInstance.getSharedInstance().getSockPath()
     self.client = self.loop.run_until_complete(WatchmanClient.from_socket(sockpath))
Example #41
0
 def getSockPath(self):
     return WatchmanInstance.getSharedInstance().getSockPath()
Example #42
0
    def runTest(self):
        env = os.environ.copy()
        env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath()
        proc = subprocess.Popen(
            self.getCommandArgs(),
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail('Interrupted by SIGINT')
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" % (status, stdout, stderr))
            return

        res_pat = re.compile('^(not )?ok (\d+) (.*)$')
        diag_pat = re.compile('^# (.*)$')

        # Now parse the TAP output
        lines = stdout.split('\n')
        # first line is the plan
        try:
            plan = int(lines.pop(0).split('..')[1])
        except Exception as e:
            self.fail(stdout + '\n' + stderr)
            return
        last_test = 0
        diags = None
        for line in lines:
            res = res_pat.match(line)
            if res:
                this_test = int(res.group(2))
                if this_test != last_test + 1:
                    print(stdout, stderr)
                    self.fail('Expected test number %d, got %d' % (
                        last_test + 1,
                        this_test))
                last_test = this_test
                if res.group(1) == 'not ':
                    # Failed
                    msg = line
                    if diags is not None:
                        msg = msg + '\n'.join(diags)
                    self.fail(msg)
                    failed

                diags = None
                continue

            res = diag_pat.match(line)
            if res:
                if diags is None:
                    diags = []
                diags.append(res.group(1))
                continue

            if line != '':
                print('Invalid tap output from %s: %s' %
                      (self.id(), line))

        self.assertEqual(last_test, plan,
                         '%s planned %d but executed %d tests' % (
                             self.id(),
                             plan,
                             last_test))
Example #43
0
    def runTest(self):
        env = os.environ.copy()
        env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance(
        ).getSockPath()
        dotted = os.path.normpath(self.id()).replace(os.sep, '.').replace(
            'tests.integration.', '').replace('.php', '')
        env['TMPDIR'] = os.path.join(tempfile.tempdir, dotted)
        if os.name != 'nt' and len(env['TMPDIR']) > 94:
            self.fail('temp dir name %s is too long for unix domain sockets' %
                      env['TMPDIR'])
        os.mkdir(env['TMPDIR'])
        env['TMP'] = env['TMPDIR']
        env['TEMP'] = env['TMPDIR']
        env['IN_PYTHON_HARNESS'] = '1'
        proc = subprocess.Popen(self.getCommandArgs(),
                                env=env,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail('Interrupted by SIGINT')
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" % (status, stdout, stderr))
            return

        res_pat = re.compile('^(not )?ok (\d+) (.*)$')
        diag_pat = re.compile('^# (.*)$')
        plan_pat = re.compile('^1\.\.(\d+)$')

        # Now parse the TAP output
        lines = stdout.replace('\r\n', '\n').split('\n')
        last_test = 0
        diags = None
        plan = None

        for line in lines:
            res = plan_pat.match(line)
            if res:
                plan = int(res.group(1))
                continue

            res = res_pat.match(line)
            if res:
                this_test = int(res.group(2))
                if this_test != last_test + 1:
                    print(stdout, stderr)
                    self.fail('Expected test number %d, got %d' %
                              (last_test + 1, this_test))
                last_test = this_test
                if res.group(1) == 'not ':
                    # Failed
                    msg = line
                    if diags is not None:
                        msg = msg + '\n' + '\n'.join(diags)
                    self.fail(msg)
                    failed

                diags = None
                continue

            res = diag_pat.match(line)
            if res:
                if diags is None:
                    diags = []
                diags.append(res.group(1))
                continue

            if line != '':
                print('Invalid tap output from %s: %s' % (self.id(), line))

        if plan is None:
            self.fail('no plan was observed')
        else:
            self.assertEqual(
                last_test, plan, '%s planned %d but executed %s tests' %
                (self.id(), plan, last_test))
Example #44
0
 def getSockPath(self):
     return WatchmanInstance.getSharedInstance().getSockPath()
Example #45
0
 def setUp(self):
     self.loop = asyncio.get_event_loop()
     sockpath = WatchmanInstance.getSharedInstance().getSockPath()
     self.client = self.loop.run_until_complete(WatchmanClient.from_socket(sockpath))
Example #46
0
 def resumeWatchman(self):
     WatchmanInstance.getSharedInstance().resume()
Example #47
0
 def getServerLogContents(self):
     """
     Returns the contents of the server log file as an array
     that has already been split by line.
     """
     return WatchmanInstance.getSharedInstance().getServerLogContents().split("\n")
Example #48
0
 def suspendWatchman(self):
     WatchmanInstance.getSharedInstance().suspend()
Example #49
0
    def runTest(self):
        env = os.environ.copy()
        env["WATCHMAN_SOCK"] = WatchmanInstance.getSharedInstance().getSockPath()
        dotted = os.path.normpath(self.id()).replace(os.sep, ".").replace("tests.integration.", "").replace(".php", "")
        env["TMPDIR"] = os.path.join(tempfile.tempdir, dotted)
        if os.name != "nt" and len(env["TMPDIR"]) > 94:
            self.fail("temp dir name %s is too long for unix domain sockets" % env["TMPDIR"])
        os.mkdir(env["TMPDIR"])
        env["IN_PYTHON_HARNESS"] = "1"
        proc = subprocess.Popen(self.getCommandArgs(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail("Interrupted by SIGINT")
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" % (status, stdout, stderr))
            return

        res_pat = re.compile("^(not )?ok (\d+) (.*)$")
        diag_pat = re.compile("^# (.*)$")
        plan_pat = re.compile("^1\.\.(\d+)$")

        # Now parse the TAP output
        lines = stdout.split("\n")
        last_test = 0
        diags = None
        plan = None

        for line in lines:
            res = plan_pat.match(line)
            if res:
                plan = int(res.group(1))
                continue

            res = res_pat.match(line)
            if res:
                this_test = int(res.group(2))
                if this_test != last_test + 1:
                    print(stdout, stderr)
                    self.fail("Expected test number %d, got %d" % (last_test + 1, this_test))
                last_test = this_test
                if res.group(1) == "not ":
                    # Failed
                    msg = line
                    if diags is not None:
                        msg = msg + "\n".join(diags)
                    self.fail(msg)
                    failed

                diags = None
                continue

            res = diag_pat.match(line)
            if res:
                if diags is None:
                    diags = []
                diags.append(res.group(1))
                continue

            if line != "":
                print("Invalid tap output from %s: %s" % (self.id(), line))

        self.assertEqual(last_test, plan, "%s planned %d but executed %s tests" % (self.id(), plan, last_test))
Example #50
0
    def runTest(self):
        env = os.environ.copy()
        env['WATCHMAN_SOCK'] = WatchmanInstance.getSharedInstance().getSockPath()

        def clean_file_name(name):
            name = name.replace(os.sep, '')
            name = name.replace('tests.integration', '')
            name = name.replace('.php', '')
            name = name.replace('_php', '')
            name = name.replace('.runTest', '')
            return name

        dotted = clean_file_name(os.path.normpath(self.id()))
        env['TMPDIR'] = os.path.join(TempDir.get_temp_dir().get_dir(), dotted)
        if os.name != 'nt' and len(env['TMPDIR']) > 94:
            self.fail('temp dir name %s is too long for unix domain sockets' %
                env['TMPDIR'])
        os.mkdir(env['TMPDIR'])
        env['TMP'] = env['TMPDIR']
        env['TEMP'] = env['TMPDIR']
        env['IN_PYTHON_HARNESS'] = '1'
        env['WATCHMAN_PYTHON_BINARY'] = sys.executable
        proc = subprocess.Popen(
            self.getCommandArgs(),
            cwd=env.get('WATCHMAN_SRC_DIR', os.getcwd()),
            env=env,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate()
        status = proc.poll()

        if status == -signal.SIGINT:
            Interrupt.setInterrupted()
            self.fail('Interrupted by SIGINT')
            return

        if status != 0:
            self.fail("Exit status %d\n%s\n%s\n" % (status, stdout, stderr))
            return

        res_pat = re.compile(b'^(not )?ok (\d+) (.*)$')
        diag_pat = re.compile(b'^# (.*)$')
        plan_pat = re.compile(b'^1\.\.(\d+)$')

        # Now parse the TAP output
        lines = stdout.replace(b'\r\n', b'\n').split(b'\n')
        last_test = 0
        diags = None
        plan = None

        for line in lines:
            res = plan_pat.match(line)
            if res:
              plan = int(res.group(1))
              continue

            res = res_pat.match(line)
            if res:
                this_test = int(res.group(2))
                if this_test != last_test + 1:
                    print(stdout, stderr)
                    self.fail('Expected test number %d, got %d' % (
                        last_test + 1,
                        this_test))
                last_test = this_test
                if res.group(1) == b'not ':
                    # Failed
                    msg = line
                    if diags is not None:
                        msg = msg + b'\n' + b'\n'.join(diags)
                    self.fail(msg.decode('utf-8'))
                    failed

                diags = None
                continue

            res = diag_pat.match(line)
            if res:
                if diags is None:
                    diags = []
                diags.append(res.group(1))
                continue

            if line != b'':
                print('Invalid tap output from %s: %s' %
                      (self.id(), line))

        if plan is None:
            self.fail('no plan was observed')
        else:
            self.assertEqual(last_test, plan,
                         '%s planned %d but executed %s tests' % (
                             self.id(),
                             plan,
                             last_test))
Example #51
0
 def suspendWatchman(self):
     WatchmanInstance.getSharedInstance().suspend()