Skip to content

Commit

Permalink
Merge branch 'trunk' into select-parity
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani authored May 8, 2024
2 parents bf4a4de + 0345a23 commit 16dc775
Show file tree
Hide file tree
Showing 38 changed files with 298 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .bazelrc.remote
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test:remote --test_env=PATH=/bin:/usr/bin:/usr/local/bin
test:remote --test_env=HOME=/home/dev

# Make sure we sniff credentials properly
build:remote --credential_helper=%workspace%/scripts/credential-helper.sh
build:remote --credential_helper=gypsum.cluster.engflow.com=%workspace%/scripts/credential-helper.sh

# Use pinned browsers when running remotely
build:remote --//common:pin_browsers
Expand Down
10 changes: 10 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ use_repo(pip, "py_dev_requirements")

register_toolchains("@pythons_hub//:all")

# https://github.com/bazelbuild/rules_jvm_external/pull/1079
archive_override(
module_name = "rules_jvm_external",
integrity = "sha256-yS8Qes1PLbYbe10b1WSgl0Auqn/1Wlxg8O3wSr7a/Sg=",
patch_strip = 1,
patches = ["//java:rules_jvm_external_javadoc.patch"],
strip_prefix = "rules_jvm_external-f572a26116c7ef71d8842dd056c2605782f7be8d",
urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/f572a26116c7ef71d8842dd056c2605782f7be8d.tar.gz"],
)

