-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ package:dds ] Silently handle exceptions raised within RPC request
handlers Fixes flutter/flutter#84113 Change-Id: I416308845c5c7f9a1bb547b6429f1e9d49393583 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212268 Reviewed-by: Zach Anderson <zra@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
- Loading branch information
Showing
4 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:dds/dds.dart'; | ||
import 'package:dds/src/dds_impl.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:web_socket_channel/web_socket_channel.dart'; | ||
|
||
import 'common/fakes.dart'; | ||
|
||
Future<HttpServer> startHttpServer() async { | ||
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0); | ||
server.listen((event) async { | ||
event.response.add([1, 2, 3]); | ||
await event.response.flush(); | ||
await server.close(force: true); | ||
}); | ||
return server; | ||
} | ||
|
||
void main() { | ||
webSocketBuilder = (Uri _) => FakeWebSocketChannel(); | ||
peerBuilder = (WebSocketChannel _, dynamic __) async => FakePeer(); | ||
|
||
test("Handles 'Connection closed before full header was received'", () async { | ||
final httpServer = await startHttpServer(); | ||
final dds = await DartDevelopmentService.startDartDevelopmentService( | ||
Uri(scheme: 'http', host: httpServer.address.host, port: httpServer.port), | ||
enableAuthCodes: false, | ||
); | ||
final uri = dds.uri!; | ||
|
||
try { | ||
final client = HttpClient(); | ||
final request = await client.get(uri.host, uri.port, 'getVM'); | ||
await request.close(); | ||
fail('Unexpected successful response'); | ||
} catch (e) { | ||
expect( | ||
e.toString(), | ||
contains( | ||
'Connection closed before full header was received', | ||
), | ||
); | ||
} finally { | ||
await dds.shutdown(); | ||
await dds.done; | ||
} | ||
}); | ||
} |