コード例 #1
0
ファイル: test_nodejs.py プロジェクト: Stevenzwzhai/watchman
    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())
コード例 #2
0
ファイル: test_nodejs.py プロジェクト: zphj1987/watchman
    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())
コード例 #3
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)
コード例 #4
0
ファイル: NodeTests.py プロジェクト: 1514louluo/watchman
    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)
コード例 #5
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)
コード例 #6
0
ファイル: NodeTests.py プロジェクト: runt18/watchman
    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)
コード例 #7
0
ファイル: test_nodejs.py プロジェクト: danez/watchman
    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())
コード例 #8
0
 def _waitForCheck(self, cond, res_check, timeout):
     deadline = time.time() + timeout
     res = None
     while time.time() < deadline:
         Interrupt.checkInterrupt()
         res = cond()
         if res_check(res):
             return [True, res]
         time.sleep(0.03)
     return [False, res]
コード例 #9
0
 def _waitForCheck(self, cond, res_check, timeout):
     deadline = time.time() + timeout
     res = None
     while time.time() < deadline:
         Interrupt.checkInterrupt()
         res = cond()
         if res_check(res):
             return [True, res]
         time.sleep(0.03)
     return [False, res]
コード例 #10
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())
コード例 #11
0
ファイル: runtests.py プロジェクト: exponentjs/watchman
def runner():
    global results_queue
    global tests_queue

    try:
        # Start up a shared watchman instance for the tests.
        inst = WatchmanInstance.Instance()
        inst.start()
        # Allow tests to locate this default instance
        WatchmanInstance.setSharedInstance(inst)
    except Exception as e:
        print('This is going to suck:', e)
        return

    while True:
        test = tests_queue.get()
        try:
            if test == 'terminate':
                break

            if Interrupt.wasInterrupted():
                continue

            try:
                result = Result()
                test.run(result)
                results_queue.put(result)
            except Exception as e:
                print(e)

        finally:
            tests_queue.task_done()

    inst.stop()
コード例 #12
0
def runner():
    global results_queue
    global tests_queue

    try:
        # Start up a shared watchman instance for the tests.
        inst = WatchmanInstance.Instance()
        inst.start()
        # Allow tests to locate this default instance
        WatchmanInstance.setSharedInstance(inst)
    except Exception as e:
        print('This is going to suck:', e)
        return

    while True:
        test = tests_queue.get()
        try:
            if test == 'terminate':
                break

            if Interrupt.wasInterrupted():
                continue

            try:
                result = Result()
                test.run(result)
                results_queue.put(result)
            except Exception as e:
                print(e)

        finally:
            tests_queue.task_done()

    inst.stop()
コード例 #13
0
    def waitForSub(self, name, root, accept=None, timeout=10, remove=True):
        client = self.getClient()

        def default_accept(dat):
            return True

        if accept is None:
            accept = default_accept

        deadline = time.time() + timeout
        while time.time() < deadline:
            Interrupt.checkInterrupt()
            sub = self.getSubscription(name, root=root, remove=False)
            if sub is not None:
                res = accept(sub)
                if res:
                    return self.getSubscription(name, root=root, remove=remove)
            # wait for more data
            client.setTimeout(deadline - time.time())
            client.receive()

        return None
コード例 #14
0
ファイル: WatchmanTestCase.py プロジェクト: zfis/watchman
    def waitForSub(self, name, root, accept=None, timeout=10, remove=True):
        client = self.getClient()

        def default_accept(dat):
            return True

        if accept is None:
            accept = default_accept

        deadline = time.time() + timeout
        while time.time() < deadline:
            Interrupt.checkInterrupt()
            sub = self.getSubscription(name, root=root, remove=False)
            if sub is not None:
                res = accept(sub)
                if res:
                    return self.getSubscription(name, root=root, remove=remove)
            # wait for more data
            client.setTimeout(deadline - time.time())
            client.receive()

        return None
コード例 #15
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)
コード例 #16
0
def runner():
    global results_queue
    global tests_queue

    broken = False
    try:
        # Start up a shared watchman instance for the tests.
        inst = WatchmanInstance.Instance({
            "watcher": args.watcher
        }, debug_watchman=args.debug_watchman)
        inst.start()
        # Allow tests to locate this default instance
        WatchmanInstance.setSharedInstance(inst)
    except Exception as e:
        print('while starting watchman: %s' % str(e))
        traceback.print_exc()
        broken = True

    while not broken:
        test = tests_queue.get()
        try:
            if test == 'terminate':
                break

            if Interrupt.wasInterrupted() or broken:
                continue

            try:
                result = Result()
                test.run(result)
                results_queue.put(result)
            except Exception as e:
                print(e)

        finally:
            tests_queue.task_done()

    if not broken:
        inst.stop()
