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

Side by Side Diff: pkg/shelf/test/shelf_io_test.dart

Issue 252393007: Make sure handler errors won't bring down a shelf server. (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
« pkg/shelf/lib/shelf_io.dart ('K') | « pkg/shelf/pubspec.yaml ('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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 shelf_io_test; 5 library shelf_io_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 expect(body, 'test body'); 177 expect(body, 'test body');
178 return syncHandler(request); 178 return syncHandler(request);
179 }); 179 });
180 }); 180 });
181 181
182 return _schedulePost(body: 'test body').then((response) { 182 return _schedulePost(body: 'test body').then((response) {
183 expect(response.statusCode, HttpStatus.OK); 183 expect(response.statusCode, HttpStatus.OK);
184 expect(response.stream.bytesToString(), completion('Hello from /')); 184 expect(response.stream.bytesToString(), completion('Hello from /'));
185 }); 185 });
186 }); 186 });
187
188 test('passes asynchronous exceptions to the parent error zone', () {
189 return runZoned(() {
190 return shelf_io.serve((request) {
191 new Future(() => throw 'oh no');
192 return syncHandler(request);
193 }, 'localhost', 0).then((server) {
194 return http.get('http://localhost:${server.port}').then((response) {
195 expect(response.statusCode, HttpStatus.OK);
196 expect(response.body, 'Hello from /');
197 server.close();
198 });
199 });
200 }, onError: expectAsync((error) {
201 expect(error, equals('oh no'));
202 }));
203 });
204
205 test("doesn't pass asynchronous exceptions to the root error zone", () {
206 return Zone.ROOT.run(() {
207 return shelf_io.serve((request) {
208 new Future(() => throw 'oh no');
209 return syncHandler(request);
210 }, 'localhost', 0).then((server) {
211 return http.get('http://localhost:${server.port}').then((response) {
212 expect(response.statusCode, HttpStatus.OK);
213 expect(response.body, 'Hello from /');
214 server.close();
215 });
216 });
217 });
218 });
187 } 219 }
188 220
189 int _serverPort; 221 int _serverPort;
190 222
191 Future _scheduleServer(Handler handler) { 223 Future _scheduleServer(Handler handler) {
192 return schedule(() => shelf_io.serve(handler, 'localhost', 0).then((server) { 224 return schedule(() => shelf_io.serve(handler, 'localhost', 0).then((server) {
193 currentSchedule.onComplete.schedule(() { 225 currentSchedule.onComplete.schedule(() {
194 _serverPort = null; 226 _serverPort = null;
195 return server.close(force: true); 227 return server.close(force: true);
196 }); 228 });
(...skipping 16 matching lines...) Expand all
213 245
214 var request = new http.Request('POST', 246 var request = new http.Request('POST',
215 Uri.parse('http://localhost:$_serverPort/')); 247 Uri.parse('http://localhost:$_serverPort/'));
216 248
217 if (headers != null) request.headers.addAll(headers); 249 if (headers != null) request.headers.addAll(headers);
218 if (body != null) request.body = body; 250 if (body != null) request.body = body;
219 251
220 return request.send(); 252 return request.send();
221 }); 253 });
222 } 254 }
OLDNEW
« pkg/shelf/lib/shelf_io.dart ('K') | « pkg/shelf/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698