Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Configurable port for parallel testing #1

Closed
wants to merge 1 commit into from

1 participant

@chriswdb

This patch makes the port used for webkit configurable by environment variable; this is useful for running multiple webkits during parallelized testing, e.g.:

Before do
  if Capybara.current_driver == :webkit
    # Use different ports for parallel testing
    if ENV['TEST_ENV_NUMBER']
      ENV['CAPYBARA_WEBKIT_PORT'] = (9200 + ENV['TEST_ENV_NUMBER'].to_i).to_s
    end
  end
end
@chriswdb chriswdb closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 2 deletions.
  1. +1 −1  lib/capybara/driver/webkit/browser.rb
  2. +17 −1 src/Server.cpp
View
2  lib/capybara/driver/webkit/browser.rb
@@ -76,7 +76,7 @@ def connect
end
def attempt_connect
- @socket = @socket_class.open("localhost", 9200)
+ @socket = @socket_class.open("localhost", ENV['CAPYBARA_WEBKIT_PORT'] || 9200)
rescue Errno::ECONNREFUSED
end
View
18 src/Server.cpp
@@ -4,14 +4,30 @@
#include <QTcpServer>
+#include <cerrno>
+
Server::Server(QObject *parent) : QObject(parent) {
m_tcp_server = new QTcpServer(this);
m_page = new WebPage(this);
}
bool Server::start() {
+ unsigned short port = 9200;
+ long l;
+ char *env_port = getenv("CAPYBARA_WEBKIT_PORT");
+
connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(handleConnection()));
- return m_tcp_server->listen(QHostAddress::Any, 9200);
+
+ if (env_port) {
+ errno = 0;
+ l = strtol(env_port, NULL, 10); // Base 10
+ if (errno == 0) {
+ port = l;
+ }
+ }
+ printf("Starting webkit on port %hu.\n", port);
+
+ return m_tcp_server->listen(QHostAddress::Any, port);
}
void Server::handleConnection() {
Something went wrong with that request. Please try again.