Add deadline repro test

This commit is contained in:
Moritz 2024-01-22 10:21:08 +01:00
parent e54366e1e4
commit a1e3dab7bb
1 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,70 @@
@TestOn('vm')
import 'dart:async';
import 'package:grpc/grpc.dart';
import 'package:test/test.dart';
import 'src/generated/echo.pbgrpc.dart';
void main() {
late Server server;
late EchoServiceClient fakeClient;
late ClientChannel fakeChannel;
setUp(() async {
server = Server.create(
services: [EchoService()],
codecRegistry: CodecRegistry(
codecs: const [GzipCodec(), IdentityCodec()],
),
);
await server.serve(address: 'localhost', port: 8081);
final options = ChannelOptions(
credentials: const ChannelCredentials.insecure(),
codecRegistry: CodecRegistry(
codecs: const [GzipCodec(), IdentityCodec()],
),
);
fakeChannel = ClientChannel(
'localhost',
port: server.port!,
options: options,
);
fakeClient = EchoServiceClient(fakeChannel);
});
tearDown(() async {
await fakeChannel.shutdown();
await server.shutdown();
});
test('Ping twice', () async {
final callOptions = CallOptions(
timeout: Duration(microseconds: 50),
);
for (var i = 0; i < 100; i++) {
expectLater(
() => fakeClient.echo(
EchoRequest(message: 'some message'),
options: callOptions,
),
throwsA(isA<GrpcError>()),
);
}
});
}
class EchoService extends EchoServiceBase {
@override
Future<EchoResponse> echo(ServiceCall call, EchoRequest request) async {
await Future.delayed(Duration(milliseconds: 1));
return EchoResponse(
message: String.fromCharCodes(request.message.codeUnits.reversed));
}
@override
Stream<ServerStreamingEchoResponse> serverStreamingEcho(
ServiceCall call, ServerStreamingEchoRequest request) {
throw UnimplementedError();
}
}