Skip to content

Commit c4b770e

Browse files
authored
Merge branch 'trunk' into fix-python-type-annotations
2 parents 4722123 + 55f02a9 commit c4b770e

File tree

6 files changed

+71
-19
lines changed

6 files changed

+71
-19
lines changed

dotnet/src/webdriver/BiDi/Communication/Broker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ internal Broker(BiDi bidi, Uri url)
8484
new RealmConverter(_bidi),
8585
new RealmTypeConverter(),
8686
new DateTimeOffsetConverter(),
87+
new TimeSpanConverter(),
8788
new PrintPageRangeConverter(),
8889
new InputOriginConverter(),
8990
new WebExtensionConverter(_bidi),

dotnet/src/webdriver/BiDi/Communication/Json/Converters/DateTimeOffsetConverter.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,7 @@ internal class DateTimeOffsetConverter : JsonConverter<DateTimeOffset>
2727
{
2828
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
2929
{
30-
// Workaround: it should be Int64, chrome uses double for `expiry` like "expiry":1737379944.308351
31-
32-
if (reader.TryGetInt64(out long unixTime) is false)
33-
{
34-
var doubleValue = reader.GetDouble();
35-
36-
unixTime = Convert.ToInt64(doubleValue);
37-
}
38-
39-
return DateTimeOffset.FromUnixTimeMilliseconds(unixTime);
30+
return DateTimeOffset.FromUnixTimeMilliseconds(reader.GetInt64());
4031
}
4132

4233
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// <copyright file="TimeSpanConverter.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System;
21+
using System.Text.Json;
22+
using System.Text.Json.Serialization;
23+
24+
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;
25+
26+
internal class TimeSpanConverter : JsonConverter<TimeSpan>
27+
{
28+
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
29+
{
30+
if (reader.TryGetInt64(out long milliseconds) is false)
31+
{
32+
var doubleValue = reader.GetDouble();
33+
34+
milliseconds = Convert.ToInt64(doubleValue);
35+
}
36+
37+
return TimeSpan.FromMilliseconds(milliseconds);
38+
}
39+
40+
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
41+
{
42+
writer.WriteNumberValue(value.TotalMilliseconds);
43+
}
44+
}

dotnet/src/webdriver/BiDi/Network/Cookie.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@
1818
// </copyright>
1919

2020
using System;
21-
using System.Text.Json.Serialization;
2221

2322
namespace OpenQA.Selenium.BiDi.Network;
2423

25-
public sealed record Cookie(string Name, BytesValue Value, string Domain, string Path, long Size, bool HttpOnly, bool Secure, SameSite SameSite)
26-
{
27-
[JsonInclude]
28-
public DateTimeOffset? Expiry { get; internal set; }
29-
}
24+
public sealed record Cookie(string Name, BytesValue Value, string Domain, string Path, long Size, bool HttpOnly, bool Secure, SameSite SameSite, TimeSpan? Expiry);
3025

3126
public enum SameSite
3227
{

java/src/org/openqa/selenium/grid/node/Node.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ protected Node(
199199
.to(() -> new Drain(this, json))
200200
.with(spanDecorator("node.drain").andThen(requiresSecret)),
201201
get("/se/grid/node/status")
202-
.to(() -> req -> new HttpResponse().setContent(asJson(getStatus())))
202+
.to(
203+
() ->
204+
req -> new HttpResponse().setContent(asJson(Map.of("value", getStatus()))))
203205
.with(spanDecorator("node.node_status")),
204206
get("/status").to(() -> new StatusHandler(this)).with(spanDecorator("node.status")));
205207
}

java/src/org/openqa/selenium/grid/router/HandleSession.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
2222
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID_EVENT;
2323
import static org.openqa.selenium.remote.http.Contents.asJson;
24+
import static org.openqa.selenium.remote.http.HttpMethod.GET;
2425
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
2526
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;
2627
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST_EVENT;
2728
import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;
2829

2930
import java.io.Closeable;
3031
import java.net.URI;
32+
import java.time.Duration;
3133
import java.time.Instant;
3234
import java.time.temporal.ChronoUnit;
3335
import java.util.Iterator;
@@ -43,8 +45,10 @@
4345
import org.openqa.selenium.NoSuchSessionException;
4446
import org.openqa.selenium.concurrent.ExecutorServices;
4547
import org.openqa.selenium.concurrent.GuardedRunnable;
48+
import org.openqa.selenium.grid.data.NodeStatus;
4649
import org.openqa.selenium.grid.sessionmap.SessionMap;
4750
import org.openqa.selenium.grid.web.ReverseProxyHandler;
51+
import org.openqa.selenium.grid.web.Values;
4852
import org.openqa.selenium.internal.Require;
4953
import org.openqa.selenium.remote.ErrorCodec;
5054
import org.openqa.selenium.remote.SessionId;
@@ -230,8 +234,7 @@ private Callable<UsageCountingReverseProxyHandler> loadSessionId(
230234
return entry;
231235
}
232236

233-
ClientConfig config =
234-
ClientConfig.defaultConfig().baseUri(sessionUri).withRetries();
237+
ClientConfig config = fetchNodeSessionTimeout(sessionUri).withRetries();
235238
HttpClient httpClient = httpClientFactory.createClient(config);
236239

237240
return new CacheEntry(httpClient, 1);
@@ -247,6 +250,22 @@ private Callable<UsageCountingReverseProxyHandler> loadSessionId(
247250
});
248251
}
249252

253+
private ClientConfig fetchNodeSessionTimeout(URI uri) {
254+
ClientConfig config = ClientConfig.defaultConfig().baseUri(uri);
255+
Duration sessionTimeout = config.readTimeout();
256+
try (HttpClient httpClient = httpClientFactory.createClient(config)) {
257+
HttpRequest statusRequest = new HttpRequest(GET, "/se/grid/node/status");
258+
HttpResponse res = httpClient.execute(statusRequest);
259+
NodeStatus nodeStatus = Values.get(res, NodeStatus.class);
260+
if (nodeStatus != null) {
261+
sessionTimeout = nodeStatus.getSessionTimeout();
262+
}
263+
}
264+
LOG.fine("Set read timeout: " + sessionTimeout.toSeconds() + " seconds for " + uri);
265+
config = config.readTimeout(sessionTimeout);
266+
return config;
267+
}
268+
250269
@Override
251270
public void close() {
252271
ExecutorServices.shutdownGracefully(

0 commit comments

Comments
 (0)