コード例 #1
0
    def test_binding(self):
        """
        If a specific port is requested, and a server is already started in the
        requested port, then the layer setup fails.
        """
        s = socket.socket()
        try:
            s.bind((socket.gethostbyname(""), 4225))
        except socket.error:
            s.close()
            s = None
            raise

        if "JSTESTDRIVER_SERVER" in os.environ:
            del os.environ["JSTESTDRIVER_SERVER"]
        os.environ["JSTESTDRIVER_PORT"] = "4225"
        try:
            try:
                JsTestDriverLayer.setUp()
            except ValueError, e:
                msg = str(e)
                self.assertIn(
                    "Failed to execute JsTestDriver server on port 4225", msg)
                self.assertIn(
                    "java.lang.RuntimeException: java.net.BindException: "
                    "Address already in use", msg)
            else:
コード例 #2
0
    def test_server_timeout(self):
        """
        If we don't see that the server is started before the timeout, a
        ValueError is raised, even if the process is still running.
        """
        timeout = 1
        os.environ["JSTESTDRIVER_CAPTURE_TIMEOUT"] = "%s" % timeout
        os.environ["JSTESTDRIVER_BROWSER"] = ""
        if "JSTESTDRIVER_SERVER" in os.environ:
            del os.environ["JSTESTDRIVER_SERVER"]
        os.environ["JSTESTDRIVER_PORT"] = "4225"

        mock_proc = self.mock_popen()
        mock_file = self.mock_builtin_open()

        with self.mocker.order():
            mock_time = self.mocker.replace("time.time")
            # The first time is to initialize the start time.
            mock_time()
            start_time = 0
            self.mocker.result(start_time)

            # The second time is to check if the timeout is exceeded in
            # the while loop.
            mock_time()
            self.mocker.result(start_time)
            # Go one iteration of the while loop, reporting the server
            # is starting up.
            mock_proc.poll()
            self.mocker.result(None)
            mock_file.readline()
            self.mocker.result("INFO: still starting")

            # Trigger a timeout.
            mock_time()
            self.mocker.result(start_time + timeout + 1)

            # The opened file is closed.
            mock_file.close()
            self.mocker.result(None)

            # Last check whether the server is still running.
            mock_proc.poll()
            self.mocker.result(None)

            # Since the server is running, it gets terminated.
            mock_proc.terminate()
            self.mocker.result(None)
            mock_proc.wait()
            self.mocker.result(None)

        self.mocker.replay()

        try:
            JsTestDriverLayer.setUp()
        except ValueError, e:
            msg = str(e)
            self.assertIn(
                "Failed to execute JsTestDriver server in 1 seconds"
                " on port 4225", msg)
コード例 #3
0
    def test_server_fail(self):
        """
        If we a poll of the process returns a non-None value while we
        are waiting, we report that server couldn't be started.
        """
        mock_proc = self.mock_popen()
        mock_file = self.mock_builtin_open()

        with self.mocker.order():
            mock_time = self.mocker.replace("time.time")
            # The first time is to initialize the start time.
            mock_time()
            start_time = 0
            self.mocker.result(start_time)

            # The second time is to check if the timeout is exceeded in
            # the while loop.
            mock_time()
            self.mocker.result(start_time)
            # Go one iteration of the while loop, reporting the server
            # is starting up.
            mock_proc.poll()
            self.mocker.result(None)
            mock_file.readline()
            self.mocker.result("INFO: still starting")

            # Go another iteration of the while loop, reporting the
            # server failed to start up.
            mock_time()
            self.mocker.result(start_time)
            mock_proc.poll()
            self.mocker.result(1)

            # The opened file is closed.
            mock_file.close()
            self.mocker.result(None)

        self.mocker.replay()

        if "JSTESTDRIVER_SERVER" in os.environ:
            del os.environ["JSTESTDRIVER_SERVER"]
        os.environ["JSTESTDRIVER_PORT"] = "4225"

        try:
            JsTestDriverLayer.setUp()
        except ValueError, e:
            msg = str(e)
            self.assertIn(
                "Failed to execute JsTestDriver server on port 4225", msg)
コード例 #4
0
    def test_wait_for_server_startup(self):
        """
        Even if we don't wait for the browser to be captured, we wait
        for the server to start up.
        """
        mock_proc = self.mock_popen()
        mock_file = self.mock_builtin_open()

        with self.mocker.order():
            mock_time = self.mocker.replace("time.time")
            # The first time is to initialize the start time.
            mock_time()
            start_time = 0
            self.mocker.result(start_time)

            # The second time is to check if the timeout is exceeded in
            # the while loop.
            mock_time()
            self.mocker.result(start_time)
            # Go one iteration of the while loop, reporting the server
            # has started.
            mock_proc.poll()
            self.mocker.result(None)
            mock_file.readline()
            self.mocker.result("INFO: Finished action run.")

            # The opened file is closed.
            mock_file.close()
            self.mocker.result(None)

            # Last check to make sure the server is running ok.
            mock_proc.poll()
            self.mocker.result(None)

        self.mocker.replay()

        os.environ["JSTESTDRIVER_BROWSER"] = ""
        if "JSTESTDRIVER_SERVER" in os.environ:
            del os.environ["JSTESTDRIVER_SERVER"]
        os.environ["JSTESTDRIVER_PORT"] = "4225"

        JsTestDriverLayer.setUp()
        self.assertEqual(
            "http://localhost:4225", os.environ["JSTESTDRIVER_SERVER"])
コード例 #5
0
    def test_timeout_browser(self):
        """
        If we fail to capture a browser within the specified timeout, an
        appropriate message is shown. In order to test that, let's set the
        browser to be empty so that the JsTestDriver server doesn't capture a
        browser automatically, and set the timeout to a very short time so we
        don't wait for too long.
        """
        os.environ["JSTESTDRIVER_CAPTURE_TIMEOUT"] = "1"
        os.environ["JSTESTDRIVER_BROWSER"] = "not-a-browser"
        if "JSTESTDRIVER_SERVER" in os.environ:
            del os.environ["JSTESTDRIVER_SERVER"]
        os.environ["JSTESTDRIVER_PORT"] = "4225"

        try:
            try:
                JsTestDriverLayer.setUp()
            except ValueError, e:
                msg = str(e)
                self.assertIn("Failed to capture a browser in 1 seconds", msg)
            else:
コード例 #6
0
            del os.environ["JSTESTDRIVER_SERVER"]
        os.environ["JSTESTDRIVER_PORT"] = "4225"
        try:
            try:
                JsTestDriverLayer.setUp()
            except ValueError, e:
                msg = str(e)
                self.assertIn(
                    "Failed to execute JsTestDriver server on port 4225", msg)
                self.assertIn(
                    "java.lang.RuntimeException: java.net.BindException: "
                    "Address already in use", msg)
            else:
                self.fail("ValueError not raised")
        finally:
            JsTestDriverLayer.tearDown()
            s.close()

    def test_connection_error(self):
        """
        An appropriate message is printed when the JsTestDriver client cannot
        connect to a server.
        """
        runner = getattr(testrunner, "run_internal", testrunner.run)
        root_directory = os.path.abspath(
            dirname(dirname(dirname(dirname(__file__)))))
        defaults = [
            "--path", root_directory,
            "-m", "lazr.testing.tests.test_js",
            "-t", "JsTestDriverSelfTest"]
        arguments = [