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

Unified Diff: pkg/scheduled_test/lib/src/schedule.dart

Issue 14706002: Always capture stack traces when running pub tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Lazily capture stack traces in scheduled_test. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/scheduled_test/lib/src/schedule_error.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/scheduled_test/lib/src/schedule.dart
diff --git a/pkg/scheduled_test/lib/src/schedule.dart b/pkg/scheduled_test/lib/src/schedule.dart
index d5eb9af41929f55e15741b14f3eecabd02325740..1dfb6106d93cba63650ce32e32d0f374b1f7a539 100644
--- a/pkg/scheduled_test/lib/src/schedule.dart
+++ b/pkg/scheduled_test/lib/src/schedule.dart
@@ -379,9 +379,9 @@ class TaskQueue {
/// The descriptions of all callbacks that are blocking the completion of
/// [this].
- List<String> get pendingCallbacks =>
- new UnmodifiableListView<String>(_pendingCallbacks);
- final _pendingCallbacks = new Queue<String>();
+ List<PendingCallback> get pendingCallbacks =>
+ new UnmodifiableListView<PendingCallback>(_pendingCallbacks);
+ final _pendingCallbacks = new Queue<PendingCallback>();
/// A completer that will be completed once [_pendingCallbacks] becomes empty
/// after the queue finishes running its tasks.
@@ -505,18 +505,21 @@ class TaskQueue {
bool _timedOut() =>
_schedule.currentQueue != this || pendingCallbacks.isEmpty;
- if (description == null) {
- description = "Out-of-band operation #${_totalCallbacks}";
- }
-
- if (captureStackTraces) {
- var stackString = prefixLines(terseTraceString(new Trace.current()));
- description += "\n\nStack trace:\n$stackString";
- }
-
_totalCallbacks++;
+ var trace = captureStackTraces ? new Trace.current() : null;
+ var pendingCallback = new PendingCallback._(() {
+ var fullDescription = description;
+ if (fullDescription == null) {
+ fullDescription = "Out-of-band operation #${_totalCallbacks}";
+ }
+
+ if (captureStackTraces) {
Bob Nystrom 2013/04/30 23:05:36 If capturing stack traces is fast enough now, how
nweiz 2013/04/30 23:13:14 Done.
+ var stackString = prefixLines(terseTraceString(trace));
+ fullDescription += "\n\nStack trace:\n$stackString";
+ }
+ });
+ _pendingCallbacks.add(pendingCallback);
- _pendingCallbacks.add(description);
return (arg) {
try {
return fn(arg);
@@ -531,7 +534,7 @@ class TaskQueue {
} finally {
if (_timedOut()) return;
- _pendingCallbacks.remove(description);
+ _pendingCallbacks.remove(pendingCallback);
if (_pendingCallbacks.isEmpty && !isRunningTasks) {
_noPendingCallbacksCompleter.complete();
}
@@ -605,3 +608,22 @@ class TaskQueue {
}).join("\n");
}
}
+
+/// A thunk for lazily resolving the description of a [PendingCallback].
+typedef String _DescriptionThunk();
Bob Nystrom 2013/04/30 23:05:36 Oh Dart and your awful function type syntax. You c
nweiz 2013/04/30 23:13:14 Currently we're using this once each in several di
+
+/// An identifier for an out-of-band callback running during a schedule.
+class PendingCallback {
Bob Nystrom 2013/04/30 23:05:36 The fact that it's for an out-of-band callback isn
nweiz 2013/04/30 23:13:14 I'm more interested in being able to add more pend
Bob Nystrom 2013/05/01 00:02:25 In that case, keep the name of this type, but upda
nweiz 2013/05/01 00:33:44 That's specifically referring to the string, not t
+ final _DescriptionThunk _thunk;
+ String _description;
+
+ /// The string description of the callback.
+ String get description {
+ if (_description == null) _description = _thunk();
+ return _description;
+ }
+
+ String toString() => description;
+
+ PendingCallback._(this._thunk);
+}
« no previous file with comments | « no previous file | pkg/scheduled_test/lib/src/schedule_error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698