コード例 #17
0
def runner():
    global results_queue
    global tests_queue

    broken = False
    try:
        # Start up a shared watchman instance for the tests.
        inst = WatchmanInstance.Instance({
            "watcher": args.watcher
        }, debug_watchman=args.debug_watchman)
        inst.start()
        # Allow tests to locate this default instance
        WatchmanInstance.setSharedInstance(inst)
    except Exception as e:
        print('while starting watchman: %s' % str(e))
        traceback.print_exc()
        broken = True

    while not broken:
        test = tests_queue.get()
        try:
            if test == 'terminate':
                break

            if Interrupt.wasInterrupted() or broken:
                continue

            try:
                result = Result()
                test.run(result)
                results_queue.put(result)
            except Exception as e:
                print(e)

        finally:
            tests_queue.task_done()

    if not broken:
        inst.stop()
コード例 #18
0
def runner():
    global results_queue
    global tests_queue

    broken = False
    try:
        # Start up a shared watchman instance for the tests.
        inst = WatchmanInstance.Instance({"watcher": args.watcher},
                                         debug_watchman=args.debug_watchman)
        inst.start()
        # Allow tests to locate this default instance
        WatchmanInstance.setSharedInstance(inst)

        if has_asyncio:
            # Each thread will have its own event loop
            asyncio.set_event_loop(asyncio.new_event_loop())

    except Exception as e:
        print('while starting watchman: %s' % str(e))
        traceback.print_exc()
        broken = True

    while not broken:
        test = tests_queue.get()
        try:
            if test == 'terminate':
                break

            if Interrupt.wasInterrupted() or broken:
                continue

            result = None
            for attempt in range(0, args.retry_flaky + 1):
                try:
                    result = Result()
                    result.setAttemptNumber(attempt)

                    if hasattr(test, 'setAttemptNumber'):
                        test.setAttemptNumber(attempt)

                    test.run(result)

                    if hasattr(test, 'setAttemptNumber') and \
                            not result.wasSuccessful():
                        # Facilitate retrying this possibly flaky test
                        continue

                    break
                except Exception as e:
                    print(e)

                    if hasattr(test, 'setAttemptNumber') and \
                            not result.wasSuccessful():
                        # Facilitate retrying this possibly flaky test
                        continue

            if not result.wasSuccessful() and \
                    'TRAVIS' in os.environ and \
                    hasattr(test, 'dumpLogs'):
                test.dumpLogs()

            results_queue.put(result)

        finally:
            tests_queue.task_done()

    if not broken:
        inst.stop()
コード例 #19
0
 def shouldStop(self):
     if Interrupt.wasInterrupted():
         return True
     return super(Result, self).shouldStop()
コード例 #20
0
def interrupt_handler(signo, frame):
    Interrupt.setInterrupted()
コード例 #21
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))
コード例 #22
0
ファイル: runtests.py プロジェクト: aweeraman/watchman
def runner():
    global results_queue
    global tests_queue

    broken = False
    try:
        # Start up a shared watchman instance for the tests.
        inst = WatchmanInstance.Instance({"watcher": args.watcher},
                                         debug_watchman=args.debug_watchman)
        inst.start()
        # Allow tests to locate this default instance
        WatchmanInstance.setSharedInstance(inst)

        if has_asyncio:
            # Each thread will have its own event loop
            asyncio.set_event_loop(asyncio.new_event_loop())

    except Exception as e:
        print("while starting watchman: %s" % str(e))
        traceback.print_exc()
        broken = True

    while not broken:
        test = tests_queue.get()
        try:
            if test == "terminate":
                break

            if Interrupt.wasInterrupted() or broken:
                continue

            result = None
            for attempt in range(0, args.retry_flaky + 1):
                # Check liveness of the server
                try:
                    client = pywatchman.client(timeout=3.0,
                                               sockpath=inst.getSockPath())
                    client.query("version")
                    client.close()
                except Exception as exc:
                    print(
                        "Failed to connect to watchman server: %s; starting a new one"
                        % exc)

                    try:
                        inst.stop()
                    except Exception:
                        pass

                    try:
                        inst = WatchmanInstance.Instance(
                            {"watcher": args.watcher},
                            debug_watchman=args.debug_watchman,
                        )
                        inst.start()
                        # Allow tests to locate this default instance
                        WatchmanInstance.setSharedInstance(inst)
                    except Exception as e:
                        print("while starting watchman: %s" % str(e))
                        traceback.print_exc()
                        broken = True
                        continue

                try:
                    result = Result()
                    result.setAttemptNumber(attempt)

                    if hasattr(test, "setAttemptNumber"):
                        test.setAttemptNumber(attempt)

                    test.run(result)

                    if hasattr(
                            test,
                            "setAttemptNumber") and not result.wasSuccessful():
                        # Facilitate retrying this possibly flaky test
                        continue

                    break
                except Exception as e:
                    print(e)

                    if hasattr(
                            test,
                            "setAttemptNumber") and not result.wasSuccessful():
                        # Facilitate retrying this possibly flaky test
                        continue

            if (not result.wasSuccessful() and "TRAVIS" in os.environ
                    and hasattr(test, "dumpLogs")):
                test.dumpLogs()

            results_queue.put(result)

        finally:
            tests_queue.task_done()

    if not broken:
        inst.stop()
