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:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 const SESSION_ID = "DARTSESSID"; | 8 const SESSION_ID = "DARTSESSID"; |
9 | 9 |
10 String getSessionId(List<Cookie> cookies) { | 10 String getSessionId(List<Cookie> cookies) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 futures.add(connectGetSession(server.port).then((session) { | 54 futures.add(connectGetSession(server.port).then((session) { |
55 Expect.isNotNull(session); | 55 Expect.isNotNull(session); |
56 Expect.isTrue(sessions.contains(session)); | 56 Expect.isTrue(sessions.contains(session)); |
57 return connectGetSession(server.port, session).then((session2) { | 57 return connectGetSession(server.port, session).then((session2) { |
58 Expect.equals(session2, session); | 58 Expect.equals(session2, session); |
59 Expect.isTrue(sessions.contains(session2)); | 59 Expect.isTrue(sessions.contains(session2)); |
60 return session2; | 60 return session2; |
61 }); | 61 }); |
62 })); | 62 })); |
63 } | 63 } |
64 Futures.wait(futures).then((clientSessions) { | 64 Future.wait(futures).then((clientSessions) { |
65 Expect.equals(sessions.length, sessionCount); | 65 Expect.equals(sessions.length, sessionCount); |
66 Expect.setEquals(new Set.from(clientSessions), sessions); | 66 Expect.setEquals(new Set.from(clientSessions), sessions); |
67 server.close(); | 67 server.close(); |
68 }); | 68 }); |
69 } | 69 } |
70 | 70 |
71 void testTimeout(int sessionCount) { | 71 void testTimeout(int sessionCount) { |
72 HttpServer server = new HttpServer(); | 72 HttpServer server = new HttpServer(); |
73 server.sessionTimeout = 0; | 73 server.sessionTimeout = 0; |
74 server.listen("127.0.0.1", 0); | 74 server.listen("127.0.0.1", 0); |
75 var timeouts = []; | 75 var timeouts = []; |
76 server.defaultRequestHandler = (request, response) { | 76 server.defaultRequestHandler = (request, response) { |
77 var c = new Completer(); | 77 var c = new Completer(); |
78 timeouts.add(c.future); | 78 timeouts.add(c.future); |
79 request.session().onTimeout = () { | 79 request.session().onTimeout = () { |
80 c.complete(null); | 80 c.complete(null); |
81 }; | 81 }; |
82 response.outputStream.close(); | 82 response.outputStream.close(); |
83 }; | 83 }; |
84 | 84 |
85 var futures = []; | 85 var futures = []; |
86 for (int i = 0; i < sessionCount; i++) { | 86 for (int i = 0; i < sessionCount; i++) { |
87 futures.add(connectGetSession(server.port)); | 87 futures.add(connectGetSession(server.port)); |
88 } | 88 } |
89 Futures.wait(futures).then((clientSessions) { | 89 Future.wait(futures).then((clientSessions) { |
90 Futures.wait(timeouts).then((_) { | 90 Future.wait(timeouts).then((_) { |
91 futures = []; | 91 futures = []; |
92 for (var id in clientSessions) { | 92 for (var id in clientSessions) { |
93 futures.add(connectGetSession(server.port, id).then((session) { | 93 futures.add(connectGetSession(server.port, id).then((session) { |
94 Expect.isNotNull(session); | 94 Expect.isNotNull(session); |
95 Expect.notEquals(id, session); | 95 Expect.notEquals(id, session); |
96 })); | 96 })); |
97 } | 97 } |
98 Futures.wait(futures).then((_) { | 98 Future.wait(futures).then((_) { |
99 server.close(); | 99 server.close(); |
100 }); | 100 }); |
101 }); | 101 }); |
102 }); | 102 }); |
103 } | 103 } |
104 | 104 |
105 void main() { | 105 void main() { |
106 testSessions(5); | 106 testSessions(5); |
107 testTimeout(5); | 107 testTimeout(5); |
108 } | 108 } |
OLD | NEW |