Skip to content

Commit c7e07a0

Browse files
authored
Fix interop tests (#651)
* Fix interop tests * Keepalive cleanups * Prepare for publish
1 parent 8886dfd commit c7e07a0

File tree

8 files changed

+17
-13
lines changed

8 files changed

+17
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
## 3.2.3-wip
1+
## 3.2.3
22

33
* Add const constructor to `GrpcError` fixing #606.
44
* Make `GrpcError` non-final to allow implementations.
55
* Only send keepalive pings on open connections.
6+
* Fix interop tests.
67

78
## 3.2.2
89

lib/grpc.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export 'src/auth/auth_io.dart'
2121
ServiceAccountAuthenticator;
2222
export 'src/client/call.dart' show ClientCall;
2323
export 'src/client/client.dart' show Client;
24+
export 'src/client/client_keepalive.dart' show ClientKeepAliveOptions;
2425
export 'src/client/client_transport_connector.dart'
2526
show ClientTransportConnector;
2627
export 'src/client/connection.dart' show ConnectionState;
@@ -50,6 +51,7 @@ export 'src/server/server.dart'
5051
ServerTlsCredentials,
5152
ConnectionServer,
5253
Server;
54+
export 'src/server/server_keepalive.dart' show ServerKeepAliveOptions;
5355
export 'src/server/service.dart' show ServiceMethod, Service;
5456
export 'src/shared/api.dart';
5557
export 'src/shared/codec.dart' show Codec, IdentityCodec, GzipCodec;

lib/src/client/client_keepalive.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ClientKeepAliveOptions {
2727

2828
const ClientKeepAliveOptions({
2929
this.pingInterval,
30-
this.timeout = const Duration(milliseconds: 20000),
30+
this.timeout = const Duration(seconds: 20),
3131
this.permitWithoutCalls = false,
3232
});
3333

@@ -189,7 +189,7 @@ class ClientKeepAlive {
189189
final void Function() ping;
190190

191191
final ClientKeepAliveOptions _options;
192-
Duration get _pingInterval => _options.pingInterval ?? Duration(days: 365);
192+
Duration get _pingInterval => _options.pingInterval!;
193193

194194
ClientKeepAlive({
195195
required ClientKeepAliveOptions options,
@@ -236,7 +236,9 @@ class ClientKeepAlive {
236236
}
237237

238238
void _setState(KeepAliveEvent event) {
239-
final newState = state.onEvent(event, this);
240-
if (newState != null) state = newState;
239+
if (_options.shouldSendPings) {
240+
final newState = state.onEvent(event, this);
241+
if (newState != null) state = newState;
242+
}
241243
}
242244
}

lib/src/server/server.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class ConnectionServer {
9090
final CodecRegistry? _codecRegistry;
9191
final GrpcErrorHandler? _errorHandler;
9292
final ServerKeepAliveOptions _keepAliveOptions;
93-
final List<ServerHandler> _handlers = [];
93+
final Map<ServerTransportConnection, List<ServerHandler>> _handlers = {};
9494

9595
final _connections = <ServerTransportConnection>[];
9696

@@ -117,6 +117,7 @@ class ConnectionServer {
117117
InternetAddress? remoteAddress,
118118
}) async {
119119
_connections.add(connection);
120+
_handlers[connection] = [];
120121
// TODO(jakobr): Set active state handlers, close connection after idle
121122
// timeout.
122123
final onDataReceivedController = StreamController<void>();
@@ -128,7 +129,7 @@ class ConnectionServer {
128129
dataNotifier: onDataReceivedController.stream,
129130
).handle();
130131
connection.incomingStreams.listen((stream) {
131-
_handlers.add(serveStream_(
132+
_handlers[connection]!.add(serveStream_(
132133
stream: stream,
133134
clientCertificate: clientCertificate,
134135
remoteAddress: remoteAddress,
@@ -143,10 +144,11 @@ class ConnectionServer {
143144
// half-closed tcp streams.
144145
// Half-closed streams seems to not be fully supported by package:http2.
145146
// https://github.com/dart-lang/http2/issues/42
146-
for (var handler in _handlers) {
147+
for (var handler in _handlers[connection]!) {
147148
handler.cancel();
148149
}
149150
_connections.remove(connection);
151+
_handlers.remove(connection);
150152
await onDataReceivedController.close();
151153
});
152154
}

lib/src/server/server_keepalive.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class ServerKeepAliveOptions {
1414
final Duration minIntervalBetweenPingsWithoutData;
1515

1616
const ServerKeepAliveOptions({
17-
this.minIntervalBetweenPingsWithoutData =
18-
const Duration(milliseconds: 300000),
17+
this.minIntervalBetweenPingsWithoutData = const Duration(minutes: 5),
1918
this.maxBadPings = 2,
2019
});
2120
}

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: 3.2.3-wip
3+
version: 3.2.3
44

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

test/keepalive_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:grpc/grpc.dart';
55
import 'package:grpc/src/client/client_keepalive.dart';
66
import 'package:grpc/src/client/connection.dart';
77
import 'package:grpc/src/client/http2_connection.dart';
8-
import 'package:grpc/src/server/server_keepalive.dart';
98
import 'package:http2/transport.dart';
109
import 'package:test/test.dart';
1110

test/src/client_utils.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import 'dart:convert';
1818

1919
import 'package:grpc/grpc.dart';
2020
import 'package:grpc/src/client/channel.dart' as base;
21-
import 'package:grpc/src/client/client_keepalive.dart';
2221
import 'package:grpc/src/client/http2_connection.dart';
2322
import 'package:grpc/src/shared/message.dart';
2423
import 'package:http2/transport.dart';

0 commit comments

Comments
 (0)