-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Tests, DartDoc, and Lints to Service Extension Router
This CL is a polish step in preparation for publishing SER. Change-Id: If1222e3b63270362c25fa076e6adc01fe4938ed5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335244 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Dan Chevalier <[email protected]>
- Loading branch information
Dan Chevalier
authored and
Commit Queue
committed
Nov 13, 2023
1 parent
47b9e3e
commit 98fd1b7
Showing
7 changed files
with
275 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
|
||
include: package:lints/recommended.yaml | ||
|
||
linter: | ||
rules: | ||
- avoid_void_async | ||
- unawaited_futures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ library; | |
|
||
export 'src/stream_manager.dart'; | ||
export 'src/client.dart'; | ||
export 'src/client_manager.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:service_extension_router/src/client.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
class TestClientManager extends ClientManager {} | ||
|
||
class TestClient extends Client { | ||
int closeCount = 0; | ||
int sendRequestCount = 0; | ||
int streamNotifyCount = 0; | ||
|
||
@override | ||
Future<void> close() { | ||
closeCount++; | ||
return Future.value(); | ||
} | ||
|
||
@override | ||
Future sendRequest({required String method, parameters}) { | ||
sendRequestCount++; | ||
return Future.value(); | ||
} | ||
|
||
@override | ||
void streamNotify(String stream, Map<String, Object?> data) { | ||
streamNotifyCount++; | ||
} | ||
} | ||
|
||
void main() { | ||
group('ClientManager', () { | ||
late ClientManager clientManager; | ||
setUp(() { | ||
clientManager = TestClientManager(); | ||
}); | ||
test('add and remove client', () { | ||
final client = TestClient(); | ||
|
||
expect(clientManager.clients.length, 0); | ||
|
||
clientManager.addClient(client); | ||
|
||
expect(clientManager.clients.length, 1); | ||
expect(clientManager.clients.first, client); | ||
|
||
clientManager.removeClient(client); | ||
|
||
expect(clientManager.clients.length, 0); | ||
}); | ||
|
||
test('client name', () { | ||
final client = TestClient(); | ||
|
||
// Name unset until client is added to a manager | ||
expect(client.name, isNull); | ||
|
||
// Sets the client name to a default | ||
clientManager.addClient(client); | ||
final defaultClientName = client.name; | ||
expect(client.name?.startsWith('client'), isTrue); | ||
|
||
clientManager.setClientName(client, 'test'); | ||
expect(client.name, 'test'); | ||
|
||
clientManager.clearClientName(client); | ||
expect(client.name, defaultClientName); | ||
}); | ||
|
||
test('findFirstClientThatHandlesService', () { | ||
final client1 = TestClient(); | ||
final client2 = TestClient(); | ||
client1.services['service1'] = 'alias1'; | ||
client2.services['service2'] = 'alias2'; | ||
clientManager.addClient(client1); | ||
clientManager.addClient(client2); | ||
|
||
expect( | ||
clientManager.findFirstClientThatHandlesService('service1'), | ||
client1, | ||
); | ||
expect( | ||
clientManager.findFirstClientThatHandlesService('service2'), | ||
client2, | ||
); | ||
}); | ||
|
||
test('shutdown', () async { | ||
final client1 = TestClient(); | ||
final client2 = TestClient(); | ||
final client3 = TestClient(); | ||
clientManager.addClient(client1); | ||
clientManager.addClient(client2); | ||
clientManager.addClient(client3); | ||
|
||
expect(client1.closeCount, 0); | ||
expect(client2.closeCount, 0); | ||
expect(client3.closeCount, 0); | ||
expect( | ||
clientManager.clients, | ||
unorderedEquals([ | ||
client1, | ||
client2, | ||
client3, | ||
]), | ||
); | ||
|
||
await clientManager.shutdown(); | ||
|
||
expect(client1.closeCount, 1); | ||
expect(client2.closeCount, 1); | ||
expect(client3.closeCount, 1); | ||
expect( | ||
clientManager.clients, | ||
[], | ||
); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.