Skip to content

Commit

Permalink
Explicitly close http clients (#311)
Browse files Browse the repository at this point in the history
* Explicitly close http clients

* 3.1.0
  • Loading branch information
iinozemtsev authored Jan 28, 2025
1 parent d83d6a3 commit e84e9cc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 3.1.0-wip
## 3.1.0

* Add a `reason` argument to `Clock.waitFor`.
* Explicitly close http clients on quit.

## 3.0.4

Expand Down
2 changes: 2 additions & 0 deletions lib/async_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Future<WebDriver> createDriver(
final session = await client.send(
handler.session.buildCreateRequest(desired: desired),
handler.session.parseCreateResponse);
client.close();

if (session.spec != WebDriverSpec.JsonWire &&
session.spec != WebDriverSpec.W3c) {
Expand Down Expand Up @@ -90,6 +91,7 @@ Future<WebDriver> fromExistingSession(

final session = await client.send(handler.session.buildInfoRequest(sessionId),
(response) => handler.session.parseInfoResponse(response, sessionId));
client.close();

if (session.spec != WebDriverSpec.JsonWire &&
session.spec != WebDriverSpec.W3c) {
Expand Down
12 changes: 8 additions & 4 deletions lib/src/async/web_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,14 @@ class WebDriver implements SearchContext {
_handler.core.parsePageSourceResponse);

/// Quits the browser.
Future<void> quit({bool closeSession = true}) => closeSession
? _client.send(_handler.core.buildDeleteSessionRequest(),
_handler.core.parseDeleteSessionResponse)
: Future.value();
Future<void> quit({bool closeSession = true}) async {
if (!closeSession) {
return;
}
await _client.send(_handler.core.buildDeleteSessionRequest(),
_handler.core.parseDeleteSessionResponse);
_client.close();
}

/// Closes the current window.
///
Expand Down
2 changes: 2 additions & 0 deletions lib/src/common/request_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,6 @@ abstract class AsyncRequestClient extends RequestClient {
}

Future<WebDriverResponse> sendRaw(WebDriverRequest request);

void close() {}
}
3 changes: 3 additions & 0 deletions lib/src/request/async_io_request_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ class AsyncIoRequestClient extends AsyncRequestClient {

@override
String toString() => 'AsyncIo';

@override
void close() => client.close(force: true);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: webdriver
version: 3.1.0-wip
version: 3.1.0
description: >-
Provides WebDriver bindings for Dart. Supports WebDriver JSON interface and
W3C spec. Requires the use of WebDriver remote server.
Expand Down

0 comments on commit e84e9cc

Please sign in to comment.