/** * 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 afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) { String currentName = Thread.currentThread().getName(); Thread.currentThread().setName(getProxyName()); if (request instanceof WebDriverRequest && "DELETE".equalsIgnoreCase(request.getMethod())) { WebDriverRequest seleniumRequest = (WebDriverRequest) request; if (seleniumRequest.getRequestType().equals(RequestType.STOP_SESSION)) { long executionTime = (System.currentTimeMillis() - session.getSlot().getLastSessionStart()) / 1000; getGa().testEvent(getProxyClassName(), session.getRequestedCapabilities().toString(), executionTime); addTestToDashboard(session.getExternalKey().getKey(), true); } } super.afterCommand(session, request, response); Thread.currentThread().setName(currentName); }
@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 screenResolution = getCapability(newSession.getSlot().getCapabilities(), ZaleniumCapabilityType.SCREEN_RESOLUTION, "N/A"); String browserVersion = getCapability(newSession.getSlot().getCapabilities(), CapabilityType.VERSION, ""); String timeZone = getCapability(newSession.getSlot().getCapabilities(), ZaleniumCapabilityType.TIME_ZONE, "N/A"); testInformation = new TestInformation.TestInformationBuilder() .withTestName(testName)
public SessionInfoBean(TestSession session) { requestedCapabilities = session.getRequestedCapabilities(); nodeCapabilities = session.getSlot().getCapabilities(); }
public URL getRemoteHostForSession(String sessionId) { for (TestSession activeSession : registry.getActiveSessions()) { if (sessionId.equals(activeSession.getExternalKey().getKey())) { return activeSession.getSlot().getProxy().getRemoteHost(); } } throw new IllegalArgumentException("Invalid sessionId. No active session is present for id:" + sessionId); }