/** * 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(); }
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; }
public SeleniumTestSlot(TestSlot testSlot) { RemoteProxy proxy = testSlot.getProxy(); host = proxy.getRemoteHost(); capabilities = toCapabilities(testSlot); isReserved = testSlot.getSession() != null; }
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); }
public Collection<SeleniumTestSlotGroup> call() { Map<URL, SeleniumTestSlotGroup> groups = new HashMap<URL, SeleniumTestSlotGroup>(); if (HubHolder.getHub() == null) { return Collections.emptyList(); } GridRegistry registry = HubHolder.getHub().getRegistry(); if (registry != null) { for (RemoteProxy proxy : registry.getAllProxies()) { for (TestSlot slot : proxy.getTestSlots()) { URL host = slot.getProxy().getRemoteHost(); SeleniumTestSlotGroup grp = groups.get(host); if (grp == null) { grp = new SeleniumTestSlotGroup(host); groups.put(host, grp); } grp.addTestSlot(new SeleniumTestSlot(slot)); } } } List<SeleniumTestSlotGroup> values = new ArrayList<SeleniumTestSlotGroup>(groups.values()); Collections.sort(values); return values; } });