| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 var server = new ScheduledServer(); | 184 var server = new ScheduledServer(); |
| 185 expect(server.url.then((url) => http.read(url.resolve('/hello'))), | 185 expect(server.url.then((url) => http.read(url.resolve('/hello'))), |
| 186 completion(equals('Hello, test!'))); | 186 completion(equals('Hello, test!'))); |
| 187 | 187 |
| 188 server.handle('GET', '/hello', (request) => fail('oh no')); | 188 server.handle('GET', '/hello', (request) => fail('oh no')); |
| 189 }, 'oh no'); | 189 }, 'oh no'); |
| 190 } | 190 } |
| 191 | 191 |
| 192 /// Creates a metatest that runs [testBody], captures its schedule errors, and | 192 /// Creates a metatest that runs [testBody], captures its schedule errors, and |
| 193 /// asserts that it throws an error with the given [errorMessage]. | 193 /// asserts that it throws an error with the given [errorMessage]. |
| 194 void expectServerError(String description, void testBody(), | 194 void expectServerError(String description, testBody(), |
| 195 String errorMessage) { | 195 String errorMessage) { |
| 196 expectTestFails(description, testBody, (errors) { | 196 expectTestFails(description, testBody, (errors) { |
| 197 // There can be between one and three errors here. The first is the | 197 // There can be between one and three errors here. The first is the |
| 198 // expected server error. The second is an HttpException that may occur if | 198 // expected server error. The second is an HttpException that may occur if |
| 199 // the server is closed fast enough after the error. The third is due to | 199 // the server is closed fast enough after the error. The third is due to |
| 200 // issue 9151: the HttpException is reported without a stack trace, and so | 200 // issue 9151: the HttpException is reported without a stack trace, and so |
| 201 // when it's wrapped twice it registers as a different exception each time | 201 // when it's wrapped twice it registers as a different exception each time |
| 202 // (because it's given an ad-hoc stack trace). | 202 // (because it's given an ad-hoc stack trace). |
| 203 expect(errors.length, inInclusiveRange(1, 3)); | 203 expect(errors.length, inInclusiveRange(1, 3)); |
| 204 expect(errors[0].error.toString(), equals(errorMessage)); | 204 expect(errors[0].error.toString(), equals(errorMessage)); |
| 205 | 205 |
| 206 for (var i = 1; i < errors.length; i++) { | 206 for (var i = 1; i < errors.length; i++) { |
| 207 expect(errors[i].error, new isInstanceOf<HttpException>()); | 207 expect(errors[i].error, new isInstanceOf<HttpException>()); |
| 208 } | 208 } |
| 209 }); | 209 }); |
| 210 } | 210 } |
| OLD | NEW |