@Override public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { String currentName = configureThreadName(); super.afterCommand(session, request, response); LOGGER.debug("lastCommand: {} - executing...", request.getMethod(), request.getPathInfo()); if (request instanceof WebDriverRequest && "POST".equalsIgnoreCase(request.getMethod())) { WebDriverRequest seleniumRequest = (WebDriverRequest) request; if (RequestType.START_SESSION.equals(seleniumRequest.getRequestType())) { ExternalSessionKey externalKey = Optional.ofNullable(session.getExternalKey()) .orElse(new ExternalSessionKey("[No external key present]")); LOGGER.debug(String.format("Test session started with internal key %s and external key %s assigned to remote %s.", session.getInternalKey(), externalKey, getId())); LOGGER.debug("Test session started with internal key {} and external key {} assigned to remote.", session.getInternalKey(), externalKey); videoRecording(DockerSeleniumContainerAction.START_RECORDING); } } this.lastCommandTime = System.currentTimeMillis(); setThreadName(currentName); }
/** * Ends this test session for the hub, releasing the resources in the hub / registry. It does not * release anything on the remote. The resources are released in a separate thread, so the call * returns immediately. It allows release with long duration not to block the test while the hub is * releasing the resource. * * @param session The session to terminate * @param reason the reason for termination */ public void terminate(final TestSession session, final SessionTerminationReason reason) { // Thread safety reviewed String remoteName = ""; if (session.getSlot().getProxy() instanceof DockerSeleniumRemoteProxy) { remoteName = ((DockerSeleniumRemoteProxy)session.getSlot().getProxy()).getRegistration().getContainerId(); } String internalKey = Optional.ofNullable(session.getInternalKey()).orElse("No internal key"); ExternalSessionKey externalKey = Optional.ofNullable(session.getExternalKey()).orElse(new ExternalSessionKey("No external key was assigned")); new Thread(() -> _release(session.getSlot(), reason), "Terminate Test Session int id: [" + internalKey + "] ext id: [" + externalKey + "] container: [" + remoteName + "]").start(); }
@Override public void afterSession(TestSession session) { String currentName = configureThreadName(); try { // This means that the shutdown command was triggered before receiving this afterSession command if (!TestInformation.TestStatus.TIMEOUT.equals(testInformation.getTestStatus())) { long executionTime = (System.currentTimeMillis() - session.getSlot().getLastSessionStart()) / 1000; ga.testEvent(DockerSeleniumRemoteProxy.class.getName(), session.getRequestedCapabilities().toString(), executionTime); if (isTestSessionLimitReached()) { LOGGER.info("Session {} completed. Node should shutdown soon...", session.getInternalKey()); cleanupNode(true); } else { LOGGER.info("Session {} completed. Cleaning up node for reuse, used {} of max {} sessions", session.getInternalKey(), getAmountOfExecutedTests(), maxTestSessions); cleanupNode(false); } } } catch (Exception e) { LOGGER.warn(e.toString(), e); } finally { super.afterSession(session); } setThreadName(currentName); }
private boolean takeRequestHandler(RequestHandler handler) { final TestSession session = proxies.getNewSession(handler.getRequest().getDesiredCapabilities()); final boolean sessionCreated = session != null; if (sessionCreated) { String remoteName = session.getSlot().getProxy().getId(); long timeToAssignProxy = System.currentTimeMillis() - handler.getRequest().getCreationTime(); LOG.info("Test session with internal key {} assigned to remote ({}) after {} seconds ({} ms).", session.getInternalKey(), remoteName, timeToAssignProxy / 1000, timeToAssignProxy); seleniumTestSessionStartLatency.observe(timeToAssignProxy / Collector.MILLISECONDS_PER_SECOND); seleniumTestSessionsWaiting.dec(); activeTestSessions.add(session); handler.bindSession(session); } return sessionCreated; }
String seleniumSessionId = newSession.getExternalKey() != null ? newSession.getExternalKey().getKey() : newSession.getInternalKey(); if (testName.isEmpty()) { testName = seleniumSessionId;