| 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 19 matching lines...) Expand all Loading... |
| 30 errors = currentSchedule.errors; | 30 errors = currentSchedule.errors; |
| 31 }); | 31 }); |
| 32 | 32 |
| 33 var server = new ScheduledServer(); | 33 var server = new ScheduledServer(); |
| 34 expect(server.url.then((url) => http.read(url.resolve('/hello'))), | 34 expect(server.url.then((url) => http.read(url.resolve('/hello'))), |
| 35 completion(equals('Hello, test!'))); | 35 completion(equals('Hello, test!'))); |
| 36 }); | 36 }); |
| 37 | 37 |
| 38 test('test 2', () { | 38 test('test 2', () { |
| 39 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 39 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 40 // TODO(nweiz): There can be three errors due to issue 9151. The | 40 expect(errors.length, 2); |
| 41 // HttpException is reported without a stack trace, and so when it's | 41 expect(errors[0].error, new isInstanceOf<ScheduledServerError>()); |
| 42 // wrapped twice it registers as a different exception each time (because | 42 expect(errors[0].error.message, equals("'scheduled server 0' received " |
| 43 // it's given an ad-hoc stack trace). Always expect two exceptions when | 43 "GET /hello when no more requests were expected.")); |
| 44 // issue 9151 is fixed. | |
| 45 expect(errors.length, inInclusiveRange(2, 3)); | |
| 46 expect(errors[0].error, equals("'scheduled server 0' received GET /hello " | |
| 47 "when no more requests were expected.")); | |
| 48 expect(errors[1].error, new isInstanceOf<HttpException>()); | 44 expect(errors[1].error, new isInstanceOf<HttpException>()); |
| 49 if (errors.length > 2) { | |
| 50 expect(errors[2].error, new isInstanceOf<HttpException>()); | |
| 51 } | |
| 52 }); | 45 }); |
| 53 }, passing: ['test 2']); | 46 }, passing: ['test 2']); |
| 54 | 47 |
| 55 expectTestsPass("a handler runs when it's hit", () { | 48 expectTestsPass("a handler runs when it's hit", () { |
| 56 test('test', () { | 49 test('test', () { |
| 57 var server = new ScheduledServer(); | 50 var server = new ScheduledServer(); |
| 58 expect(server.url.then((url) => http.read(url.resolve('/hello'))), | 51 expect(server.url.then((url) => http.read(url.resolve('/hello'))), |
| 59 completion(equals('Hello, test!'))); | 52 completion(equals('Hello, test!'))); |
| 60 | 53 |
| 61 server.handle('GET', '/hello', (request) { | 54 server.handle('GET', '/hello', (request) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 }); | 101 }); |
| 109 }); | 102 }); |
| 110 | 103 |
| 111 test('test 2', () { | 104 test('test 2', () { |
| 112 // TODO(nweiz): There can be three errors due to issue 9151. The | 105 // TODO(nweiz): There can be three errors due to issue 9151. The |
| 113 // HttpException is reported without a stack trace, and so when it's | 106 // HttpException is reported without a stack trace, and so when it's |
| 114 // wrapped twice it registers as a different exception each time (because | 107 // wrapped twice it registers as a different exception each time (because |
| 115 // it's given an ad-hoc stack trace). Always expect two exceptions when | 108 // it's given an ad-hoc stack trace). Always expect two exceptions when |
| 116 // issue 9151 is fixed. | 109 // issue 9151 is fixed. |
| 117 expect(errors.length, inInclusiveRange(2, 3)); | 110 expect(errors.length, inInclusiveRange(2, 3)); |
| 118 expect(errors[0].error, equals("'scheduled server 0' received GET /hello " | 111 expect(errors[0].error, new isInstanceOf<ScheduledServerError>()); |
| 119 "earlier than expected.")); | 112 expect(errors[0].error.message, equals( |
| 113 "'scheduled server 0' received GET /hello earlier than expected.")); |
| 120 expect(errors[1].error, new isInstanceOf<HttpException>()); | 114 expect(errors[1].error, new isInstanceOf<HttpException>()); |
| 121 if (errors.length > 2) { | 115 if (errors.length > 2) { |
| 122 expect(errors[2].error, new isInstanceOf<HttpException>()); | 116 expect(errors[2].error, new isInstanceOf<HttpException>()); |
| 123 } | 117 } |
| 124 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 118 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 125 }); | 119 }); |
| 126 }, passing: ['test 2']); | 120 }, passing: ['test 2']); |
| 127 | 121 |
| 128 expectTestsPass("a handler waits for the immediately prior task to complete " | 122 expectTestsPass("a handler waits for the immediately prior task to complete " |
| 129 "before checking if it's too early", () { | 123 "before checking if it's too early", () { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 158 expect(server.url.then((url) => http.read(url.resolve('/hello'))), | 152 expect(server.url.then((url) => http.read(url.resolve('/hello'))), |
| 159 completion(equals('Hello, test!'))); | 153 completion(equals('Hello, test!'))); |
| 160 | 154 |
| 161 server.handle('GET', '/goodbye', (request) { | 155 server.handle('GET', '/goodbye', (request) { |
| 162 request.response.write('Goodbye, test!'); | 156 request.response.write('Goodbye, test!'); |
| 163 request.response.close(); | 157 request.response.close(); |
| 164 }); | 158 }); |
| 165 }); | 159 }); |
| 166 | 160 |
| 167 test('test 2', () { | 161 test('test 2', () { |
| 168 // TODO(nweiz): There can be three errors due to issue 9151. The | 162 expect(errors.length, 2); |
| 169 // HttpException is reported without a stack trace, and so when it's | 163 expect(errors[0].error, new isInstanceOf<ScheduledServerError>()); |
| 170 // wrapped twice it registers as a different exception each time (because | 164 expect(errors[0].error.message, equals( |
| 171 // it's given an ad-hoc stack trace). Always expect two exceptions when | 165 "'scheduled server 0' expected GET /goodbye, but got GET /hello.")); |
| 172 // issue 9151 is fixed. | |
| 173 expect(errors.length, inInclusiveRange(2, 3)); | |
| 174 expect(errors[0].error, equals("'scheduled server 0' expected GET " | |
| 175 "/goodbye, but got GET /hello.")); | |
| 176 expect(errors[1].error, new isInstanceOf<HttpException>()); | 166 expect(errors[1].error, new isInstanceOf<HttpException>()); |
| 177 if (errors.length > 2) { | |
| 178 expect(errors[2].error, new isInstanceOf<HttpException>()); | |
| 179 } | |
| 180 }); | 167 }); |
| 181 }, passing: ['test 2']); | 168 }, passing: ['test 2']); |
| 182 | 169 |
| 183 expectTestsPass("a handler fails if the method is wrong", () { | 170 expectTestsPass("a handler fails if the method is wrong", () { |
| 184 var errors; | 171 var errors; |
| 185 test('test 1', () { | 172 test('test 1', () { |
| 186 currentSchedule.onException.schedule(() { | 173 currentSchedule.onException.schedule(() { |
| 187 errors = currentSchedule.errors; | 174 errors = currentSchedule.errors; |
| 188 }); | 175 }); |
| 189 | 176 |
| 190 var server = new ScheduledServer(); | 177 var server = new ScheduledServer(); |
| 191 expect(server.url.then((url) => http.head(url.resolve('/hello'))), | 178 expect(server.url.then((url) => http.head(url.resolve('/hello'))), |
| 192 completes); | 179 completes); |
| 193 | 180 |
| 194 server.handle('GET', '/hello', (request) { | 181 server.handle('GET', '/hello', (request) { |
| 195 request.response.write('Hello, test!'); | 182 request.response.write('Hello, test!'); |
| 196 request.response.close(); | 183 request.response.close(); |
| 197 }); | 184 }); |
| 198 }); | 185 }); |
| 199 | 186 |
| 200 test('test 2', () { | 187 test('test 2', () { |
| 201 // TODO(nweiz): There can be three errors due to issue 9151. The | 188 expect(errors.length, 2); |
| 202 // HttpException is reported without a stack trace, and so when it's | 189 expect(errors[0].error, new isInstanceOf<ScheduledServerError>()); |
| 203 // wrapped twice it registers as a different exception each time (because | 190 expect(errors[0].error.message, equals( |
| 204 // it's given an ad-hoc stack trace). Always expect two exceptions when | 191 "'scheduled server 0' expected GET /hello, but got HEAD /hello.")); |
| 205 // issue 9151 is fixed. | |
| 206 expect(errors.length, inInclusiveRange(2, 3)); | |
| 207 expect(errors[0].error, equals("'scheduled server 0' expected GET " | |
| 208 "/hello, but got HEAD /hello.")); | |
| 209 expect(errors[1].error, new isInstanceOf<HttpException>()); | 192 expect(errors[1].error, new isInstanceOf<HttpException>()); |
| 210 if (errors.length > 2) { | |
| 211 expect(errors[2].error, new isInstanceOf<HttpException>()); | |
| 212 } | |
| 213 }); | 193 }); |
| 214 }, passing: ['test 2']); | 194 }, passing: ['test 2']); |
| 215 | 195 |
| 216 expectTestsPass("a handler times out waiting to be hit", () { | 196 expectTestsPass("a handler times out waiting to be hit", () { |
| 217 var clock = mock_clock.mock()..run(); | 197 var clock = mock_clock.mock()..run(); |
| 218 var timeOfException; | 198 var timeOfException; |
| 219 var errors; | 199 var errors; |
| 220 test('test 1', () { | 200 test('test 1', () { |
| 221 currentSchedule.timeout = new Duration(milliseconds: 2); | 201 currentSchedule.timeout = new Duration(milliseconds: 2); |
| 222 currentSchedule.onException.schedule(() { | 202 currentSchedule.onException.schedule(() { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 request.response.close(); | 276 request.response.close(); |
| 297 }); | 277 }); |
| 298 | 278 |
| 299 server.handle('GET', '/hello/2', (request) { | 279 server.handle('GET', '/hello/2', (request) { |
| 300 request.response.write('Hello, request 2!'); | 280 request.response.write('Hello, request 2!'); |
| 301 request.response.close(); | 281 request.response.close(); |
| 302 }); | 282 }); |
| 303 }); | 283 }); |
| 304 | 284 |
| 305 test('test 2', () { | 285 test('test 2', () { |
| 306 // TODO(nweiz): There can be three errors due to issue 9151. The | 286 expect(errors.length, 2); |
| 307 // HttpException is reported without a stack trace, and so when it's | 287 expect(errors[0].error, new isInstanceOf<ScheduledServerError>()); |
| 308 // wrapped twice it registers as a different exception each time (because | 288 expect(errors[0].error.message, equals("'scheduled server 0' received " |
| 309 // it's given an ad-hoc stack trace). Always expect two exceptions when | 289 "GET /hello/3 when no more requests were expected.")); |
| 310 // issue 9151 is fixed. | |
| 311 expect(errors.length, inInclusiveRange(2, 3)); | |
| 312 expect(errors[0].error, equals("'scheduled server 0' received GET " | |
| 313 "/hello/3 when no more requests were expected.")); | |
| 314 expect(errors[1].error, new isInstanceOf<HttpException>()); | 290 expect(errors[1].error, new isInstanceOf<HttpException>()); |
| 315 if (errors.length > 2) { | |
| 316 expect(errors[2].error, new isInstanceOf<HttpException>()); | |
| 317 } | |
| 318 }); | 291 }); |
| 319 }, passing: ['test 2']); | 292 }, passing: ['test 2']); |
| 320 | 293 |
| 321 expectTestsPass("an error in a handler doesn't cause a timeout", () { | 294 expectTestsPass("an error in a handler doesn't cause a timeout", () { |
| 322 var errors; | 295 var errors; |
| 323 test('test 1', () { | 296 test('test 1', () { |
| 324 currentSchedule.onException.schedule(() { | 297 currentSchedule.onException.schedule(() { |
| 325 errors = currentSchedule.errors; | 298 errors = currentSchedule.errors; |
| 326 }); | 299 }); |
| 327 | 300 |
| 328 var server = new ScheduledServer(); | 301 var server = new ScheduledServer(); |
| 329 expect(server.url.then((url) => http.read(url.resolve('/hello'))), | 302 expect(server.url.then((url) => http.read(url.resolve('/hello'))), |
| 330 completion(equals('Hello, test!'))); | 303 completion(equals('Hello, test!'))); |
| 331 | 304 |
| 332 server.handle('GET', '/hello', (request) { | 305 server.handle('GET', '/hello', (request) { |
| 333 throw 'oh no'; | 306 throw new TestFailure('oh no'); |
| 334 }); | 307 }); |
| 335 }); | 308 }); |
| 336 | 309 |
| 337 test('test 2', () { | 310 test('test 2', () { |
| 338 // TODO(nweiz): There can be three errors due to issue 9151. The | 311 expect(errors.length, 2); |
| 339 // HttpException is reported without a stack trace, and so when it's | 312 expect(errors[0].error, new isInstanceOf<TestFailure>()); |
| 340 // wrapped twice it registers as a different exception each time (because | 313 expect(errors[0].error.message, equals('oh no')); |
| 341 // it's given an ad-hoc stack trace). Always expect two exceptions when | |
| 342 // issue 9151 is fixed. | |
| 343 expect(errors.length, inInclusiveRange(2, 3)); | |
| 344 expect(errors[0].error, equals('oh no')); | |
| 345 expect(errors[1].error, new isInstanceOf<HttpException>()); | 314 expect(errors[1].error, new isInstanceOf<HttpException>()); |
| 346 if (errors.length > 2) { | |
| 347 expect(errors[2].error, new isInstanceOf<HttpException>()); | |
| 348 } | |
| 349 }); | 315 }); |
| 350 }, passing: ['test 2']); | 316 }, passing: ['test 2']); |
| 351 } | 317 } |
| OLD | NEW |