OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // |
| 5 // This test checks that sockets belonging to an isolate are properly cleaned up |
| 6 // when the isolate shuts down abnormally. If the socket is not properly cleaned |
| 7 // up, the test will time out. |
| 8 |
| 9 import 'dart:async'; |
| 10 import 'dart:io'; |
| 11 import 'dart:isolate'; |
| 12 |
| 13 import "package:async_helper/async_helper.dart"; |
| 14 import "package:expect/expect.dart"; |
| 15 |
| 16 ConnectorIsolate(int port) async { |
| 17 Socket socket = await Socket.connect("127.0.0.1", port); |
| 18 socket.listen((_) {}); |
| 19 } |
| 20 |
| 21 main() async { |
| 22 asyncStart(); |
| 23 ServerSocket server = await ServerSocket.bind("127.0.0.1", 0); |
| 24 Isolate isolate = await Isolate.spawn(ConnectorIsolate, server.port); |
| 25 Completer<Null> completer = new Completer<Null>(); |
| 26 server.listen((Socket socket) { |
| 27 socket.listen((_) {}, onDone: () { |
| 28 print("Socket closed normally"); |
| 29 completer.complete(null); |
| 30 socket.close(); |
| 31 }, onError: (e) { |
| 32 Expect.fail("Socket error $e"); |
| 33 }); |
| 34 isolate.kill(); |
| 35 }); |
| 36 await completer.future; |
| 37 await server.close(); |
| 38 asyncEnd(); |
| 39 } |
OLD | NEW |