java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
use_repo(
java_toolchains,
Expand Down
26 changes: 13 additions & 13 deletions common/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ js_library(

http_archive(
name = "linux_beta_firefox",
url = "https://ftp.mozilla.org/pub/firefox/releases/126.0b8/linux-x86_64/en-US/firefox-126.0b8.tar.bz2",
sha256 = "75198959b1eeedc81be229ad3066ee6d49ecde985ce5d5d11d61f0914e288517",
url = "https://ftp.mozilla.org/pub/firefox/releases/126.0b9/linux-x86_64/en-US/firefox-126.0b9.tar.bz2",
sha256 = "053e60089c6ab85507dca96ad8c9d32e3fc6d21ac5bdf7e616c673327804565f",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand All @@ -72,8 +72,8 @@ js_library(

dmg_archive(
name = "mac_beta_firefox",
url = "https://ftp.mozilla.org/pub/firefox/releases/126.0b8/mac/en-US/Firefox%20126.0b8.dmg",
sha256 = "ca247dbfa1b092f36c75ab785acb0c54e608545b76dc06fbac9a9034df0daf8a",
url = "https://ftp.mozilla.org/pub/firefox/releases/126.0b9/mac/en-US/Firefox%20126.0b9.dmg",
sha256 = "67806b532db26059fbe747ec3fc2f6306d9bb4b09e1b264c49461c4d613b5366",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -123,10 +123,10 @@ js_library(

pkg_archive(
name = "mac_edge",
url = "https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/8325266a-e5ef-4b92-b110-6e387417723c/MicrosoftEdge-124.0.2478.67.pkg",
sha256 = "4c79de91852bda6a779761d06cfa00d48ae4f08dfe3903543f3674b973bd780b",
url = "https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/e6f7f9ba-499c-44cb-9c19-28daeaa82dc6/MicrosoftEdge-124.0.2478.80.pkg",
sha256 = "fc667b0401c05bbe0e4d337cc593641e2b653107fafd363b401cd32baa8a4f53",
move = {
"MicrosoftEdge-124.0.2478.67.pkg/Payload/Microsoft Edge.app": "Edge.app",
"MicrosoftEdge-124.0.2478.80.pkg/Payload/Microsoft Edge.app": "Edge.app",
},
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
Expand All @@ -143,8 +143,8 @@ js_library(

deb_archive(
name = "linux_edge",
url = "https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/microsoft-edge-stable_124.0.2478.67-1_amd64.deb",
sha256 = "3d12f66a279b0a82b478625696f23e1ac935e0596d57e19a41da232ee0c58a65",
url = "https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/microsoft-edge-stable_124.0.2478.80-1_amd64.deb",
sha256 = "a7eb75d95730c520eec998f755fcc427a9b4ac6a150bbb267b21e8383b6dc105",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand All @@ -165,8 +165,8 @@ js_library(

http_archive(
name = "linux_edgedriver",
url = "https://msedgedriver.azureedge.net/124.0.2478.67/edgedriver_linux64.zip",
sha256 = "25a169807beb4fc2485cf601f04c76cfffcc2c1e23a875941bc8aa41bee0587c",
url = "https://msedgedriver.azureedge.net/124.0.2478.80/edgedriver_linux64.zip",
sha256 = "4c9192c8e42ac1e1d779784ba95a0b28807cc75ae1be07be740f40bc20410670",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand All @@ -182,8 +182,8 @@ js_library(

http_archive(
name = "mac_edgedriver",
url = "https://msedgedriver.azureedge.net/124.0.2478.67/edgedriver_mac64.zip",
sha256 = "571d910bc662e2dfcf10e47cf40d11f76568b893abbde877f2beb487693ed983",
url = "https://msedgedriver.azureedge.net/124.0.2478.80/edgedriver_mac64.zip",
sha256 = "f8d8b0eaacb884196e5f368a64cad246a86e5a92941b0d37c5d7aa8ebb0fec1f",
build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Expand Down
29 changes: 17 additions & 12 deletions java/src/org/openqa/selenium/devtools/CdpClientGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -913,18 +913,23 @@ public TypeDeclaration<?> toTypeDeclaration() {
fromJson.getBody().get().addStatement(String.format("return new %s(%s);", name, getMapper()));

MethodDeclaration toJson = classDecl.addMethod("toJson").setPublic(true);
if (type.equals("object")) {
toJson.setType("java.util.Map<String, Object>");
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
} else if (type.equals("number")) {
toJson.setType(Number.class);
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
} else if (type.equals("integer")) {
toJson.setType(Integer.class);
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
} else {
toJson.setType(String.class);
toJson.getBody().get().addStatement(String.format("return %s.toString();", propertyName));
switch (type) {
case "object":
toJson.setType("java.util.Map<String, Object>");
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
break;
case "number":
toJson.setType(Number.class);
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
break;
case "integer":
toJson.setType(Integer.class);
toJson.getBody().get().addStatement(String.format("return %s;", propertyName));
break;
default:
toJson.setType(String.class);
toJson.getBody().get().addStatement(String.format("return %s.toString();", propertyName));
break;
}

MethodDeclaration toString = classDecl.addMethod("toString").setPublic(true);
Expand Down
29 changes: 29 additions & 0 deletions java/src/org/openqa/selenium/devtools/RequestFailedException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.devtools;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.http.Filter;
import org.openqa.selenium.remote.http.HttpHandler;

/**
* This exception is thrown by the final {@link HttpHandler} in a {@link Filter} chain when the
* browser fails to send a HTTP request. It can be caught in a {@link Filter} to handle the error
* by, for example, returning a custom HTTP response.
*/
public class RequestFailedException extends WebDriverException {}
18 changes: 16 additions & 2 deletions java/src/org/openqa/selenium/devtools/idealized/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.openqa.selenium.devtools.DevToolsException;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.NetworkInterceptor;
import org.openqa.selenium.devtools.RequestFailedException;
import org.openqa.selenium.internal.Either;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.http.Contents;
Expand Down Expand Up @@ -202,8 +203,12 @@ public void prepareToInterceptTraffic() {
String id = getRequestId(pausedRequest);

if (hasErrorResponse(pausedRequest)) {
pendingResponses.remove(id);
devTools.send(continueWithoutModification(pausedRequest));
CompletableFuture<HttpResponse> future = pendingResponses.remove(id);
if (future == null) {
devTools.send(continueWithoutModification(pausedRequest));
} else {
future.completeExceptionally(new RequestFailedException());
}
return;
}

Expand Down Expand Up @@ -244,6 +249,11 @@ public void prepareToInterceptTraffic() {
pendingResponses.remove(id);
return STOP_PROCESSING;
} catch (ExecutionException e) {
if (e.getCause() instanceof RequestFailedException) {
// Throwing here will give the user's filter a chance to intercept
// the failure and handle it.
throw (RequestFailedException) e.getCause();
}
if (fetchEnabled.get()) {
LOG.log(WARNING, e, () -> "Unable to process request");
}
Expand All @@ -261,6 +271,10 @@ public void prepareToInterceptTraffic() {
}

devTools.send(fulfillRequest(pausedRequest, forBrowser));
} catch (RequestFailedException e) {
// If the exception reaches here, we know the user's filter has not handled it and the
// browser should continue its normal error handling.
devTools.send(continueWithoutModification(pausedRequest));
} catch (TimeoutException e) {
if (fetchEnabled.get()) {
throw e;
Expand Down
23 changes: 22 additions & 1 deletion java/src/org/openqa/selenium/grid/data/NodeStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class NodeStatus {
private final Set<Slot> slots;
private final Availability availability;
private final Duration heartbeatPeriod;
private final Duration sessionTimeout;
private final String version;
private final Map<String, String> osInfo;

Expand All @@ -52,6 +53,7 @@ public NodeStatus(
Set<Slot> slots,
Availability availability,
Duration heartbeatPeriod,
Duration sessionTimeout,
String version,
Map<String, String> osInfo) {
this.nodeId = Require.nonNull("Node id", nodeId);
Expand All @@ -62,6 +64,7 @@ public NodeStatus(
this.slots = unmodifiableSet(new HashSet<>(Require.nonNull("Slots", slots)));
this.availability = Require.nonNull("Availability", availability);
this.heartbeatPeriod = heartbeatPeriod;
this.sessionTimeout = sessionTimeout;
this.version = Require.nonNull("Grid Node version", version);
this.osInfo = Require.nonNull("Node host OS info", osInfo);
}
Expand All @@ -73,6 +76,7 @@ public static NodeStatus fromJson(JsonInput input) {
Set<Slot> slots = null;
Availability availability = null;
Duration heartbeatPeriod = null;
Duration sessionTimeout = null;
String version = null;
Map<String, String> osInfo = null;

Expand All @@ -87,6 +91,10 @@ public static NodeStatus fromJson(JsonInput input) {
heartbeatPeriod = Duration.ofMillis(input.read(Long.class));
break;

case "sessionTimeout":
sessionTimeout = Duration.ofMillis(input.read(Long.class));
break;

case "nodeId":
nodeId = input.read(NodeId.class);
break;
Expand Down Expand Up @@ -119,7 +127,15 @@ public static NodeStatus fromJson(JsonInput input) {
input.endObject();

return new NodeStatus(
nodeId, externalUri, maxSessions, slots, availability, heartbeatPeriod, version, osInfo);
nodeId,
externalUri,
maxSessions,
slots,
availability,
heartbeatPeriod,
sessionTimeout,
version,
osInfo);
}

public boolean hasCapability(Capabilities caps, SlotMatcher slotMatcher) {
Expand Down Expand Up @@ -162,6 +178,10 @@ public Duration getHeartbeatPeriod() {
return heartbeatPeriod;
}

public Duration getSessionTimeout() {
return sessionTimeout;
}

public String getVersion() {
return version;
}
Expand Down Expand Up @@ -212,6 +232,7 @@ private Map<String, Object> toJson() {
toReturn.put("slots", slots);
toReturn.put("availability", availability);
toReturn.put("heartbeatPeriod", heartbeatPeriod.toMillis());
toReturn.put("sessionTimeout", sessionTimeout.toMillis());
toReturn.put("version", version);
toReturn.put("osInfo", osInfo);

Expand Down
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/grid/distributor/AddNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public HttpResponse execute(HttpRequest req) {
status.getNodeId(),
status.getExternalUri(),
registrationSecret,
status.getSessionTimeout(),
status.getSlots().stream().map(Slot::getStereotype).collect(Collectors.toSet()));

distributor.add(node);
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/grid/distributor/GridModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ private NodeStatus rewrite(NodeStatus status, Availability availability) {
status.getSlots(),
availability,
status.getHeartbeatPeriod(),
status.getSessionTimeout(),
status.getVersion(),
status.getOsInfo());
}
Expand Down Expand Up @@ -508,6 +509,7 @@ private void amend(Availability availability, NodeStatus status, Slot slot) {
newSlots,
availability,
status.getHeartbeatPeriod(),
status.getSessionTimeout(),
status.getVersion(),
status.getOsInfo()));
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ private void register(NodeStatus status) {
status.getNodeId(),
status.getExternalUri(),
registrationSecret,
status.getSessionTimeout(),
capabilities);

add(remoteNode);
Expand Down
10 changes: 9 additions & 1 deletion java/src/org/openqa/selenium/grid/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.net.URI;
import java.time.Duration;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
Expand Down Expand Up @@ -116,13 +117,16 @@ public abstract class Node implements HasReadyState, Routable {
protected final Tracer tracer;
private final NodeId id;
private final URI uri;
private final Duration sessionTimeout;
private final Route routes;
protected boolean draining;

protected Node(Tracer tracer, NodeId id, URI uri, Secret registrationSecret) {
protected Node(
Tracer tracer, NodeId id, URI uri, Secret registrationSecret, Duration sessionTimeout) {
this.tracer = Require.nonNull("Tracer", tracer);
this.id = Require.nonNull("Node id", id);
this.uri = Require.nonNull("URI", uri);
this.sessionTimeout = Require.positive("Session timeout", sessionTimeout);
Require.nonNull("Registration secret", registrationSecret);

RequiresSecretFilter requiresSecret = new RequiresSecretFilter(registrationSecret);
Expand Down Expand Up @@ -246,6 +250,10 @@ public TemporaryFilesystem getDownloadsFilesystem(UUID uuid) throws IOException

public abstract HealthCheck getHealthCheck();

public Duration getSessionTimeout() {
return sessionTimeout;
}

public boolean isDraining() {
return draining;
}
Expand Down
Loading

0 comments on commit 16dc775

Please sign in to comment.