@VisibleForTesting protected void terminateIdleTest() { for (TestSlot testSlot : getTestSlots()) { if (testSlot.getSession() != null) { long executionTime = (System.currentTimeMillis() - testSlot.getLastSessionStart()) / 1000; ga.testEvent(DockerSeleniumRemoteProxy.class.getName(), testSlot.getSession().getRequestedCapabilities().toString(), executionTime); getRegistry().forceRelease(testSlot, SessionTerminationReason.ORPHAN); } } }
@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); }
@VisibleForTesting public void terminateIdleSessions() { String currentName = Thread.currentThread().getName(); Thread.currentThread().setName(getProxyName()); for (TestSlot testSlot : getTestSlots()) { if (testSlot.getSession() != null && (testSlot.getSession().getInactivityTime() >= (getMaxTestIdleTime() * 1000L))) { long executionTime = (System.currentTimeMillis() - testSlot.getLastSessionStart()) / 1000; getGa().testEvent(getProxyClassName(), testSlot.getSession().getRequestedCapabilities().toString(), executionTime); // If it is null, it is probable that the test never reached the cloud service. if (testSlot.getSession().getExternalKey() != null) { addTestToDashboard(testSlot.getSession().getExternalKey().getKey(), false); } getRegistry().forceRelease(testSlot, SessionTerminationReason.ORPHAN); logger.warn("Releasing slot and terminating session due to inactivity."); } } 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); }