OLD | NEW |
---|---|
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 'package:http/http.dart' as http; | 10 import 'package:http/http.dart' as http; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 request.response.close(); | 163 request.response.close(); |
164 }); | 164 }); |
165 }); | 165 }); |
166 | 166 |
167 test('test 2', () { | 167 test('test 2', () { |
168 // TODO(nweiz): There can be three errors due to issue 9151. The | 168 // TODO(nweiz): There can be three errors due to issue 9151. The |
169 // HttpException is reported without a stack trace, and so when it's | 169 // HttpException is reported without a stack trace, and so when it's |
170 // wrapped twice it registers as a different exception each time (because | 170 // wrapped twice it registers as a different exception each time (because |
171 // it's given an ad-hoc stack trace). Always expect two exceptions when | 171 // it's given an ad-hoc stack trace). Always expect two exceptions when |
172 // issue 9151 is fixed. | 172 // issue 9151 is fixed. |
173 // Issue 9151 has been fixed, but there are still three errors reported. | |
174 // The second is now a copy of the first, rather than a copy of the third. | |
nweiz
2013/09/18 22:46:02
This comment shouldn't look like a conversation; i
| |
173 expect(errors.length, inInclusiveRange(2, 3)); | 175 expect(errors.length, inInclusiveRange(2, 3)); |
174 expect(errors[0].error, equals("'scheduled server 0' expected GET " | 176 expect(errors[0].error, equals("'scheduled server 0' expected GET " |
175 "/goodbye, but got GET /hello.")); | 177 "/goodbye, but got GET /hello.")); |
176 expect(errors[1].error, new isInstanceOf<HttpException>()); | 178 expect(errors[1].error, anyOf(new isInstanceOf<HttpException>(), |
179 equals("'scheduled server 0' expected GET " | |
180 "/goodbye, but got GET /hello."))); | |
177 if (errors.length > 2) { | 181 if (errors.length > 2) { |
178 expect(errors[2].error, new isInstanceOf<HttpException>()); | 182 expect(errors[2].error, new isInstanceOf<HttpException>()); |
179 } | 183 } |
180 }); | 184 }); |
181 }, passing: ['test 2']); | 185 }, passing: ['test 2']); |
182 | 186 |
183 expectTestsPass("a handler fails if the method is wrong", () { | 187 expectTestsPass("a handler fails if the method is wrong", () { |
184 var errors; | 188 var errors; |
185 test('test 1', () { | 189 test('test 1', () { |
186 currentSchedule.onException.schedule(() { | 190 currentSchedule.onException.schedule(() { |
187 errors = currentSchedule.errors; | 191 errors = currentSchedule.errors; |
188 }); | 192 }); |
189 | 193 |
190 var server = new ScheduledServer(); | 194 var server = new ScheduledServer(); |
191 expect(server.url.then((url) => http.head(url.resolve('/hello'))), | 195 expect(server.url.then((url) => http.head(url.resolve('/hello'))), |
192 completes); | 196 completes); |
193 | 197 |
194 server.handle('GET', '/hello', (request) { | 198 server.handle('GET', '/hello', (request) { |
195 request.response.write('Hello, test!'); | 199 request.response.write('Hello, test!'); |
196 request.response.close(); | 200 request.response.close(); |
197 }); | 201 }); |
198 }); | 202 }); |
199 | 203 |
200 test('test 2', () { | 204 test('test 2', () { |
201 // TODO(nweiz): There can be three errors due to issue 9151. The | 205 // TODO(nweiz): There can be three errors due to issue 9151. The |
202 // HttpException is reported without a stack trace, and so when it's | 206 // HttpException is reported without a stack trace, and so when it's |
203 // wrapped twice it registers as a different exception each time (because | 207 // wrapped twice it registers as a different exception each time (because |
204 // it's given an ad-hoc stack trace). Always expect two exceptions when | 208 // it's given an ad-hoc stack trace). Always expect two exceptions when |
205 // issue 9151 is fixed. | 209 // issue 9151 is fixed. |
210 // Issue 9151 has been fixed, but there are still three errors reported. | |
211 // The second is now a copy of the first, rather than a copy of the third. | |
206 expect(errors.length, inInclusiveRange(2, 3)); | 212 expect(errors.length, inInclusiveRange(2, 3)); |
207 expect(errors[0].error, equals("'scheduled server 0' expected GET " | 213 expect(errors[0].error, equals("'scheduled server 0' expected GET " |
208 "/hello, but got HEAD /hello.")); | 214 "/hello, but got HEAD /hello.")); |
209 expect(errors[1].error, new isInstanceOf<HttpException>()); | 215 expect(errors[1].error, anyOf(new isInstanceOf<HttpException>(), |
216 equals("'scheduled server 0' expected GET " | |
217 "/goodbye, but got GET /hello."))); | |
210 if (errors.length > 2) { | 218 if (errors.length > 2) { |
211 expect(errors[2].error, new isInstanceOf<HttpException>()); | 219 expect(errors[2].error, new isInstanceOf<HttpException>()); |
212 } | 220 } |
213 }); | 221 }); |
214 }, passing: ['test 2']); | 222 }, passing: ['test 2']); |
215 | 223 |
216 expectTestsPass("a handler times out waiting to be hit", () { | 224 expectTestsPass("a handler times out waiting to be hit", () { |
217 var clock = mock_clock.mock()..run(); | 225 var clock = mock_clock.mock()..run(); |
218 var timeOfException; | 226 var timeOfException; |
219 var errors; | 227 var errors; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 throw 'oh no'; | 341 throw 'oh no'; |
334 }); | 342 }); |
335 }); | 343 }); |
336 | 344 |
337 test('test 2', () { | 345 test('test 2', () { |
338 // TODO(nweiz): There can be three errors due to issue 9151. The | 346 // TODO(nweiz): There can be three errors due to issue 9151. The |
339 // HttpException is reported without a stack trace, and so when it's | 347 // HttpException is reported without a stack trace, and so when it's |
340 // wrapped twice it registers as a different exception each time (because | 348 // wrapped twice it registers as a different exception each time (because |
341 // it's given an ad-hoc stack trace). Always expect two exceptions when | 349 // it's given an ad-hoc stack trace). Always expect two exceptions when |
342 // issue 9151 is fixed. | 350 // issue 9151 is fixed. |
351 // Issue 9151 has been fixed, but there are still three errors reported. | |
352 // The second is now a copy of the first, rather than a copy of the third. | |
343 expect(errors.length, inInclusiveRange(2, 3)); | 353 expect(errors.length, inInclusiveRange(2, 3)); |
344 expect(errors[0].error, equals('oh no')); | 354 expect(errors[0].error, equals('oh no')); |
345 expect(errors[1].error, new isInstanceOf<HttpException>()); | 355 expect(errors[1].error, anyOf(new isInstanceOf<HttpException>(), |
356 equals("'scheduled server 0' expected GET " | |
357 "/goodbye, but got GET /hello."))); | |
346 if (errors.length > 2) { | 358 if (errors.length > 2) { |
347 expect(errors[2].error, new isInstanceOf<HttpException>()); | 359 expect(errors[2].error, new isInstanceOf<HttpException>()); |
348 } | 360 } |
349 }); | 361 }); |
350 }, passing: ['test 2']); | 362 }, passing: ['test 2']); |
351 } | 363 } |
OLD | NEW |