diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 2f58e625..c80305bd 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -93,5 +93,5 @@ jobs: - name: Run tests run: dart test --platform ${{ matrix.platform }} - name: Run vmservice test - if: ${{ matrix.platform != 'chrome' && false }} #Disable until https://github.com/grpc/grpc-dart/issues/697 is resolved + if: ${{ matrix.platform != 'chrome' }} run: dart run --enable-vm-service --timeline-streams=Dart test/timeline_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d55328e..14b3032b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ -## 4.0.2 +## 4.0.2-wip * Internal optimization to client code. +* Small fixes, such as ports in testing and enabling `timeline_test.dart`. ## 4.0.1 diff --git a/README.md b/README.md index 1e0419a4..f85542b2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The [Dart](https://www.dart.dev/) implementation of ## Learn more - [Quick Start](https://grpc.io/docs/languages/dart/quickstart) - get an app running in minutes -- [Examples](example) +- [Examples](https://github.com/grpc/grpc-dart/tree/master/example) - [API reference](https://grpc.io/docs/languages/dart/api) For complete documentation, see [Dart gRPC](https://grpc.io/docs/languages/dart). diff --git a/lib/src/shared/status.dart b/lib/src/shared/status.dart index 4f8a9c1f..cb662326 100644 --- a/lib/src/shared/status.dart +++ b/lib/src/shared/status.dart @@ -352,6 +352,7 @@ class GrpcError implements Exception { /// This list comes from `error_details.proto`. If any new error detail types are /// added to the protbuf definition, this function should be updated accordingly to /// support them. +@visibleForTesting GeneratedMessage parseErrorDetailsFromAny(Any any) { switch (any.typeUrl) { case 'type.googleapis.com/google.rpc.RetryInfo': diff --git a/pubspec.yaml b/pubspec.yaml index e2f106d0..e89e71ae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: grpc description: Dart implementation of gRPC, a high performance, open-source universal RPC framework. -version: 4.0.2 +version: 4.0.2-wip repository: https://github.com/grpc/grpc-dart diff --git a/test/client_tests/client_xhr_transport_test.dart b/test/client_tests/client_xhr_transport_test.dart index ece79432..1c58077f 100644 --- a/test/client_tests/client_xhr_transport_test.dart +++ b/test/client_tests/client_xhr_transport_test.dart @@ -65,7 +65,7 @@ class MockHttpRequest extends Mock implements HttpRequest { class MockXhrClientConnection extends XhrClientConnection { MockXhrClientConnection({int? code}) : _statusCode = code ?? 200, - super(Uri.parse('test:8080')); + super(Uri.parse('test:0')); late MockHttpRequest latestRequest; final int _statusCode; diff --git a/test/client_tests/grpc_or_grpcweb_channel_grpc_test.dart b/test/client_tests/grpc_or_grpcweb_channel_grpc_test.dart index 1db9bdad..a2b6e4a2 100644 --- a/test/client_tests/grpc_or_grpcweb_channel_grpc_test.dart +++ b/test/client_tests/grpc_or_grpcweb_channel_grpc_test.dart @@ -20,7 +20,7 @@ import 'package:grpc/grpc_or_grpcweb.dart'; import 'package:test/test.dart'; const host = 'example.com'; -const port = 8080; +const port = 0; void main() { test('Channel on non-web uses gRPC ClientChannel with correct params', () { diff --git a/test/client_tests/grpc_or_grpcweb_channel_web_test.dart b/test/client_tests/grpc_or_grpcweb_channel_web_test.dart index 3bd9329d..8382219e 100644 --- a/test/client_tests/grpc_or_grpcweb_channel_web_test.dart +++ b/test/client_tests/grpc_or_grpcweb_channel_web_test.dart @@ -20,7 +20,7 @@ import 'package:grpc/grpc_web.dart'; import 'package:test/test.dart'; const host = 'example.com'; -const port = 8080; +const port = 0; void main() { test('Channel on web uses GrpcWebClientChannel with correct URI', () { diff --git a/test/keepalive_test.dart b/test/keepalive_test.dart index 4e710811..3da1b80e 100644 --- a/test/keepalive_test.dart +++ b/test/keepalive_test.dart @@ -34,14 +34,18 @@ void main() { late EchoServiceClient unresponsiveClient; late ClientChannel unresponsiveChannel; + final pingInterval = Duration(milliseconds: 10); + final timeout = Duration(milliseconds: 30); + final maxBadPings = 5; + setUp(() async { final serverOptions = ServerKeepAliveOptions( - maxBadPings: 5, + maxBadPings: maxBadPings, minIntervalBetweenPingsWithoutData: Duration(milliseconds: 10), ); final clientOptions = ClientKeepAliveOptions( - pingInterval: Duration(milliseconds: 10), - timeout: Duration(milliseconds: 30), + pingInterval: pingInterval, + timeout: timeout, permitWithoutCalls: true, ); @@ -79,7 +83,7 @@ void main() { test('Server terminates connection after too many pings without data', () async { await fakeClient.echo(EchoRequest()); - await Future.delayed(Duration(milliseconds: 300)); + await Future.delayed(timeout * maxBadPings * 2); await fakeClient.echo(EchoRequest()); // Check that the server closed the connection, the next request then has // to build a new one. @@ -88,12 +92,10 @@ void main() { test('Server doesnt terminate connection after pings, as data is sent', () async { - final timer = Timer.periodic( - Duration(milliseconds: 10), (timer) => fakeClient.echo(EchoRequest())); - await Future.delayed(Duration(milliseconds: 200), () => timer.cancel()); - - // Wait for last request to be sent - await Future.delayed(Duration(milliseconds: 20)); + for (var i = 0; i < 10; i++) { + await fakeClient.echo(EchoRequest()); + await Future.delayed(timeout * 0.2); + } // Check that the server never closed the connection expect(fakeChannel.newConnectionCounter, 1); @@ -102,9 +104,11 @@ void main() { test('Server doesnt ack the ping, making the client shutdown the connection', () async { await unresponsiveClient.echo(EchoRequest()); - await Future.delayed(Duration(milliseconds: 200)); + await Future.delayed(timeout * 2); await expectLater( - unresponsiveClient.echo(EchoRequest()), throwsA(isA())); + unresponsiveClient.echo(EchoRequest()), + throwsA(isA()), + ); }); } @@ -113,7 +117,7 @@ class FakeClientChannel extends ClientChannel { FakeHttp2ClientConnection? fakeHttp2ClientConnection; FakeClientChannel( super.host, { - super.port = 443, + super.port, super.options = const ChannelOptions(), super.channelShutdownHandler, }); @@ -145,7 +149,7 @@ class FakeHttp2ClientConnection extends Http2ClientConnection { class UnresponsiveClientChannel extends ClientChannel { UnresponsiveClientChannel( super.host, { - super.port = 443, + super.port, super.options = const ChannelOptions(), super.channelShutdownHandler, }); @@ -189,8 +193,6 @@ class FakeEchoService extends EchoServiceBase { @override Stream serverStreamingEcho( - ServiceCall call, ServerStreamingEchoRequest request) { - // TODO: implement serverStreamingEcho - throw UnimplementedError(); - } + ServiceCall call, ServerStreamingEchoRequest request) => + throw UnsupportedError('Not used in this test'); } diff --git a/test/proxy_secure_test.dart b/test/proxy_secure_test.dart index d4deb252..806913b2 100644 --- a/test/proxy_secure_test.dart +++ b/test/proxy_secure_test.dart @@ -33,13 +33,13 @@ void main() { server = Server.create(services: [FakeEchoService()]); await server.serve( address: 'localhost', - port: 8888, + port: 0, security: ServerTlsCredentials( certificate: File('test/data/localhost.crt').readAsBytesSync(), privateKey: File('test/data/localhost.key').readAsBytesSync(), ), ); - final proxy = Proxy(host: 'localhost', port: 8080); + final proxy = Proxy(host: 'localhost', port: 0); final proxyCAName = '/CN=mitmproxy/O=mitmproxy'; fakeChannel = ClientChannel( diff --git a/test/proxy_test.dart b/test/proxy_test.dart index ec832af4..6fc30720 100644 --- a/test/proxy_test.dart +++ b/test/proxy_test.dart @@ -30,9 +30,9 @@ void main() { setUp(() async { server = Server.create(services: [FakeEchoService()]); - await server.serve(address: 'localhost', port: 8888); + await server.serve(address: 'localhost', port: 0); - final proxy = Proxy(host: 'localhost', port: 8080); + final proxy = Proxy(host: 'localhost', port: 0); fakeChannel = ClientChannel( 'localhost', diff --git a/test/server_cancellation_test.dart b/test/server_cancellation_test.dart index 4de5aa28..ab119bb2 100644 --- a/test/server_cancellation_test.dart +++ b/test/server_cancellation_test.dart @@ -47,7 +47,7 @@ void main() { server = Server.create( services: [EchoService()], ); - await server.serve(address: 'localhost', port: 8081); + await server.serve(address: 'localhost', port: 0); channel = ClientChannel( 'localhost', port: server.port!, diff --git a/test/tools/http2_client.dart b/test/tools/http2_client.dart index d7359cd2..9bd40045 100644 --- a/test/tools/http2_client.dart +++ b/test/tools/http2_client.dart @@ -20,7 +20,7 @@ import 'package:grpc/src/client/http2_connection.dart'; import 'package:http2/http2.dart'; Future main(List args) async { - final serverPort = 5678; + final serverPort = 0; final proxyPort = int.tryParse(args.first); final proxy = @@ -37,7 +37,7 @@ Future main(List args) async { final incoming = proxy == null ? connector.socket : await connector.connectToProxy(proxy); - final uri = Uri.parse('http://localhost:8080'); + final uri = Uri.parse('http://localhost:0'); final transport = ClientTransportConnection.viaStreams(incoming, connector.socket);