| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
| 9 | 9 |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 Future testHttpServer1() { | 30 Future testHttpServer1() { |
| 31 return HttpServer.bind('localhost', 0).then((server) { | 31 return HttpServer.bind('localhost', 0).then((server) { |
| 32 var path = getServicePath(server); | 32 var path = getServicePath(server); |
| 33 var map = lookupServiceObject(path); | 33 var map = lookupServiceObject(path); |
| 34 Expect.equals(map['type'], 'HttpServer'); | 34 Expect.equals(map['type'], 'HttpServer'); |
| 35 Expect.equals(map['id'], path); | 35 Expect.equals(map['id'], path); |
| 36 Expect.equals(map['address'], 'localhost'); | 36 Expect.equals(map['address'], 'localhost'); |
| 37 Expect.equals(map['port'], server.port); | 37 Expect.equals(map['port'], server.port); |
| 38 Expect.equals(map['closed'], false); | 38 Expect.equals(map['closed'], false); |
| 39 Expect.equals(map['idle'], 0); | 39 Expect.listEquals(map['idle'], []); |
| 40 Expect.equals(map['active'], 0); | 40 Expect.listEquals(map['active'], []); |
| 41 var socket = map['socket']; | 41 var socket = map['socket']; |
| 42 Expect.equals(socket['type'], '@Socket'); | 42 Expect.equals(socket['type'], '@Socket'); |
| 43 Expect.equals(socket['kind'], 'Listening'); | 43 Expect.equals(socket['kind'], 'Listening'); |
| 44 // Validate owner back-ref. | 44 // Validate owner back-ref. |
| 45 socket = lookupServiceObject(socket['id']); | 45 socket = lookupServiceObject(socket['id']); |
| 46 Expect.equals(socket['owner']['id'], path); | 46 Expect.equals(socket['owner']['id'], path); |
| 47 return server.close(); | 47 return server.close(); |
| 48 }); | 48 }); |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 Future testHttpServerConnection1() { |
| 53 return HttpServer.bind('localhost', 0).then((server) { |
| 54 server.listen((request) { |
| 55 var map = lookupServiceObject(getServicePath(server)); |
| 56 Expect.listEquals(map['idle'], []); |
| 57 Expect.equals(map['active'].length, 1); |
| 58 var active = map['active'].first; |
| 59 Expect.equals(active['type'], '@HttpServerConnection'); |
| 60 var path = active['id']; |
| 61 map = lookupServiceObject(path); |
| 62 Expect.equals(map['type'], 'HttpServerConnection'); |
| 63 var socket = map['socket']; |
| 64 Expect.equals(socket['type'], '@Socket'); |
| 65 Expect.equals(socket['kind'], 'Normal'); |
| 66 // Validate owner back-ref. |
| 67 socket = lookupServiceObject(socket['id']); |
| 68 Expect.equals(socket['owner']['id'], path); |
| 69 request.response.close(); |
| 70 }); |
| 71 var client = new HttpClient(); |
| 72 return client.get('localhost', server.port, '/') |
| 73 .then((request) => request.close()) |
| 74 .then((response) => response.drain()) |
| 75 .then((_) { |
| 76 // The connection should be idle now. |
| 77 var map = lookupServiceObject(getServicePath(server)); |
| 78 Expect.equals(map['idle'].length, 1); |
| 79 Expect.listEquals(map['active'], []); |
| 80 return server.close(); |
| 81 }); |
| 82 |
| 83 }); |
| 84 } |
| 85 |
| 86 |
| 52 void main() { | 87 void main() { |
| 53 final tests = [ | 88 final tests = [ |
| 54 testHttpServer1(), | 89 testHttpServer1(), |
| 90 testHttpServerConnection1(), |
| 55 ]; | 91 ]; |
| 56 | 92 |
| 57 asyncStart(); | 93 asyncStart(); |
| 58 // Run one test at a time. | 94 // Run one test at a time. |
| 59 Future.forEach(tests, (f) => f) | 95 Future.forEach(tests, (f) => f) |
| 60 .then((_) { | 96 .then((_) { |
| 61 asyncEnd(); | 97 asyncEnd(); |
| 62 }); | 98 }); |
| 63 } | 99 } |
| OLD | NEW |