Skip to content

Commit

Permalink
Merge branch 'trunk' into renovate/io.lettuce-lettuce-core-6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
VietND96 authored Jan 2, 2025
2 parents 2fc15ce + 334cfaa commit 3c113b3
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 56 deletions.
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bazel_dep(name = "rules_dotnet", version = "0.17.5")
bazel_dep(name = "rules_java", version = "7.12.4")
bazel_dep(name = "rules_jvm_external", version = "6.6")
bazel_dep(name = "rules_nodejs", version = "6.3.2")
bazel_dep(name = "rules_oci", version = "1.7.6")
bazel_dep(name = "rules_oci", version = "1.8.0")
bazel_dep(name = "rules_pkg", version = "0.10.1")
bazel_dep(name = "rules_python", version = "0.33.0")
bazel_dep(name = "rules_proto", version = "6.0.2")
Expand Down Expand Up @@ -173,14 +173,14 @@ maven.install(
"com.github.spotbugs:spotbugs:4.8.6",
"com.github.stephenc.jcip:jcip-annotations:1.0-1",
"com.google.code.gson:gson:2.11.0",
"com.google.guava:guava:33.3.1-jre",
"com.google.guava:guava:33.4.0-jre",
"com.google.auto:auto-common:1.2.2",
"com.google.auto.service:auto-service:1.1.1",
"com.google.auto.service:auto-service-annotations:1.1.1",
"com.google.googlejavaformat:google-java-format:1.25.2:1.25.0",
"com.graphql-java:graphql-java:22.3",
"dev.failsafe:failsafe:3.3.2",
"io.grpc:grpc-context:1.68.1",
"io.grpc:grpc-context:1.69.0",
"io.lettuce:lettuce-core:6.5.2.RELEASE",
"io.netty:netty-buffer",
"io.netty:netty-codec-http",
Expand Down
24 changes: 12 additions & 12 deletions java/maven_install.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@
},
"com.google.errorprone:error_prone_annotations": {
"shasums": {
"jar": "f3fc8a3a0a4020706a373b00e7f57c2512dd26d1f83d28c7d38768f8682b231e",
"sources": "2936e9b315d790d8a6364f0574bcec9c8b2d78688b317e1765c4a16f9ef80632"
"jar": "77440e270b0bc9a249903c5a076c36a722c4886ca4f42675f2903a1c53ed61a5",
"sources": "7e117e0931cb2cb4226372af336189b49edb79969d120ec958a6df0beacb0612"
},
"version": "2.28.0"
"version": "2.36.0"
},
"com.google.googlejavaformat:google-java-format": {
"shasums": {
Expand All @@ -145,10 +145,10 @@
},
"com.google.guava:guava": {
"shasums": {
"jar": "4bf0e2c5af8e4525c96e8fde17a4f7307f97f8478f11c4c8e35a0e3298ae4e90",
"sources": "b7cbdad958b791f2a036abff7724570bf9836531c460966f8a3d0df8eaa1c21d"
"jar": "b918c98a7e44dbe94ebd9fe3e40cddaadb5a93e6a78eb6008b42df237241e538",
"sources": "55ef6603b6ab1f6e3ae810b127561650ed682eb5f3fb50a212a658a74087b457"
},
"version": "33.3.1-jre"
"version": "33.4.0-jre"
},
"com.google.guava:listenablefuture": {
"shasums": {
Expand Down Expand Up @@ -214,17 +214,17 @@
},
"io.grpc:grpc-api": {
"shasums": {
"jar": "d88d815e07fe58a7572dda5d2823485b61706564f289a1e74281705d50ac2d5b",
"sources": "791d817c56f03690df499020479e23494b79ab6ed578f4f50285d83d45a1f35d"
"jar": "ffa9af0f76fb08b4dbcade9dba9805af6b216980cafa0756b4d97b6029077506",
"sources": "e175c53977b6899c7be5a2e2007f79996d46c5512e852975cb4af663ffd84db9"
},
"version": "1.68.1"
"version": "1.69.0"
},
"io.grpc:grpc-context": {
"shasums": {
"jar": "1df4f0310a7e7836bc2948afa95105f5ee27b5d468488aded74e7ff620359076",
"sources": "6f5941f8531f6eea4ff922d2019757d06dc5857327ff9b9858ace45c0cf0ef8b"
"jar": "e682d036496d4429442955b615b931ee65486bd318d0ab13d9937d11cb36ffd5",
"sources": "a2ac5373e3f1021ec3f936b7c994b5fb94b391a8db24333825a0c081163d9efd"
},
"version": "1.68.1"
"version": "1.69.0"
},
"io.lettuce:lettuce-core": {
"shasums": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(
new SessionNotCreatedException("Unable to create new session");
for (Capabilities caps : request.getDesiredCapabilities()) {
if (isNotSupported(caps)) {
// e.g. the last node drained, we have to wait for a new to register
lastFailure =
new SessionNotCreatedException(
"Unable to find a node supporting the desired capabilities");
retry = true;
continue;
}

Expand Down
9 changes: 6 additions & 3 deletions java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.openqa.selenium.grid.node.httpd;

import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.net.HttpURLConnection.HTTP_UNAVAILABLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.EVENT_BUS_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;
Expand Down Expand Up @@ -131,13 +131,16 @@ protected Handlers createHandlers(Config config) {
HttpHandler readinessCheck =
req -> {
if (node.getStatus().hasCapacity()) {
return new HttpResponse().setStatus(HTTP_NO_CONTENT);
return new HttpResponse()
.setStatus(HTTP_OK)
.setHeader("Content-Type", MediaType.PLAIN_TEXT_UTF_8.toString())
.setContent(Contents.utf8String("Node has capacity available"));
}

return new HttpResponse()
.setStatus(HTTP_UNAVAILABLE)
.setHeader("Content-Type", MediaType.PLAIN_TEXT_UTF_8.toString())
.setContent(Contents.utf8String("No capacity available"));
.setContent(Contents.utf8String("Node has no capacity available"));
};

bus.addListener(
Expand Down
61 changes: 49 additions & 12 deletions java/src/org/openqa/selenium/grid/node/local/LocalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -133,7 +135,7 @@ public class LocalNode extends Node implements Closeable {
private final int connectionLimitPerSession;

private final boolean bidiEnabled;
private final AtomicBoolean drainAfterSessions = new AtomicBoolean();
private final boolean drainAfterSessions;
private final List<SessionSlot> factories;
private final Cache<SessionId, SessionSlot> currentSessions;
private final Cache<SessionId, TemporaryFilesystem> uploadsTempFileSystem;
Expand All @@ -142,6 +144,7 @@ public class LocalNode extends Node implements Closeable {
private final AtomicInteger pendingSessions = new AtomicInteger();
private final AtomicInteger sessionCount = new AtomicInteger();
private final Runnable shutdown;
private final ReadWriteLock drainLock = new ReentrantReadWriteLock();

protected LocalNode(
Tracer tracer,
Expand Down Expand Up @@ -177,7 +180,7 @@ protected LocalNode(
this.factories = ImmutableList.copyOf(factories);
Require.nonNull("Registration secret", registrationSecret);
this.configuredSessionCount = drainAfterSessionCount;
this.drainAfterSessions.set(this.configuredSessionCount > 0);
this.drainAfterSessions = this.configuredSessionCount > 0;
this.sessionCount.set(drainAfterSessionCount);
this.cdpEnabled = cdpEnabled;
this.bidiEnabled = bidiEnabled;
Expand Down Expand Up @@ -443,6 +446,9 @@ public Either<WebDriverException, CreateSessionResponse> newSession(
CreateSessionRequest sessionRequest) {
Require.nonNull("Session request", sessionRequest);

Lock lock = drainLock.readLock();
lock.lock();

try (Span span = tracer.getCurrentContext().createSpan("node.new_session")) {
AttributeMap attributeMap = tracer.createAttributeMap();
attributeMap.put(AttributeKey.LOGGER_CLASS.getKey(), getClass().getName());
Expand All @@ -455,13 +461,14 @@ public Either<WebDriverException, CreateSessionResponse> newSession(
span.setAttribute("current.session.count", currentSessionCount);
attributeMap.put("current.session.count", currentSessionCount);

if (getCurrentSessionCount() >= maxSessionCount) {
if (currentSessionCount >= maxSessionCount) {
span.setAttribute(AttributeKey.ERROR.getKey(), true);
span.setStatus(Status.RESOURCE_EXHAUSTED);
attributeMap.put("max.session.count", maxSessionCount);
span.addEvent("Max session count reached", attributeMap);
return Either.left(new RetrySessionRequestException("Max session count reached."));
}

if (isDraining()) {
span.setStatus(
Status.UNAVAILABLE.withDescription(
Expand Down Expand Up @@ -492,6 +499,15 @@ public Either<WebDriverException, CreateSessionResponse> newSession(
new RetrySessionRequestException("No slot matched the requested capabilities."));
}

if (!decrementSessionCount()) {
slotToUse.release();
span.setAttribute(AttributeKey.ERROR.getKey(), true);
span.setStatus(Status.RESOURCE_EXHAUSTED);
attributeMap.put("drain.after.session.count", configuredSessionCount);
span.addEvent("Drain after session count reached", attributeMap);
return Either.left(new RetrySessionRequestException("Drain after session count reached."));
}

UUID uuidForSessionDownloads = UUID.randomUUID();
Capabilities desiredCapabilities = sessionRequest.getDesiredCapabilities();
if (managedDownloadsRequested(desiredCapabilities)) {
Expand Down Expand Up @@ -548,6 +564,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(
return Either.left(possibleSession.left());
}
} finally {
lock.unlock();
checkSessionCount();
}
}
Expand Down Expand Up @@ -1020,20 +1037,40 @@ public void drain() {
}

private void checkSessionCount() {
if (this.drainAfterSessions.get()) {
if (this.drainAfterSessions) {
Lock lock = drainLock.writeLock();
if (!lock.tryLock()) {
// in case we can't get a write lock another thread does hold a read lock and will call
// checkSessionCount as soon as he releases the read lock. So we do not need to wait here
// for the other session to start and release the lock, just continue and let the other
// session start to drain the node.
return;
}
try {
int remainingSessions = this.sessionCount.get();
if (remainingSessions <= 0) {
LOG.info(
String.format(
"Draining Node, configured sessions value (%s) has been reached.",
this.configuredSessionCount));
drain();
}
} finally {
lock.unlock();
}
}
}

private boolean decrementSessionCount() {
if (this.drainAfterSessions) {
int remainingSessions = this.sessionCount.decrementAndGet();
LOG.log(
Debug.getDebugLogLevel(),
"{0} remaining sessions before draining Node",
remainingSessions);
if (remainingSessions <= 0) {
LOG.info(
String.format(
"Draining Node, configured sessions value (%s) has been reached.",
this.configuredSessionCount));
drain();
}
return remainingSessions >= 0;
}
return true;
}

private Map<String, Object> toJson() {
Expand Down
49 changes: 47 additions & 2 deletions java/test/org/openqa/selenium/grid/distributor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "JUNIT5_DEPS", "java_test_suite")
load("//java:defs.bzl", "JUNIT5_DEPS", "java_selenium_test_suite", "java_test_suite")
load("//java:version.bzl", "TOOLS_JAVA_VERSION")

LARGE_TESTS = [
"DrainTest.java",
]

java_selenium_test_suite(
name = "large-tests",
size = "large",
srcs = LARGE_TESTS,
browsers = [
"chrome",
"firefox",
"edge",
],
javacopts = [
"--release",
TOOLS_JAVA_VERSION,
],
tags = [
"selenium-remote",
],
deps = [
"//java/src/org/openqa/selenium/chrome",
"//java/src/org/openqa/selenium/firefox",
"//java/src/org/openqa/selenium/grid",
"//java/src/org/openqa/selenium/grid/config",
"//java/src/org/openqa/selenium/grid/distributor",
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/remote",
"//java/src/org/openqa/selenium/support",
"//java/test/org/openqa/selenium/environment",
"//java/test/org/openqa/selenium/grid/testing",
"//java/test/org/openqa/selenium/remote/tracing:tracing-support",
"//java/test/org/openqa/selenium/testing:annotations",
"//java/test/org/openqa/selenium/testing:test-base",
artifact("org.junit.jupiter:junit-jupiter-api"),
artifact("org.junit.jupiter:junit-jupiter-params"),
artifact("org.assertj:assertj-core"),
"//java/src/org/openqa/selenium:core",
"//java/src/org/openqa/selenium/remote/http",
] + JUNIT5_DEPS,
)

java_test_suite(
name = "medium-tests",
size = "medium",
srcs = glob(["*.java"]),
srcs = glob(
["*.java"],
exclude = LARGE_TESTS,
),
javacopts = [
"--release",
TOOLS_JAVA_VERSION,
Expand Down
Loading

0 comments on commit 3c113b3

Please sign in to comment.