OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:io"; | 5 import 'dart:async'; |
| 6 import 'dart:io'; |
6 | 7 |
7 const SESSION_ID = "DARTSESSID"; | 8 const SESSION_ID = "DARTSESSID"; |
8 | 9 |
9 String getSessionId(List<Cookie> cookies) { | 10 String getSessionId(List<Cookie> cookies) { |
10 var id = cookies.reduce(null, (last, cookie) { | 11 var id = cookies.reduce(null, (last, cookie) { |
11 if (last != null) return last; | 12 if (last != null) return last; |
12 if (cookie.name.toUpperCase() == SESSION_ID) { | 13 if (cookie.name.toUpperCase() == SESSION_ID) { |
13 Expect.isTrue(cookie.httpOnly); | 14 Expect.isTrue(cookie.httpOnly); |
14 return cookie.value; | 15 return cookie.value; |
15 } | 16 } |
(...skipping 27 matching lines...) Expand all Loading... |
43 HttpServer server = new HttpServer(); | 44 HttpServer server = new HttpServer(); |
44 server.listen("127.0.0.1", 0); | 45 server.listen("127.0.0.1", 0); |
45 var sessions = new Set(); | 46 var sessions = new Set(); |
46 server.defaultRequestHandler = (request, response) { | 47 server.defaultRequestHandler = (request, response) { |
47 sessions.add(request.session().id); | 48 sessions.add(request.session().id); |
48 response.outputStream.close(); | 49 response.outputStream.close(); |
49 }; | 50 }; |
50 | 51 |
51 var futures = []; | 52 var futures = []; |
52 for (int i = 0; i < sessionCount; i++) { | 53 for (int i = 0; i < sessionCount; i++) { |
53 futures.add(connectGetSession(server.port).chain((session) { | 54 futures.add(connectGetSession(server.port).then((session) { |
54 Expect.isNotNull(session); | 55 Expect.isNotNull(session); |
55 Expect.isTrue(sessions.contains(session)); | 56 Expect.isTrue(sessions.contains(session)); |
56 return connectGetSession(server.port, session).transform((session2) { | 57 return connectGetSession(server.port, session).then((session2) { |
57 Expect.equals(session2, session); | 58 Expect.equals(session2, session); |
58 Expect.isTrue(sessions.contains(session2)); | 59 Expect.isTrue(sessions.contains(session2)); |
59 return session2; | 60 return session2; |
60 }); | 61 }); |
61 })); | 62 })); |
62 } | 63 } |
63 Futures.wait(futures).then((clientSessions) { | 64 Futures.wait(futures).then((clientSessions) { |
64 Expect.equals(sessions.length, sessionCount); | 65 Expect.equals(sessions.length, sessionCount); |
65 Expect.setEquals(new Set.from(clientSessions), sessions); | 66 Expect.setEquals(new Set.from(clientSessions), sessions); |
66 server.close(); | 67 server.close(); |
(...skipping 15 matching lines...) Expand all Loading... |
82 }; | 83 }; |
83 | 84 |
84 var futures = []; | 85 var futures = []; |
85 for (int i = 0; i < sessionCount; i++) { | 86 for (int i = 0; i < sessionCount; i++) { |
86 futures.add(connectGetSession(server.port)); | 87 futures.add(connectGetSession(server.port)); |
87 } | 88 } |
88 Futures.wait(futures).then((clientSessions) { | 89 Futures.wait(futures).then((clientSessions) { |
89 Futures.wait(timeouts).then((_) { | 90 Futures.wait(timeouts).then((_) { |
90 futures = []; | 91 futures = []; |
91 for (var id in clientSessions) { | 92 for (var id in clientSessions) { |
92 futures.add(connectGetSession(server.port, id).transform((session) { | 93 futures.add(connectGetSession(server.port, id).then((session) { |
93 Expect.isNotNull(session); | 94 Expect.isNotNull(session); |
94 Expect.notEquals(id, session); | 95 Expect.notEquals(id, session); |
95 })); | 96 })); |
96 } | 97 } |
97 Futures.wait(futures).then((_) { | 98 Futures.wait(futures).then((_) { |
98 server.close(); | 99 server.close(); |
99 }); | 100 }); |
100 }); | 101 }); |
101 }); | 102 }); |
102 } | 103 } |
103 | 104 |
104 void main() { | 105 void main() { |
105 testSessions(5); | 106 testSessions(5); |
106 testTimeout(5); | 107 testTimeout(5); |
107 } | 108 } |
OLD | NEW |