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

Side by Side Diff: pkg/scheduled_test/test/scheduled_server_test.dart

Issue 12678011: Miscellaneous small improvements for scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Guard against issue 9151 more thoroughly. Created 7 years, 9 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 | « pkg/scheduled_test/lib/src/utils.dart ('k') | no next file » | 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 library scheduled_server_test; 5 library scheduled_server_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import '../../../pkg/http/lib/http.dart' as http; 10 import '../../../pkg/http/lib/http.dart' as http;
(...skipping 17 matching lines...) Expand all
28 errors = currentSchedule.errors; 28 errors = currentSchedule.errors;
29 }); 29 });
30 30
31 var server = new ScheduledServer(); 31 var server = new ScheduledServer();
32 expect(server.url.then((url) => http.read(url.resolve('/hello'))), 32 expect(server.url.then((url) => http.read(url.resolve('/hello'))),
33 completion(equals('Hello, test!'))); 33 completion(equals('Hello, test!')));
34 }); 34 });
35 35
36 test('test 2', () { 36 test('test 2', () {
37 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 37 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
38 expect(errors.length, equals(2)); 38 // TODO(nweiz): There can be three errors due to issue 9151. The
39 // HttpParserException is reported without a stack trace, and so when it's
40 // wrapped twice it registers as a different exception each time (because
41 // it's given an ad-hoc stack trace). Always expect two exceptions when
42 // issue 9151 is fixed.
43 expect(errors.length, inInclusiveRange(2, 3));
39 expect(errors[0].error, equals("'scheduled server 0' received GET /hello " 44 expect(errors[0].error, equals("'scheduled server 0' received GET /hello "
40 "when no more requests were expected.")); 45 "when no more requests were expected."));
41 expect(errors[1].error, new isInstanceOf<HttpParserException>()); 46 expect(errors[1].error, new isInstanceOf<HttpParserException>());
47 if (errors.length > 2) {
48 expect(errors[2].error, new isInstanceOf<HttpParserException>());
49 }
42 }); 50 });
43 }, passing: ['test 2']); 51 }, passing: ['test 2']);
44 52
45 expectTestsPass("a handler runs when it's hit", () { 53 expectTestsPass("a handler runs when it's hit", () {
46 test('test', () { 54 test('test', () {
47 var server = new ScheduledServer(); 55 var server = new ScheduledServer();
48 expect(server.url.then((url) => http.read(url.resolve('/hello'))), 56 expect(server.url.then((url) => http.read(url.resolve('/hello'))),
49 completion(equals('Hello, test!'))); 57 completion(equals('Hello, test!')));
50 58
51 server.handle('GET', '/hello', (request) { 59 server.handle('GET', '/hello', (request) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // for the immediately-preceding task. 100 // for the immediately-preceding task.
93 schedule(() => null); 101 schedule(() => null);
94 102
95 server.handle('GET', '/hello', (request) { 103 server.handle('GET', '/hello', (request) {
96 request.response.write('Hello, test!'); 104 request.response.write('Hello, test!');
97 request.response.close(); 105 request.response.close();
98 }); 106 });
99 }); 107 });
100 108
101 test('test 2', () { 109 test('test 2', () {
102 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 110 // TODO(nweiz): There can be three errors due to issue 9151. The
103 expect(errors.length, equals(2)); 111 // HttpParserException is reported without a stack trace, and so when it's
112 // wrapped twice it registers as a different exception each time (because
113 // it's given an ad-hoc stack trace). Always expect two exceptions when
114 // issue 9151 is fixed.
115 expect(errors.length, inInclusiveRange(2, 3));
104 expect(errors[0].error, equals("'scheduled server 0' received GET /hello " 116 expect(errors[0].error, equals("'scheduled server 0' received GET /hello "
105 "earlier than expected.")); 117 "earlier than expected."));
106 expect(errors[1].error, new isInstanceOf<HttpParserException>()); 118 expect(errors[1].error, new isInstanceOf<HttpParserException>());
119 if (errors.length > 2) {
120 expect(errors[2].error, new isInstanceOf<HttpParserException>());
121 }
122 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
107 }); 123 });
108 }, passing: ['test 2']); 124 }, passing: ['test 2']);
109 125
110 expectTestsPass("a handler waits for the immediately prior task to complete " 126 expectTestsPass("a handler waits for the immediately prior task to complete "
111 "before checking if it's too early", () { 127 "before checking if it's too early", () {
112 test('test', () { 128 test('test', () {
113 var server = new ScheduledServer(); 129 var server = new ScheduledServer();
114 expect(server.url.then((url) => http.read(url.resolve('/hello'))), 130 expect(server.url.then((url) => http.read(url.resolve('/hello'))),
115 completion(equals('Hello, test!'))); 131 completion(equals('Hello, test!')));
116 132
(...skipping 23 matching lines...) Expand all
140 expect(server.url.then((url) => http.read(url.resolve('/hello'))), 156 expect(server.url.then((url) => http.read(url.resolve('/hello'))),
141 completion(equals('Hello, test!'))); 157 completion(equals('Hello, test!')));
142 158
143 server.handle('GET', '/goodbye', (request) { 159 server.handle('GET', '/goodbye', (request) {
144 request.response.write('Goodbye, test!'); 160 request.response.write('Goodbye, test!');
145 request.response.close(); 161 request.response.close();
146 }); 162 });
147 }); 163 });
148 164
149 test('test 2', () { 165 test('test 2', () {
150 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 166 // TODO(nweiz): There can be three errors due to issue 9151. The
151 expect(errors.length, equals(2)); 167 // HttpParserException is reported without a stack trace, and so when it's
168 // wrapped twice it registers as a different exception each time (because
169 // it's given an ad-hoc stack trace). Always expect two exceptions when
170 // issue 9151 is fixed.
171 expect(errors.length, inInclusiveRange(2, 3));
152 expect(errors[0].error, equals("'scheduled server 0' expected GET " 172 expect(errors[0].error, equals("'scheduled server 0' expected GET "
153 "/goodbye, but got GET /hello.")); 173 "/goodbye, but got GET /hello."));
154 expect(errors[1].error, new isInstanceOf<HttpParserException>()); 174 expect(errors[1].error, new isInstanceOf<HttpParserException>());
175 if (errors.length > 2) {
176 expect(errors[2].error, new isInstanceOf<HttpParserException>());
177 }
155 }); 178 });
156 }, passing: ['test 2']); 179 }, passing: ['test 2']);
157 180
158 expectTestsPass("a handler fails if the method is wrong", () { 181 expectTestsPass("a handler fails if the method is wrong", () {
159 var errors; 182 var errors;
160 test('test 1', () { 183 test('test 1', () {
161 currentSchedule.onException.schedule(() { 184 currentSchedule.onException.schedule(() {
162 errors = currentSchedule.errors; 185 errors = currentSchedule.errors;
163 }); 186 });
164 187
165 var server = new ScheduledServer(); 188 var server = new ScheduledServer();
166 expect(server.url.then((url) => http.head(url.resolve('/hello'))), 189 expect(server.url.then((url) => http.head(url.resolve('/hello'))),
167 completes); 190 completes);
168 191
169 server.handle('GET', '/hello', (request) { 192 server.handle('GET', '/hello', (request) {
170 request.response.write('Hello, test!'); 193 request.response.write('Hello, test!');
171 request.response.close(); 194 request.response.close();
172 }); 195 });
173 }); 196 });
174 197
175 test('test 2', () { 198 test('test 2', () {
176 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 199 // TODO(nweiz): There can be three errors due to issue 9151. The
177 expect(errors.length, equals(2)); 200 // HttpParserException is reported without a stack trace, and so when it's
201 // wrapped twice it registers as a different exception each time (because
202 // it's given an ad-hoc stack trace). Always expect two exceptions when
203 // issue 9151 is fixed.
204 expect(errors.length, inInclusiveRange(2, 3));
178 expect(errors[0].error, equals("'scheduled server 0' expected GET " 205 expect(errors[0].error, equals("'scheduled server 0' expected GET "
179 "/hello, but got HEAD /hello.")); 206 "/hello, but got HEAD /hello."));
180 expect(errors[1].error, new isInstanceOf<HttpParserException>()); 207 expect(errors[1].error, new isInstanceOf<HttpParserException>());
208 if (errors.length > 2) {
209 expect(errors[2].error, new isInstanceOf<HttpParserException>());
210 }
181 }); 211 });
182 }, passing: ['test 2']); 212 }, passing: ['test 2']);
183 213
184 expectTestsPass("a handler times out waiting to be hit", () { 214 expectTestsPass("a handler times out waiting to be hit", () {
185 var clock = mock_clock.mock()..run(); 215 var clock = mock_clock.mock()..run();
186 var timeOfException; 216 var timeOfException;
187 var errors; 217 var errors;
188 test('test 1', () { 218 test('test 1', () {
189 currentSchedule.timeout = new Duration(milliseconds: 2); 219 currentSchedule.timeout = new Duration(milliseconds: 2);
190 currentSchedule.onException.schedule(() { 220 currentSchedule.onException.schedule(() {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 request.response.close(); 294 request.response.close();
265 }); 295 });
266 296
267 server.handle('GET', '/hello/2', (request) { 297 server.handle('GET', '/hello/2', (request) {
268 request.response.write('Hello, request 2!'); 298 request.response.write('Hello, request 2!');
269 request.response.close(); 299 request.response.close();
270 }); 300 });
271 }); 301 });
272 302
273 test('test 2', () { 303 test('test 2', () {
274 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 304 // TODO(nweiz): There can be three errors due to issue 9151. The
275 expect(errors.length, equals(2)); 305 // HttpParserException is reported without a stack trace, and so when it's
306 // wrapped twice it registers as a different exception each time (because
307 // it's given an ad-hoc stack trace). Always expect two exceptions when
308 // issue 9151 is fixed.
309 expect(errors.length, inInclusiveRange(2, 3));
276 expect(errors[0].error, equals("'scheduled server 0' received GET " 310 expect(errors[0].error, equals("'scheduled server 0' received GET "
277 "/hello/3 when no more requests were expected.")); 311 "/hello/3 when no more requests were expected."));
278 expect(errors[1].error, new isInstanceOf<HttpParserException>()); 312 expect(errors[1].error, new isInstanceOf<HttpParserException>());
313 if (errors.length > 2) {
314 expect(errors[2].error, new isInstanceOf<HttpParserException>());
315 }
279 }); 316 });
280 }, passing: ['test 2']); 317 }, passing: ['test 2']);
281 318
282 expectTestsPass("an error in a handler doesn't cause a timeout", () { 319 expectTestsPass("an error in a handler doesn't cause a timeout", () {
283 var errors; 320 var errors;
284 test('test 1', () { 321 test('test 1', () {
285 currentSchedule.onException.schedule(() { 322 currentSchedule.onException.schedule(() {
286 errors = currentSchedule.errors; 323 errors = currentSchedule.errors;
287 }); 324 });
288 325
289 var server = new ScheduledServer(); 326 var server = new ScheduledServer();
290 expect(server.url.then((url) => http.read(url.resolve('/hello'))), 327 expect(server.url.then((url) => http.read(url.resolve('/hello'))),
291 completion(equals('Hello, test!'))); 328 completion(equals('Hello, test!')));
292 329
293 server.handle('GET', '/hello', (request) { 330 server.handle('GET', '/hello', (request) {
294 throw 'oh no'; 331 throw 'oh no';
295 }); 332 });
296 }); 333 });
297 334
298 test('test 2', () { 335 test('test 2', () {
299 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 336 // TODO(nweiz): There can be three errors due to issue 9151. The
300 expect(errors.length, equals(2)); 337 // HttpParserException is reported without a stack trace, and so when it's
338 // wrapped twice it registers as a different exception each time (because
339 // it's given an ad-hoc stack trace). Always expect two exceptions when
340 // issue 9151 is fixed.
341 expect(errors.length, inInclusiveRange(2, 3));
301 expect(errors[0].error, equals('oh no')); 342 expect(errors[0].error, equals('oh no'));
302 expect(errors[1].error, new isInstanceOf<HttpParserException>()); 343 expect(errors[1].error, new isInstanceOf<HttpParserException>());
344 if (errors.length > 2) {
345 expect(errors[2].error, new isInstanceOf<HttpParserException>());
346 }
303 }); 347 });
304 }, passing: ['test 2']); 348 }, passing: ['test 2']);
305 } 349 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/lib/src/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698