Skip to content

Commit 1c10535

Browse files
mosuemsteffenhaak
authored andcommitted
Update keepalive_test.dart
1 parent 000791c commit 1c10535

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

test/keepalive_test.dart

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void main() {
3232
late EchoServiceClient fakeClient;
3333
late FakeClientChannel fakeChannel;
3434
late EchoServiceClient unresponsiveClient;
35-
late ClientChannel unresponsiveChannel;
35+
late FakeClientChannel unresponsiveChannel;
3636

3737
setUp(() async {
3838
final serverOptions = ServerKeepAliveOptions(
@@ -99,12 +99,18 @@ void main() {
9999
expect(fakeChannel.newConnectionCounter, 1);
100100
});
101101

102-
test('Server doesnt ack the ping, making the client shutdown the connection',
102+
test('Server doesnt ack the ping, making the client shutdown the transport',
103103
() async {
104+
//Send a first request, get a connection
104105
await unresponsiveClient.echo(EchoRequest());
106+
expect(unresponsiveChannel.newConnectionCounter, 1);
107+
108+
//Ping is not being acked on time
105109
await Future.delayed(Duration(milliseconds: 200));
106-
await expectLater(
107-
unresponsiveClient.echo(EchoRequest()), throwsA(isA<GrpcError>()));
110+
111+
//A second request gets a new connection
112+
await unresponsiveClient.echo(EchoRequest());
113+
expect(unresponsiveChannel.newConnectionCounter, 2);
108114
});
109115
}
110116

@@ -113,7 +119,7 @@ class FakeClientChannel extends ClientChannel {
113119
FakeHttp2ClientConnection? fakeHttp2ClientConnection;
114120
FakeClientChannel(
115121
super.host, {
116-
super.port = 443,
122+
super.port,
117123
super.options = const ChannelOptions(),
118124
super.channelShutdownHandler,
119125
});
@@ -142,20 +148,23 @@ class FakeHttp2ClientConnection extends Http2ClientConnection {
142148
}
143149

144150
/// A wrapper around a [FakeHttp2ClientConnection]
145-
class UnresponsiveClientChannel extends ClientChannel {
151+
class UnresponsiveClientChannel extends FakeClientChannel {
146152
UnresponsiveClientChannel(
147153
super.host, {
148-
super.port = 443,
154+
super.port,
149155
super.options = const ChannelOptions(),
150156
super.channelShutdownHandler,
151157
});
152158

153159
@override
154-
ClientConnection createConnection() =>
155-
UnresponsiveHttp2ClientConnection(host, port, options);
160+
ClientConnection createConnection() {
161+
fakeHttp2ClientConnection =
162+
UnresponsiveHttp2ClientConnection(host, port, options);
163+
return fakeHttp2ClientConnection!;
164+
}
156165
}
157166

158-
class UnresponsiveHttp2ClientConnection extends Http2ClientConnection {
167+
class UnresponsiveHttp2ClientConnection extends FakeHttp2ClientConnection {
159168
UnresponsiveHttp2ClientConnection(super.host, super.port, super.options);
160169

161170
@override
@@ -189,8 +198,6 @@ class FakeEchoService extends EchoServiceBase {
189198

190199
@override
191200
Stream<ServerStreamingEchoResponse> serverStreamingEcho(
192-
ServiceCall call, ServerStreamingEchoRequest request) {
193-
// TODO: implement serverStreamingEcho
194-
throw UnimplementedError();
195-
}
201+
ServiceCall call, ServerStreamingEchoRequest request) =>
202+
throw UnimplementedError();
196203
}

0 commit comments

Comments
 (0)