Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: pkg/scheduled_test/lib/src/schedule_error.dart

Issue 12218102: Add built-in timeouts to scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_error; 5 library schedule_error;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'schedule.dart'; 9 import 'schedule.dart';
10 import 'task.dart'; 10 import 'task.dart';
11 import 'utils.dart'; 11 import 'utils.dart';
12 12
13 /// A wrapper for errors that occur during a scheduled test. 13 /// A wrapper for errors that occur during a scheduled test.
14 class ScheduleError extends AsyncError { 14 class ScheduleError extends AsyncError {
15 /// The schedule during which this error occurred. 15 /// The schedule during which this error occurred.
16 final Schedule schedule; 16 final Schedule schedule;
17 17
18 /// The task that was running when this error occurred. This may be `null` if 18 /// The task that was running when this error occurred. This may be `null` if
19 /// there was no such task. 19 /// there was no such task.
20 final Task task; 20 final Task task;
21 21
22 /// Whether the schedule was finished executing at the time the error was 22 /// The state of the schedule at the time the error was detected.
23 /// detected. 23 final ScheduleState _stateWhenDetected;
24 final bool _scheduleWasDone;
25 24
26 /// Creates a new [ScheduleError] wrapping [error]. The metadata in 25 /// Creates a new [ScheduleError] wrapping [error]. The metadata in
27 /// [AsyncError]s and [ScheduleError]s will be preserved. 26 /// [AsyncError]s and [ScheduleError]s will be preserved.
28 factory ScheduleError.from(Schedule schedule, error, {stackTrace, 27 factory ScheduleError.from(Schedule schedule, error, {stackTrace,
29 AsyncError cause, Task task}) { 28 AsyncError cause, Task task}) {
30 if (error is ScheduleError) { 29 if (error is ScheduleError) {
31 if (schedule == null) schedule = error.schedule; 30 if (schedule == null) schedule = error.schedule;
32 if (task == null) task = error.task; 31 if (task == null) task = error.task;
33 } 32 }
34 33
35 if (error is AsyncError) { 34 if (error is AsyncError) {
36 // Overwrite the explicit stack trace, because it probably came from a 35 // Overwrite the explicit stack trace, because it probably came from a
37 // rethrow in the first place. 36 // rethrow in the first place.
38 stackTrace = error.stackTrace; 37 stackTrace = error.stackTrace;
39 if (cause == null) cause = error.cause; 38 if (cause == null) cause = error.cause;
40 error = error.error; 39 error = error.error;
41 } 40 }
42 41
43 return new ScheduleError(schedule, error, stackTrace, cause, task); 42 return new ScheduleError(schedule, error, stackTrace, cause, task);
44 } 43 }
45 44
46 ScheduleError(Schedule schedule, error, stackTrace, AsyncError cause, 45 ScheduleError(Schedule schedule, error, stackTrace, AsyncError cause,
47 this.task) 46 this.task)
48 : super.withCause(error, stackTrace, cause), 47 : super.withCause(error, stackTrace, cause),
49 this.schedule = schedule, 48 this.schedule = schedule,
50 this._scheduleWasDone = schedule.done; 49 this._stateWhenDetected = schedule.state;
51 50
52 String toString() { 51 String toString() {
53 var result = new StringBuffer(); 52 var result = new StringBuffer();
54 53
55 var errorString = error.toString(); 54 var errorString = error.toString();
56 if (errorString.contains("\n")) { 55 if (errorString.contains("\n")) {
57 result.add('ScheduleError:\n'); 56 result.add('ScheduleError:\n');
58 result.add(prefixLines(errorString.trim())); 57 result.add(prefixLines(errorString.trim()));
59 result.add("\n\n"); 58 result.add("\n\n");
60 } else { 59 } else {
61 result.add('ScheduleError: "$errorString"\n'); 60 result.add('ScheduleError: "$errorString"\n');
62 } 61 }
63 62
64 result.add('Stack trace:\n'); 63 result.add('Stack trace:\n');
65 result.add(prefixLines(stackTrace.toString().trim())); 64 result.add(prefixLines(stackTrace.toString().trim()));
66 result.add("\n\n"); 65 result.add("\n\n");
67 66
68 if (task != null) { 67 if (task != null) {
69 result.add('Error detected during task in queue "${task.queue}":\n'); 68 result.add('Error detected during task in queue "${task.queue}":\n');
70 result.add(task.generateTree()); 69 result.add(task.generateTree());
71 } else if (_scheduleWasDone) { 70 } else if (_stateWhenDetected == ScheduleState.DONE) {
72 result.add('Error detected after all tasks in the queue had finished.'); 71 result.add('Error detected after all tasks in the queue had finished.');
73 } else { 72 } else { // _stateWhenDetected == ScheduleState.SET_UP
74 result.add('Error detected before the schedule started running.'); 73 result.add('Error detected before the schedule started running.');
75 } 74 }
76 75
77 return result.toString(); 76 return result.toString();
78 } 77 }
79 } 78 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/lib/src/schedule.dart ('k') | pkg/scheduled_test/lib/src/substitute_future.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698