Skip to content

Commit

Permalink
v3 selenium server, enable -browserTimeout and -timeout (also aliased…
Browse files Browse the repository at this point in the history
… to -sessionTimeout) command line arguments

delete empty test
make static final strings out of the magic strings
  • Loading branch information
lukeis committed Mar 9, 2016
1 parent 6bef2c6 commit 7308f86
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class CommandLineArgs {

@Parameter(
names = "-browserTimeout",
description = "Number of seconds a browser is allowed to hang (0 means indefinite).")
int browserTimeout;
description = "Number of seconds a browser is allowed to hang (0 means indefinite) while a command is running (example: driver.get(url)). If set, must be greater than or equal to 60. When the timeout is reached while a command is processing, the session will quit.")
int browserTimeout = 0;

@Parameter(
names = "-jettyThreads",
Expand All @@ -46,7 +46,7 @@ public class CommandLineArgs {
int port = 4444;

@Parameter(
names = "-timeout",
description = "Number of seconds we should allow a client to be idle (0 means indefinite).")
int timeout;
names = {"-timeout", "-sessionTimeout"},
description = "Number of seconds we should allow a client to be idle (0 means indefinite) between commands. Session will quit when timeout is reached. Default is 1800 (30 minutes).")
int timeout = 1800;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

public class DriverServlet extends HttpServlet {
public static final String SESSIONS_KEY = DriverServlet.class.getName() + ".sessions";
public static final String SESSION_TIMEOUT_PARAMETER = "webdriver.server.session.timeout";
public static final String BROWSER_TIMEOUT_PARAMETER = "webdriver.server.browser.timeout";

private static final String CROSS_DOMAIN_RPC_PATH = "/xdrpc";

Expand Down Expand Up @@ -81,8 +83,8 @@ public void init() throws ServletException {
DriverSessions driverSessions = sessionsSupplier.get();
commandHandler = new JsonHttpCommandHandler(driverSessions, logger);

long sessionTimeOutInMs = getValueToUseInMs("webdriver.server.session.timeout", 1800);
long browserTimeoutInMs = getValueToUseInMs("webdriver.server.browser.timeout", 0);
long sessionTimeOutInMs = getValueToUseInMs(SESSION_TIMEOUT_PARAMETER, 1800);
long browserTimeoutInMs = getValueToUseInMs(BROWSER_TIMEOUT_PARAMETER, 0);

if (sessionTimeOutInMs > 0 || browserTimeoutInMs > 0) {
createSessionCleaner(logger, driverSessions, sessionTimeOutInMs, browserTimeoutInMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class SeleniumServer implements GridNodeServer {
private int threadCount;
private Server server;
private DefaultDriverSessions driverSessions;
private int browserTimeout = 0;
private int sessionTimeout = 0;

private Thread shutDownHook;
/**
Expand Down Expand Up @@ -70,10 +72,18 @@ private void addRcSupport(ServletContextHandler handler) {
}
}

private void setThreadCount(int threadCount) {
public void setThreadCount(int threadCount) {
this.threadCount = threadCount;
}

public void setBrowserTimeout(int browserTimeout) {
this.browserTimeout = browserTimeout;
}

public void setSessionTimeout(int timeout) {
this.sessionTimeout = timeout;
}

public void boot() {
if (threadCount > 0) {
server = new Server(new QueuedThreadPool(threadCount));
Expand All @@ -87,6 +97,14 @@ public void boot() {
handler.setAttribute(DriverServlet.SESSIONS_KEY, driverSessions);
handler.setContextPath("/");
handler.addServlet(DriverServlet.class, "/wd/hub/*");

if (browserTimeout > 0) {
handler.setInitParameter(DriverServlet.BROWSER_TIMEOUT_PARAMETER, String.valueOf(browserTimeout));
}
if (sessionTimeout > 0) {
handler.setInitParameter(DriverServlet.SESSION_TIMEOUT_PARAMETER, String.valueOf(sessionTimeout));
}

addRcSupport(handler);

server.setHandler(handler);
Expand Down Expand Up @@ -191,6 +209,8 @@ public static void main(String[] argv) {

SeleniumServer server = new SeleniumServer(args.port);
server.setThreadCount(args.jettyThreads);
server.setBrowserTimeout(args.browserTimeout);
server.setSessionTimeout(args.timeout);
server.boot();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ private HttpContext createWebDriverRemoteContext(DriverSessions webDriverSession
} else {
browserTimeout /= 1000;
}
webdriverContext.setInitParameter("webdriver.server.session.timeout", String.valueOf(sessionTimeout));
webdriverContext.setInitParameter("webdriver.server.browser.timeout", String.valueOf(browserTimeout));
webdriverContext.setInitParameter(DriverServlet.SESSION_TIMEOUT_PARAMETER, String.valueOf(sessionTimeout));
webdriverContext.setInitParameter(DriverServlet.BROWSER_TIMEOUT_PARAMETER, String.valueOf(browserTimeout));
webdriverContext.setAttribute(DriverServlet.SESSIONS_KEY, webDriverSessions);
webdriverContext.setContextPath("/wd");
ServletHandler handler = new ServletHandler();
Expand Down
29 changes: 0 additions & 29 deletions java/server/test/org/openqa/grid/e2e/utils/TestHttpServlet.java

This file was deleted.

0 comments on commit 7308f86

Please sign in to comment.