Sitelet https://github.com/SeleniumHQ/selenium/commit/076d428580b7b101c62722cef10be995ffd2e44c
Skip to content

Commit 076d428

Browse files
authored
[dotnet] [bidi] Remove optional command timeout in command options (#17891)
1 parent 6b2b086 commit 076d428

13 files changed

Lines changed: 16 additions & 37 deletions

File tree

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ public async Task<TResult> ExecuteAsync<TParameters, TResult>(Command<TParameter
7878

7979
var tcs = new TaskCompletionSource<EmptyResult>(TaskCreationOptions.RunContinuationsAsynchronously);
8080

81-
using var cts = cancellationToken.CanBeCanceled
82-
? CancellationTokenSource.CreateLinkedTokenSource(cancellationToken)
83-
: new CancellationTokenSource();
81+
using CancellationTokenSource? cts = cancellationToken.CanBeCanceled
82+
? null
83+
: new CancellationTokenSource(DefaultCommandTimeout);
8484

85-
var timeout = options?.Timeout ?? DefaultCommandTimeout;
86-
cts.CancelAfter(timeout);
85+
var effectiveToken = cts?.Token ?? cancellationToken;
8786

8887
var sendBuffer = RentBuffer();
8988

@@ -132,9 +131,9 @@ public async Task<TResult> ExecuteAsync<TParameters, TResult>(Command<TParameter
132131
var commandInfo = new CommandInfo(tcs, descriptor.ResultTypeInfo);
133132
_pendingCommands[id] = commandInfo;
134133

135-
using var ctsRegistration = cts.Token.Register(() =>
134+
using var ctsRegistration = effectiveToken.Register(() =>
136135
{
137-
tcs.TrySetCanceled(cts.Token);
136+
tcs.TrySetCanceled(effectiveToken);
138137
_pendingCommands.TryRemove(id, out _);
139138
});
140139

@@ -149,7 +148,7 @@ public async Task<TResult> ExecuteAsync<TParameters, TResult>(Command<TParameter
149148
#endif
150149
}
151150

152-
await _transport.SendAsync(sendBuffer.WrittenMemory, cts.Token).ConfigureAwait(false);
151+
await _transport.SendAsync(sendBuffer.WrittenMemory, effectiveToken).ConfigureAwait(false);
153152
}
154153
catch
155154
{

‎dotnet/src/webdriver/BiDi/BrowsingContext/GetTree.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public sealed record ContextGetTreeOptions : CommandOptions
3535
internal static GetTreeOptions WithContext(ContextGetTreeOptions? options, BrowsingContext context) => new()
3636
{
3737
Root = context,
38-
MaxDepth = options?.MaxDepth,
39-
Timeout = options?.Timeout
38+
MaxDepth = options?.MaxDepth
4039
};
4140
}
4241

‎dotnet/src/webdriver/BiDi/BrowsingContext/SetViewport.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public sealed record ContextSetViewportOptions : CommandOptions
5050
{
5151
Context = context,
5252
Viewport = options?.Viewport,
53-
DevicePixelRatio = options?.DevicePixelRatio,
54-
Timeout = options?.Timeout
53+
DevicePixelRatio = options?.DevicePixelRatio
5554
};
5655
}
5756

‎dotnet/src/webdriver/BiDi/Command.cs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public AdditionalData AdditionalData
6363

6464
public abstract record CommandOptions
6565
{
66-
public TimeSpan? Timeout { get; init; }
67-
6866
public AdditionalData AdditionalData { get; init; }
6967

7068
public AdditionalData AdditionalMessageData { get; init; }

‎dotnet/src/webdriver/BiDi/Network/AddDataCollector.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public sealed record ContextAddDataCollectorOptions : CommandOptions
4343
{
4444
Contexts = [context],
4545
CollectorType = options?.CollectorType,
46-
UserContexts = options?.UserContexts,
47-
Timeout = options?.Timeout
46+
UserContexts = options?.UserContexts
4847
};
4948
}
5049

‎dotnet/src/webdriver/BiDi/Network/AddIntercept.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public record AddInterceptOptions() : CommandOptions
2929
internal AddInterceptOptions(ContextAddInterceptOptions? options) : this()
3030
{
3131
UrlPatterns = options?.UrlPatterns;
32-
Timeout = options?.Timeout;
3332
}
3433

3534
public ImmutableArray<BrowsingContext.BrowsingContext>? Contexts { get; init; }

‎dotnet/src/webdriver/BiDi/Network/SetCacheBehavior.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public sealed record ContextSetCacheBehaviorOptions : CommandOptions
3333
{
3434
internal static SetCacheBehaviorOptions WithContext(ContextSetCacheBehaviorOptions? options, BrowsingContext.BrowsingContext context) => new()
3535
{
36-
Contexts = [context],
37-
Timeout = options?.Timeout
36+
Contexts = [context]
3837
};
3938
}
4039

‎dotnet/src/webdriver/BiDi/Script/AddPreloadScript.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public sealed record ContextAddPreloadScriptOptions : CommandOptions
4444
{
4545
Contexts = [context],
4646
Arguments = options?.Arguments,
47-
Sandbox = options?.Sandbox,
48-
Timeout = options?.Timeout
47+
Sandbox = options?.Sandbox
4948
};
5049
}
5150

‎dotnet/src/webdriver/BiDi/Script/GetRealms.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public sealed record ContextGetRealmsOptions : CommandOptions
3535
internal static GetRealmsOptions WithContext(ContextGetRealmsOptions? options, BrowsingContext.BrowsingContext context) => new()
3636
{
3737
Context = context,
38-
Type = options?.Type,
39-
Timeout = options?.Timeout
38+
Type = options?.Type
4039
};
4140
}
4241

‎dotnet/src/webdriver/BiDi/Storage/DeleteCookies.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public sealed record ContextDeleteCookiesOptions : CommandOptions
3535
internal static DeleteCookiesOptions WithContext(ContextDeleteCookiesOptions? options, BrowsingContext.BrowsingContext context) => new()
3636
{
3737
Partition = new ContextPartitionDescriptor(context),
38-
Filter = options?.Filter,
39-
Timeout = options?.Timeout
38+
Filter = options?.Filter
4039
};
4140
}
4241

0 commit comments

Comments
 (0)