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

Side by Side Diff: pkg/stack_trace/test/chain_test.dart

Issue 232783008: Avoid timeouts in stack_trace's chain_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/pkg.status ('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 chain_test; 5 library chain_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 import 'package:stack_trace/stack_trace.dart'; 10 import 'package:stack_trace/stack_trace.dart';
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 }); 85 });
86 86
87 test('multiple times', () { 87 test('multiple times', () {
88 var completer = new Completer(); 88 var completer = new Completer();
89 var first = true; 89 var first = true;
90 90
91 Chain.capture(() { 91 Chain.capture(() {
92 inMicrotask(() => throw 'first error'); 92 inMicrotask(() => throw 'first error');
93 inPeriodicTimer(() => throw 'second error'); 93 inPeriodicTimer(() => throw 'second error');
94 }, onError: (error, chain) { 94 }, onError: (error, chain) {
95 if (first) { 95 try {
96 expect(error, equals('first error')); 96 if (first) {
97 expect(chain.traces[1].frames, 97 expect(error, equals('first error'));
98 contains(frameMember(startsWith('inMicrotask')))); 98 expect(chain.traces[1].frames,
99 first = false; 99 contains(frameMember(startsWith('inMicrotask'))));
100 } else { 100 first = false;
101 expect(error, equals('second error')); 101 } else {
102 expect(chain.traces[1].frames, 102 expect(error, equals('second error'));
103 contains(frameMember(startsWith('inPeriodicTimer')))); 103 expect(chain.traces[1].frames,
104 completer.complete(); 104 contains(frameMember(startsWith('inPeriodicTimer'))));
105 completer.complete();
106 }
107 } catch (error, stackTrace) {
108 completer.completeError(error, stackTrace);
105 } 109 }
106 }); 110 });
107 111
108 return completer.future; 112 return completer.future;
109 }); 113 });
110 114
111 test('and relays them to the parent zone', () { 115 test('and relays them to the parent zone', () {
112 var completer = new Completer(); 116 var completer = new Completer();
113 117
114 runZoned(() { 118 runZoned(() {
115 Chain.capture(() { 119 Chain.capture(() {
116 inMicrotask(() => throw 'error'); 120 inMicrotask(() => throw 'error');
117 }, onError: (error, chain) { 121 }, onError: (error, chain) {
118 expect(error, equals('error')); 122 expect(error, equals('error'));
119 expect(chain.traces[1].frames, 123 expect(chain.traces[1].frames,
120 contains(frameMember(startsWith('inMicrotask')))); 124 contains(frameMember(startsWith('inMicrotask'))));
121 throw error; 125 throw error;
122 }); 126 });
123 }, onError: (error, chain) { 127 }, onError: (error, chain) {
124 expect(error, equals('error')); 128 try {
125 expect(chain, new isInstanceOf<Chain>()); 129 expect(error, equals('error'));
126 expect(chain.traces[1].frames, 130 expect(chain, new isInstanceOf<Chain>());
127 contains(frameMember(startsWith('inMicrotask')))); 131 expect(chain.traces[1].frames,
128 completer.complete(); 132 contains(frameMember(startsWith('inMicrotask'))));
133 completer.complete();
134 } catch (error, stackTrace) {
135 completer.completeError(error, stackTrace);
136 }
129 }); 137 });
130 138
131 return completer.future; 139 return completer.future;
132 }); 140 });
133 }); 141 });
134 142
135 test('capture() without onError passes exceptions to parent zone', () { 143 test('capture() without onError passes exceptions to parent zone', () {
136 var completer = new Completer(); 144 var completer = new Completer();
137 145
138 runZoned(() { 146 runZoned(() {
139 Chain.capture(() => inMicrotask(() => throw 'error')); 147 Chain.capture(() => inMicrotask(() => throw 'error'));
140 }, onError: (error, chain) { 148 }, onError: (error, chain) {
141 expect(error, equals('error')); 149 try {
142 expect(chain, new isInstanceOf<Chain>()); 150 expect(error, equals('error'));
143 expect(chain.traces[1].frames, 151 expect(chain, new isInstanceOf<Chain>());
144 contains(frameMember(startsWith('inMicrotask')))); 152 expect(chain.traces[1].frames,
145 completer.complete(); 153 contains(frameMember(startsWith('inMicrotask'))));
154 completer.complete();
155 } catch (error, stackTrace) {
156 completer.completeError(error, stackTrace);
157 }
146 }); 158 });
147 159
148 return completer.future; 160 return completer.future;
149 }); 161 });
150 162
151 group('current() within capture()', () { 163 group('current() within capture()', () {
152 test('called in a microtask', () { 164 test('called in a microtask', () {
153 var completer = new Completer(); 165 var completer = new Completer();
154 Chain.capture(() { 166 Chain.capture(() {
155 inMicrotask(() => completer.complete(new Chain.current())); 167 inMicrotask(() => completer.complete(new Chain.current()));
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 /// 722 ///
711 /// [callback] is expected to throw the string `"error"`. 723 /// [callback] is expected to throw the string `"error"`.
712 Future<Chain> captureFuture(callback()) { 724 Future<Chain> captureFuture(callback()) {
713 var completer = new Completer<Chain>(); 725 var completer = new Completer<Chain>();
714 Chain.capture(callback, onError: (error, chain) { 726 Chain.capture(callback, onError: (error, chain) {
715 expect(error, equals('error')); 727 expect(error, equals('error'));
716 completer.complete(chain); 728 completer.complete(chain);
717 }); 729 });
718 return completer.future; 730 return completer.future;
719 } 731 }
OLDNEW
« no previous file with comments | « pkg/pkg.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698