Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: tests/standalone/io/http_session_test.dart

Issue 14640008: Change the signature for all network bind calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments by whesse@ Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/standalone/io/http_server_test.dart ('k') | tests/standalone/io/http_shutdown_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8
9 const SESSION_ID = "DARTSESSID"; 9 const SESSION_ID = "DARTSESSID";
10 10
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 return request.close(); 31 return request.close();
32 }) 32 })
33 .then((response) { 33 .then((response) {
34 return response.fold(getSessionId(response.cookies), (v, _) => v); 34 return response.fold(getSessionId(response.cookies), (v, _) => v);
35 }); 35 });
36 } 36 }
37 37
38 void testSessions(int sessionCount) { 38 void testSessions(int sessionCount) {
39 var client = new HttpClient(); 39 var client = new HttpClient();
40 HttpServer.bind().then((server) { 40 HttpServer.bind("127.0.0.1", 0).then((server) {
41 var sessions = new Set(); 41 var sessions = new Set();
42 server.listen((request) { 42 server.listen((request) {
43 sessions.add(request.session.id); 43 sessions.add(request.session.id);
44 request.response.close(); 44 request.response.close();
45 }); 45 });
46 46
47 var futures = []; 47 var futures = [];
48 for (int i = 0; i < sessionCount; i++) { 48 for (int i = 0; i < sessionCount; i++) {
49 futures.add(connectGetSession(client, server.port).then((session) { 49 futures.add(connectGetSession(client, server.port).then((session) {
50 Expect.isNotNull(session); 50 Expect.isNotNull(session);
51 Expect.isTrue(sessions.contains(session)); 51 Expect.isTrue(sessions.contains(session));
52 return connectGetSession(client, server.port, session).then((session2) { 52 return connectGetSession(client, server.port, session).then((session2) {
53 Expect.equals(session2, session); 53 Expect.equals(session2, session);
54 Expect.isTrue(sessions.contains(session2)); 54 Expect.isTrue(sessions.contains(session2));
55 return session2; 55 return session2;
56 }); 56 });
57 })); 57 }));
58 } 58 }
59 Future.wait(futures).then((clientSessions) { 59 Future.wait(futures).then((clientSessions) {
60 Expect.equals(sessions.length, sessionCount); 60 Expect.equals(sessions.length, sessionCount);
61 Expect.setEquals(new Set.from(clientSessions), sessions); 61 Expect.setEquals(new Set.from(clientSessions), sessions);
62 server.close(); 62 server.close();
63 client.close(); 63 client.close();
64 }); 64 });
65 }); 65 });
66 } 66 }
67 67
68 void testTimeout(int sessionCount) { 68 void testTimeout(int sessionCount) {
69 var client = new HttpClient(); 69 var client = new HttpClient();
70 HttpServer.bind().then((server) { 70 HttpServer.bind("127.0.0.1", 0).then((server) {
71 server.sessionTimeout = 0; 71 server.sessionTimeout = 0;
72 var timeouts = []; 72 var timeouts = [];
73 server.listen((request) { 73 server.listen((request) {
74 var c = new Completer(); 74 var c = new Completer();
75 timeouts.add(c.future); 75 timeouts.add(c.future);
76 request.session.onTimeout = () { 76 request.session.onTimeout = () {
77 c.complete(null); 77 c.complete(null);
78 }; 78 };
79 request.response.close(); 79 request.response.close();
80 }); 80 });
(...skipping 15 matching lines...) Expand all
96 Future.wait(futures).then((_) { 96 Future.wait(futures).then((_) {
97 server.close(); 97 server.close();
98 client.close(); 98 client.close();
99 }); 99 });
100 }); 100 });
101 }); 101 });
102 }); 102 });
103 } 103 }
104 104
105 void testSessionsData() { 105 void testSessionsData() {
106 HttpServer.bind().then((server) { 106 HttpServer.bind("127.0.0.1", 0).then((server) {
107 bool firstHit = false; 107 bool firstHit = false;
108 bool secondHit = false; 108 bool secondHit = false;
109 server.listen((request) { 109 server.listen((request) {
110 var c = new Completer(); 110 var c = new Completer();
111 var session = request.session; 111 var session = request.session;
112 if (session.isNew) { 112 if (session.isNew) {
113 Expect.isFalse(firstHit); 113 Expect.isFalse(firstHit);
114 Expect.isFalse(secondHit); 114 Expect.isFalse(secondHit);
115 firstHit = true; 115 firstHit = true;
116 session["data"] = "some data"; 116 session["data"] = "some data";
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 }); 148 });
149 }); 149 });
150 }); 150 });
151 } 151 }
152 152
153 void main() { 153 void main() {
154 testSessions(1); 154 testSessions(1);
155 testTimeout(5); 155 testTimeout(5);
156 testSessionsData(); 156 testSessionsData();
157 } 157 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_server_test.dart ('k') | tests/standalone/io/http_shutdown_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698