| 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 // TODO(nweiz): Add timeouts to scheduled tests. | |
| 6 // TODO(nweiz): Add support for calling [schedule] while the schedule is already | 5 // TODO(nweiz): Add support for calling [schedule] while the schedule is already |
| 7 // running. | 6 // running. |
| 8 // TODO(nweiz): Port the non-Pub-specific scheduled test libraries from Pub. | 7 // TODO(nweiz): Port the non-Pub-specific scheduled test libraries from Pub. |
| 9 /// A package for writing readable tests of asynchronous behavior. | 8 /// A package for writing readable tests of asynchronous behavior. |
| 10 /// | 9 /// |
| 11 /// This package works by building up a queue of asynchronous tasks called a | 10 /// This package works by building up a queue of asynchronous tasks called a |
| 12 /// "schedule", then executing those tasks in order. This allows the tests to | 11 /// "schedule", then executing those tasks in order. This allows the tests to |
| 13 /// read like synchronous, linear code, despite executing asynchronously. | 12 /// read like synchronous, linear code, despite executing asynchronously. |
| 14 /// | 13 /// |
| 15 /// The `scheduled_test` package is built on top of `unittest`, and should be | 14 /// The `scheduled_test` package is built on top of `unittest`, and should be |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 /// void main() { | 131 /// void main() { |
| 133 /// test('sendRequest sends a request', () { | 132 /// test('sendRequest sends a request', () { |
| 134 /// startServer(wrapAsync((request) { | 133 /// startServer(wrapAsync((request) { |
| 135 /// expect(request.body, equals('payload')); | 134 /// expect(request.body, equals('payload')); |
| 136 /// request.response.close(); | 135 /// request.response.close(); |
| 137 /// })); | 136 /// })); |
| 138 /// | 137 /// |
| 139 /// schedule(() => sendRequest('payload')); | 138 /// schedule(() => sendRequest('payload')); |
| 140 /// }); | 139 /// }); |
| 141 /// } | 140 /// } |
| 141 /// |
| 142 /// ## Timeouts |
| 143 /// |
| 144 /// `scheduled_test` has a built-in timeout of 30 seconds (configurable via |
| 145 /// [Schedule.timeoutLength]). This timeout is aware of the structure of the |
| 146 /// schedule; this means that it will reset for each task in a queue, when |
| 147 /// moving between queues, or almost any other sort of interaction with |
| 148 /// [currentSchedule]. As long as the [Schedule] knows your test is making some |
| 149 /// sort of progress, it won't time out. |
| 150 /// |
| 151 /// If a single task might take a long time, you can also manually tell the |
| 152 /// [Schedule] that it's making progress by calling [Schedule.ping], which will |
| 153 /// reset the timeout whenever it's called. |
| 142 library scheduled_test; | 154 library scheduled_test; |
| 143 | 155 |
| 144 import 'dart:async'; | 156 import 'dart:async'; |
| 145 | 157 |
| 146 import 'package:unittest/unittest.dart' as unittest; | 158 import 'package:unittest/unittest.dart' as unittest; |
| 147 | 159 |
| 148 import 'src/schedule.dart'; | 160 import 'src/schedule.dart'; |
| 149 import 'src/schedule_error.dart'; | 161 import 'src/schedule_error.dart'; |
| 150 import 'src/utils.dart'; | 162 import 'src/utils.dart'; |
| 151 | 163 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 unittest.ensureInitialized(); | 295 unittest.ensureInitialized(); |
| 284 unittest.wrapAsync = (f) { | 296 unittest.wrapAsync = (f) { |
| 285 if (currentSchedule == null) { | 297 if (currentSchedule == null) { |
| 286 throw new StateError("Unexpected call to wrapAsync with no current " | 298 throw new StateError("Unexpected call to wrapAsync with no current " |
| 287 "schedule."); | 299 "schedule."); |
| 288 } | 300 } |
| 289 | 301 |
| 290 return currentSchedule.wrapAsync(f); | 302 return currentSchedule.wrapAsync(f); |
| 291 }; | 303 }; |
| 292 } | 304 } |
| OLD | NEW |