Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #732

Merged
merged 11 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions lib/src/shared/status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/client_tests/client_xhr_transport_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/client_tests/grpc_or_grpcweb_channel_grpc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
2 changes: 1 addition & 1 deletion test/client_tests/grpc_or_grpcweb_channel_web_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
38 changes: 20 additions & 18 deletions test/keepalive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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>()),
);
});
}

Expand All @@ -113,7 +117,7 @@ class FakeClientChannel extends ClientChannel {
FakeHttp2ClientConnection? fakeHttp2ClientConnection;
FakeClientChannel(
super.host, {
super.port = 443,
super.port,
super.options = const ChannelOptions(),
super.channelShutdownHandler,
});
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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');
}
4 changes: 2 additions & 2 deletions test/proxy_secure_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions test/proxy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/server_cancellation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
Expand Down
4 changes: 2 additions & 2 deletions test/tools/http2_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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);
Expand Down