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
This commit is contained in:
Moritz 2024-09-06 15:09:54 +02:00 committed by GitHub
parent 38ca626e0a
commit 81776333d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 36 additions and 32 deletions

View File

@ -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

View File

@ -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

View File

@ -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).

View File

@ -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':

View File

@ -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

View File

@ -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;

View File

@ -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', () {

View File

@ -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', () {

View File

@ -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<GrpcError>()));
unresponsiveClient.echo(EchoRequest()),
throwsA(isA<GrpcError>()),
);
});
}
@ -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<ServerStreamingEchoResponse> serverStreamingEcho(
ServiceCall call, ServerStreamingEchoRequest request) {
// TODO: implement serverStreamingEcho
throw UnimplementedError();
}
ServiceCall call, ServerStreamingEchoRequest request) =>
throw UnsupportedError('Not used in this test');
}

View File

@ -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(

View File

@ -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',

View File

@ -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!,

View File

@ -20,7 +20,7 @@ import 'package:grpc/src/client/http2_connection.dart';
import 'package:http2/http2.dart';
Future<void> main(List<String> args) async {
final serverPort = 5678;
final serverPort = 0;
final proxyPort = int.tryParse(args.first);
final proxy =
@ -37,7 +37,7 @@ Future<void> main(List<String> 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);