OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import "dart:async"; | 6 import "dart:async"; |
7 import "dart:io"; | 7 import "dart:io"; |
8 import "dart:isolate"; | 8 import "dart:isolate"; |
9 | 9 |
10 void testListenOn() { | 10 void testListenOn() { |
(...skipping 21 matching lines...) Expand all Loading... |
32 }) | 32 }) |
33 .catchError((e) { | 33 .catchError((e) { |
34 String msg = "Unexpected error in Http Client: $e"; | 34 String msg = "Unexpected error in Http Client: $e"; |
35 var trace = getAttachedStackTrace(e); | 35 var trace = getAttachedStackTrace(e); |
36 if (trace != null) msg += "\nStackTrace: $trace"; | 36 if (trace != null) msg += "\nStackTrace: $trace"; |
37 Expect.fail(msg); | 37 Expect.fail(msg); |
38 }); | 38 }); |
39 } | 39 } |
40 | 40 |
41 // Test two connection after each other. | 41 // Test two connection after each other. |
42 ServerSocket.bind().then((s) { | 42 ServerSocket.bind("127.0.0.1", 0).then((s) { |
43 socket = s; | 43 socket = s; |
44 server = new HttpServer.listenOn(socket); | 44 server = new HttpServer.listenOn(socket); |
45 ReceivePort serverPort = new ReceivePort(); | 45 ReceivePort serverPort = new ReceivePort(); |
46 server.listen((HttpRequest request) { | 46 server.listen((HttpRequest request) { |
47 request.listen( | 47 request.listen( |
48 (_) {}, | 48 (_) {}, |
49 onDone: () { | 49 onDone: () { |
50 request.response.close(); | 50 request.response.close(); |
51 serverPort.close(); | 51 serverPort.close(); |
52 }); | 52 }); |
53 }); | 53 }); |
54 | 54 |
55 test(() { | 55 test(() { |
56 test(() { | 56 test(() { |
57 server.close(); | 57 server.close(); |
58 Expect.throws(() => server.port); | 58 Expect.throws(() => server.port); |
59 socket.close(); | 59 socket.close(); |
60 }); | 60 }); |
61 }); | 61 }); |
62 }); | 62 }); |
63 } | 63 } |
64 | 64 |
65 void main() { | 65 void main() { |
66 testListenOn(); | 66 testListenOn(); |
67 } | 67 } |
OLD | NEW |