コード例 #23
0
ファイル: runtests.py プロジェクト: facebook/watchman
def runner():
    global results_queue
    global tests_queue

    broken = False
    try:
        # Start up a shared watchman instance for the tests.
        inst = WatchmanInstance.Instance(
            {"watcher": args.watcher}, debug_watchman=args.debug_watchman
        )
        inst.start()
        # Allow tests to locate this default instance
        WatchmanInstance.setSharedInstance(inst)

        if has_asyncio:
            # Each thread will have its own event loop
            asyncio.set_event_loop(asyncio.new_event_loop())

    except Exception as e:
        print("while starting watchman: %s" % str(e))
        traceback.print_exc()
        broken = True

    while not broken:
        test = tests_queue.get()
        try:
            if test == "terminate":
                break

            if Interrupt.wasInterrupted() or broken:
                continue

            result = None
            for attempt in range(0, args.retry_flaky + 1):
                # Check liveness of the server
                try:
                    client = pywatchman.client(timeout=3.0, sockpath=inst.getSockPath())
                    client.query("version")
                    client.close()
                except Exception as exc:
                    print(
                        "Failed to connect to watchman server: %s; starting a new one"
                        % exc
                    )

                    try:
                        inst.stop()
                    except Exception:
                        pass

                    try:
                        inst = WatchmanInstance.Instance(
                            {"watcher": args.watcher},
                            debug_watchman=args.debug_watchman,
                        )
                        inst.start()
                        # Allow tests to locate this default instance
                        WatchmanInstance.setSharedInstance(inst)
                    except Exception as e:
                        print("while starting watchman: %s" % str(e))
                        traceback.print_exc()
                        broken = True
                        continue

                try:
                    result = Result()
                    result.setAttemptNumber(attempt)

                    if hasattr(test, "setAttemptNumber"):
                        test.setAttemptNumber(attempt)

                    test.run(result)

                    if hasattr(test, "setAttemptNumber") and not result.wasSuccessful():
                        # Facilitate retrying this possibly flaky test
                        continue

                    break
                except Exception as e:
                    print(e)

                    if hasattr(test, "setAttemptNumber") and not result.wasSuccessful():
                        # Facilitate retrying this possibly flaky test
                        continue

            if (
                not result.wasSuccessful()
                and "TRAVIS" in os.environ
                and hasattr(test, "dumpLogs")
            ):
                test.dumpLogs()

            results_queue.put(result)

        finally:
            tests_queue.task_done()

    if not broken:
        inst.stop()
コード例 #24
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))
コード例 #25
0
ファイル: test_php.py プロジェクト: danez/watchman
    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))
コード例 #26
0
ファイル: Events.py プロジェクト: TheQYD/cobblr
def CheckInterruptEvents():
    """Checks for any interrupts."""
    if SystemState.interrupt_queue.empty() is False:
        interrupt_args = SystemState.interrupt_queue.get()
        Interrupt.ProcessInterruptEvents(interrupt_args)
コード例 #27
0
ファイル: runtests.py プロジェクト: Adjyoucmp/watchman
 def shouldStop(self):
     if Interrupt.wasInterrupted():
         return True
     return super(Result, self).shouldStop()
コード例 #28
0
ファイル: runtests.py プロジェクト: Adjyoucmp/watchman
def interrupt_handler(signo, frame):
    Interrupt.setInterrupted()
コード例 #29
0
ファイル: WatchmanTapTests.py プロジェクト: kwlzn/watchman
    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))