Skip to content

Commit 8177633

Browse files
authored
Small fixes (#732)
* Small fixes * Revert changes on file * Add changelog * Small fixes in keepalive test * Add delay * Fix symbol visibilty * Add try catch for debugging * Fail * fail * Use for loop
1 parent 38ca626 commit 8177633

13 files changed

+36
-32
lines changed

.github/workflows/dart.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@ jobs:
9393
- name: Run tests
9494
run: dart test --platform ${{ matrix.platform }}
9595
- name: Run vmservice test
96-
if: ${{ matrix.platform != 'chrome' && false }} #Disable until https://github.com/grpc/grpc-dart/issues/697 is resolved
96+
if: ${{ matrix.platform != 'chrome' }}
9797
run: dart run --enable-vm-service --timeline-streams=Dart test/timeline_test.dart

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## 4.0.2
1+
## 4.0.2-wip
22

33
* Internal optimization to client code.
4+
* Small fixes, such as ports in testing and enabling `timeline_test.dart`.
45

56
## 4.0.1
67

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The [Dart](https://www.dart.dev/) implementation of
88
## Learn more
99

1010
- [Quick Start](https://grpc.io/docs/languages/dart/quickstart) - get an app running in minutes
11-
- [Examples](example)
11+
- [Examples](https://github.com/grpc/grpc-dart/tree/master/example)
1212
- [API reference](https://grpc.io/docs/languages/dart/api)
1313

1414
For complete documentation, see [Dart gRPC](https://grpc.io/docs/languages/dart).

lib/src/shared/status.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ class GrpcError implements Exception {
352352
/// This list comes from `error_details.proto`. If any new error detail types are
353353
/// added to the protbuf definition, this function should be updated accordingly to
354354
/// support them.
355+
@visibleForTesting
355356
GeneratedMessage parseErrorDetailsFromAny(Any any) {
356357
switch (any.typeUrl) {
357358
case 'type.googleapis.com/google.rpc.RetryInfo':

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: grpc
22
description: Dart implementation of gRPC, a high performance, open-source universal RPC framework.
3-
version: 4.0.2
3+
version: 4.0.2-wip
44

55
repository: https://github.com/grpc/grpc-dart
66

test/client_tests/client_xhr_transport_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class MockHttpRequest extends Mock implements HttpRequest {
6565
class MockXhrClientConnection extends XhrClientConnection {
6666
MockXhrClientConnection({int? code})
6767
: _statusCode = code ?? 200,
68-
super(Uri.parse('test:8080'));
68+
super(Uri.parse('test:0'));
6969

7070
late MockHttpRequest latestRequest;
7171
final int _statusCode;

test/client_tests/grpc_or_grpcweb_channel_grpc_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import 'package:grpc/grpc_or_grpcweb.dart';
2020
import 'package:test/test.dart';
2121

2222
const host = 'example.com';
23-
const port = 8080;
23+
const port = 0;
2424

2525
void main() {
2626
test('Channel on non-web uses gRPC ClientChannel with correct params', () {

test/client_tests/grpc_or_grpcweb_channel_web_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import 'package:grpc/grpc_web.dart';
2020
import 'package:test/test.dart';
2121

2222
const host = 'example.com';
23-
const port = 8080;
23+
const port = 0;
2424

2525
void main() {
2626
test('Channel on web uses GrpcWebClientChannel with correct URI', () {

test/keepalive_test.dart

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ void main() {
3434
late EchoServiceClient unresponsiveClient;
3535
late ClientChannel unresponsiveChannel;
3636

37+
final pingInterval = Duration(milliseconds: 10);
38+
final timeout = Duration(milliseconds: 30);
39+
final maxBadPings = 5;
40+
3741
setUp(() async {
3842
final serverOptions = ServerKeepAliveOptions(
39-
maxBadPings: 5,
43+
maxBadPings: maxBadPings,
4044
minIntervalBetweenPingsWithoutData: Duration(milliseconds: 10),
4145
);
4246
final clientOptions = ClientKeepAliveOptions(
43-
pingInterval: Duration(milliseconds: 10),
44-
timeout: Duration(milliseconds: 30),
47+
pingInterval: pingInterval,
48+
timeout: timeout,
4549
permitWithoutCalls: true,
4650
);
4751

@@ -79,7 +83,7 @@ void main() {
7983
test('Server terminates connection after too many pings without data',
8084
() async {
8185
await fakeClient.echo(EchoRequest());
82-
await Future.delayed(Duration(milliseconds: 300));
86+
await Future.delayed(timeout * maxBadPings * 2);
8387
await fakeClient.echo(EchoRequest());
8488
// Check that the server closed the connection, the next request then has
8589
// to build a new one.
@@ -88,12 +92,10 @@ void main() {
8892

8993
test('Server doesnt terminate connection after pings, as data is sent',
9094
() async {
91-
final timer = Timer.periodic(
92-
Duration(milliseconds: 10), (timer) => fakeClient.echo(EchoRequest()));
93-
await Future.delayed(Duration(milliseconds: 200), () => timer.cancel());
94-
95-
// Wait for last request to be sent
96-
await Future.delayed(Duration(milliseconds: 20));
95+
for (var i = 0; i < 10; i++) {
96+
await fakeClient.echo(EchoRequest());
97+
await Future.delayed(timeout * 0.2);
98+
}
9799

98100
// Check that the server never closed the connection
99101
expect(fakeChannel.newConnectionCounter, 1);
@@ -102,9 +104,11 @@ void main() {
102104
test('Server doesnt ack the ping, making the client shutdown the connection',
103105
() async {
104106
await unresponsiveClient.echo(EchoRequest());
105-
await Future.delayed(Duration(milliseconds: 200));
107+
await Future.delayed(timeout * 2);
106108
await expectLater(
107-
unresponsiveClient.echo(EchoRequest()), throwsA(isA<GrpcError>()));
109+
unresponsiveClient.echo(EchoRequest()),
110+
throwsA(isA<GrpcError>()),
111+
);
108112
});
109113
}
110114

@@ -113,7 +117,7 @@ class FakeClientChannel extends ClientChannel {
113117
FakeHttp2ClientConnection? fakeHttp2ClientConnection;
114118
FakeClientChannel(
115119
super.host, {
116-
super.port = 443,
120+
super.port,
117121
super.options = const ChannelOptions(),
118122
super.channelShutdownHandler,
119123
});
@@ -145,7 +149,7 @@ class FakeHttp2ClientConnection extends Http2ClientConnection {
145149
class UnresponsiveClientChannel extends ClientChannel {
146150
UnresponsiveClientChannel(
147151
super.host, {
148-
super.port = 443,
152+
super.port,
149153
super.options = const ChannelOptions(),
150154
super.channelShutdownHandler,
151155
});
@@ -189,8 +193,6 @@ class FakeEchoService extends EchoServiceBase {
189193

190194
@override
191195
Stream<ServerStreamingEchoResponse> serverStreamingEcho(
192-
ServiceCall call, ServerStreamingEchoRequest request) {
193-
// TODO: implement serverStreamingEcho
194-
throw UnimplementedError();
195-
}
196+
ServiceCall call, ServerStreamingEchoRequest request) =>
197+
throw UnsupportedError('Not used in this test');
196198
}

test/proxy_secure_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ void main() {
3333
server = Server.create(services: [FakeEchoService()]);
3434
await server.serve(
3535
address: 'localhost',
36-
port: 8888,
36+
port: 0,
3737
security: ServerTlsCredentials(
3838
certificate: File('test/data/localhost.crt').readAsBytesSync(),
3939
privateKey: File('test/data/localhost.key').readAsBytesSync(),
4040
),
4141
);
42-
final proxy = Proxy(host: 'localhost', port: 8080);
42+
final proxy = Proxy(host: 'localhost', port: 0);
4343
final proxyCAName = '/CN=mitmproxy/O=mitmproxy';
4444

4545
fakeChannel = ClientChannel(

test/proxy_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ void main() {
3030

3131
setUp(() async {
3232
server = Server.create(services: [FakeEchoService()]);
33-
await server.serve(address: 'localhost', port: 8888);
33+
await server.serve(address: 'localhost', port: 0);
3434

35-
final proxy = Proxy(host: 'localhost', port: 8080);
35+
final proxy = Proxy(host: 'localhost', port: 0);
3636

3737
fakeChannel = ClientChannel(
3838
'localhost',

test/server_cancellation_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747
server = Server.create(
4848
services: [EchoService()],
4949
);
50-
await server.serve(address: 'localhost', port: 8081);
50+
await server.serve(address: 'localhost', port: 0);
5151
channel = ClientChannel(
5252
'localhost',
5353
port: server.port!,

test/tools/http2_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import 'package:grpc/src/client/http2_connection.dart';
2020
import 'package:http2/http2.dart';
2121

2222
Future<void> main(List<String> args) async {
23-
final serverPort = 5678;
23+
final serverPort = 0;
2424
final proxyPort = int.tryParse(args.first);
2525

2626
final proxy =
@@ -37,7 +37,7 @@ Future<void> main(List<String> args) async {
3737
final incoming =
3838
proxy == null ? connector.socket : await connector.connectToProxy(proxy);
3939

40-
final uri = Uri.parse('http://localhost:8080');
40+
final uri = Uri.parse('http://localhost:0');
4141

4242
final transport =
4343
ClientTransportConnection.viaStreams(incoming, connector.socket);

0 commit comments

Comments
 (0)