| 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 schedule; | 5 library schedule; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
| 11 import 'package:unittest/unittest.dart' as unittest; | 11 import 'package:unittest/unittest.dart' as unittest; |
| 12 | 12 |
| 13 import 'mock_clock.dart' as mock_clock; | 13 import 'mock_clock.dart' as mock_clock; |
| 14 import 'schedule_error.dart'; | 14 import 'schedule_error.dart'; |
| 15 import '../scheduled_test.dart' show captureStackTraces; |
| 15 import 'substitute_future.dart'; | 16 import 'substitute_future.dart'; |
| 16 import 'task.dart'; | 17 import 'task.dart'; |
| 17 import 'utils.dart'; | 18 import 'utils.dart'; |
| 18 import 'value_future.dart'; | 19 import 'value_future.dart'; |
| 19 | 20 |
| 20 /// The schedule of tasks to run for a single test. This has three separate task | 21 /// The schedule of tasks to run for a single test. This has three separate task |
| 21 /// queues: [tasks], [onComplete], and [onException]. It also provides | 22 /// queues: [tasks], [onComplete], and [onException]. It also provides |
| 22 /// visibility into the current state of the schedule. | 23 /// visibility into the current state of the schedule. |
| 23 class Schedule { | 24 class Schedule { |
| 24 /// The main task queue for the schedule. These tasks are run before the other | 25 /// The main task queue for the schedule. These tasks are run before the other |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 currentQueue._signalTimeout(new ScheduleError.from(this, "The schedule " | 303 currentQueue._signalTimeout(new ScheduleError.from(this, "The schedule " |
| 303 "timed out after $_timeout of inactivity.")); | 304 "timed out after $_timeout of inactivity.")); |
| 304 }); | 305 }); |
| 305 } | 306 } |
| 306 } | 307 } |
| 307 | 308 |
| 308 /// Register an error in the schedule's error list. This ensures that there | 309 /// Register an error in the schedule's error list. This ensures that there |
| 309 /// are no duplicate errors, and that all errors are wrapped in | 310 /// are no duplicate errors, and that all errors are wrapped in |
| 310 /// [ScheduleError]. | 311 /// [ScheduleError]. |
| 311 void _addError(error) { | 312 void _addError(error) { |
| 312 if (errors.contains(error)) return; | 313 if (error is ScheduleError && errors.contains(error)) return; |
| 313 errors.add(new ScheduleError.from(this, error)); | 314 errors.add(new ScheduleError.from(this, error)); |
| 314 } | 315 } |
| 315 } | 316 } |
| 316 | 317 |
| 317 /// An enum of states for a [Schedule]. | 318 /// An enum of states for a [Schedule]. |
| 318 class ScheduleState { | 319 class ScheduleState { |
| 319 /// The schedule can have tasks added to its queue, but is not yet running | 320 /// The schedule can have tasks added to its queue, but is not yet running |
| 320 /// them. | 321 /// them. |
| 321 static const SET_UP = const ScheduleState._("SET_UP"); | 322 static const SET_UP = const ScheduleState._("SET_UP"); |
| 322 | 323 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 Function _wrapAsync(fn(arg), String description) { | 490 Function _wrapAsync(fn(arg), String description) { |
| 490 assert(_schedule.state == ScheduleState.SET_UP || isRunning); | 491 assert(_schedule.state == ScheduleState.SET_UP || isRunning); |
| 491 | 492 |
| 492 // It's possible that the queue timed out before [fn] finished. | 493 // It's possible that the queue timed out before [fn] finished. |
| 493 bool _timedOut() => | 494 bool _timedOut() => |
| 494 _schedule.currentQueue != this || pendingCallbacks.isEmpty; | 495 _schedule.currentQueue != this || pendingCallbacks.isEmpty; |
| 495 | 496 |
| 496 if (description == null) { | 497 if (description == null) { |
| 497 description = "Out-of-band operation #${_totalCallbacks}"; | 498 description = "Out-of-band operation #${_totalCallbacks}"; |
| 498 } | 499 } |
| 499 var stackString = prefixLines(terseTraceString(new Trace.current())); | 500 |
| 500 description = "$description\n\nStack trace:\n$stackString"; | 501 if (captureStackTraces) { |
| 502 var stackString = prefixLines(terseTraceString(new Trace.current())); |
| 503 description += "\n\nStack trace:\n$stackString"; |
| 504 } |
| 505 |
| 501 _totalCallbacks++; | 506 _totalCallbacks++; |
| 502 | 507 |
| 503 _pendingCallbacks.add(description); | 508 _pendingCallbacks.add(description); |
| 504 return (arg) { | 509 return (arg) { |
| 505 try { | 510 try { |
| 506 return fn(arg); | 511 return fn(arg); |
| 507 } catch (e, stackTrace) { | 512 } catch (e, stackTrace) { |
| 508 var error = new ScheduleError.from( | 513 var error = new ScheduleError.from( |
| 509 _schedule, e, stackTrace: stackTrace); | 514 _schedule, e, stackTrace: stackTrace); |
| 510 if (_timedOut()) { | 515 if (_timedOut()) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 return prefixLines(childString, | 587 return prefixLines(childString, |
| 583 firstPrefix: " $prefix ", prefix: " | "); | 588 firstPrefix: " $prefix ", prefix: " | "); |
| 584 }).join('\n'); | 589 }).join('\n'); |
| 585 taskString = '$taskString\n$childrenString'; | 590 taskString = '$taskString\n$childrenString'; |
| 586 } | 591 } |
| 587 | 592 |
| 588 return taskString; | 593 return taskString; |
| 589 }).join("\n"); | 594 }).join("\n"); |
| 590 } | 595 } |
| 591 } | 596 } |
| OLD | NEW |