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

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

Issue 12512005: Display which nested tasks are running when an error occurs in a scheduled test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
« no previous file with comments | « pkg/scheduled_test/lib/src/schedule.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 task; 5 library task;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'future_group.dart'; 10 import 'future_group.dart';
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 // If the parent queue experiences an error before this task has started 84 // If the parent queue experiences an error before this task has started
85 // running, pipe that error out through [result]. This ensures that we don't 85 // running, pipe that error out through [result]. This ensures that we don't
86 // get deadlocked by something like `expect(schedule(...), completes)`. 86 // get deadlocked by something like `expect(schedule(...), completes)`.
87 queue.onTasksComplete.catchError((e) { 87 queue.onTasksComplete.catchError((e) {
88 if (state == TaskState.WAITING) _resultCompleter.completeError(e); 88 if (state == TaskState.WAITING) _resultCompleter.completeError(e);
89 }); 89 });
90 90
91 // catchError makes sure any error thrown by fn isn't top-leveled by virtue 91 // catchError makes sure any error thrown by fn isn't top-leveled by virtue
92 // of being passed to the result future. 92 // of being passed to the result future.
93 result.whenComplete(() { 93 result.then((_) {
94 _state = TaskState.DONE; 94 _state = TaskState.SUCCESS;
95 }).catchError((e) {
96 _state = TaskState.ERROR;
97 throw e;
95 }).catchError((_) {}); 98 }).catchError((_) {});
96 } 99 }
97 100
98 /// Run [fn] as a child of this task. Returns a Future that will complete with 101 /// Run [fn] as a child of this task. Returns a Future that will complete with
99 /// the result of the child task. This task will not complete until [fn] has 102 /// the result of the child task. This task will not complete until [fn] has
100 /// finished. 103 /// finished.
101 Future runChild(fn(), String description) { 104 Future runChild(fn(), String description) {
102 var task = new Task._child(fn, description, this); 105 var task = new Task._child(fn, description, this);
103 children.add(task); 106 children.add(task);
104 if (_childGroup == null || _childGroup.completed) { 107 if (_childGroup == null || _childGroup.completed) {
(...skipping 13 matching lines...) Expand all
118 } 121 }
119 122
120 /// An enum of states for a [Task]. 123 /// An enum of states for a [Task].
121 class TaskState { 124 class TaskState {
122 /// The task is waiting to be run. 125 /// The task is waiting to be run.
123 static const WAITING = const TaskState._("WAITING"); 126 static const WAITING = const TaskState._("WAITING");
124 127
125 /// The task is currently running. 128 /// The task is currently running.
126 static const RUNNING = const TaskState._("RUNNING"); 129 static const RUNNING = const TaskState._("RUNNING");
127 130
128 /// The task has finished running, either successfully or with an error. 131 /// The task has finished running successfully.
129 static const DONE = const TaskState._("DONE"); 132 static const SUCCESS = const TaskState._("SUCCESS");
133
134 /// The task has finished running with an error.
135 static const ERROR = const TaskState._("ERROR");
130 136
131 /// The name of the state. 137 /// The name of the state.
132 final String name; 138 final String name;
133 139
140 /// Whether the state indicates that the task has finished running. This is
141 /// true for both the [SUCCESS] and [ERROR] states.
142 bool get isDone => this == SUCCESS || this == ERROR;
143
134 const TaskState._(this.name); 144 const TaskState._(this.name);
135 145
136 String toString() => name; 146 String toString() => name;
137 } 147 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/lib/src/schedule.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698