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

Side by Side Diff: runtime/observatory/tests/service/test_helper.dart

Issue 1074053002: Run service tests in a zone that gracefully handles websocket disconnections (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 | « no previous file | 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 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked
5 5
6 library test_helper; 6 library test_helper;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:io'; 10 import 'dart:io';
11 import 'package:observatory/service_io.dart'; 11 import 'package:observatory/service_io.dart';
12 12
13 bool _isWebSocketDisconnect(e) {
14 if (e is! ServiceException) {
15 return false;
16 }
17 return (e as ServiceException).message == 'WebSocket disconnected';
18 }
19
13 // This invocation should set up the state being tested. 20 // This invocation should set up the state being tested.
14 const String _TESTEE_MODE_FLAG = "--testee-mode"; 21 const String _TESTEE_MODE_FLAG = "--testee-mode";
15 22
16 class _TestLauncher { 23 class _TestLauncher {
17 Process process; 24 Process process;
18 final List<String> args; 25 final List<String> args;
19 26
20 _TestLauncher() : args = ['--enable-vm-service:0', 27 _TestLauncher() : args = ['--enable-vm-service:0',
21 Platform.script.toFilePath(), 28 Platform.script.toFilePath(),
22 _TESTEE_MODE_FLAG] {} 29 _TESTEE_MODE_FLAG] {}
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 102 }
96 // Wait around for the process to be killed. 103 // Wait around for the process to be killed.
97 stdin.first.then((_) => exit(0)); 104 stdin.first.then((_) => exit(0));
98 } else { 105 } else {
99 var process = new _TestLauncher(); 106 var process = new _TestLauncher();
100 process.launch(pause_on_exit).then((port) { 107 process.launch(pause_on_exit).then((port) {
101 String addr = 'ws://localhost:$port/ws'; 108 String addr = 'ws://localhost:$port/ws';
102 var testIndex = 0; 109 var testIndex = 0;
103 var totalTests = tests.length - 1; 110 var totalTests = tests.length - 1;
104 var name = Platform.script.pathSegments.last; 111 var name = Platform.script.pathSegments.last;
105 new WebSocketVM(new WebSocketVMTarget(addr)).load() 112 runZoned(() {
106 .then((VM vm) => vm.isolates.first.load()) 113 new WebSocketVM(new WebSocketVMTarget(addr)).load()
107 .then((Isolate isolate) => Future.forEach(tests, (test) { 114 .then((VM vm) => vm.isolates.first.load())
108 print('Running $name [$testIndex/$totalTests]'); 115 .then((Isolate isolate) => Future.forEach(tests, (test) {
109 testIndex++; 116 print('Running $name [$testIndex/$totalTests]');
110 return test(isolate); 117 testIndex++;
111 })).then((_) => process.requestExit()); 118 return test(isolate);
119 })).then((_) => process.requestExit());
120 }, onError: (e, st) {
121 if (!_isWebSocketDisconnect(e)) {
122 print('Unexpected exception in service tests: $e $st');
123 throw e;
124 }
125 });
112 }); 126 });
113 } 127 }
114 } 128 }
115 129
116 130
117 // Cancel the subscription and complete the completer when finished processing 131 // Cancel the subscription and complete the completer when finished processing
118 // events. 132 // events.
119 typedef void ServiceEventHandler(ServiceEvent event, 133 typedef void ServiceEventHandler(ServiceEvent event,
120 StreamSubscription subscription, 134 StreamSubscription subscription,
121 Completer completer); 135 Completer completer);
(...skipping 27 matching lines...) Expand all
149 } 163 }
150 // Wait around for the process to be killed. 164 // Wait around for the process to be killed.
151 stdin.first.then((_) => exit(0)); 165 stdin.first.then((_) => exit(0));
152 } else { 166 } else {
153 var process = new _TestLauncher(); 167 var process = new _TestLauncher();
154 process.launch(pause_on_exit).then((port) async { 168 process.launch(pause_on_exit).then((port) async {
155 String addr = 'ws://localhost:$port/ws'; 169 String addr = 'ws://localhost:$port/ws';
156 var testIndex = 0; 170 var testIndex = 0;
157 var totalTests = tests.length - 1; 171 var totalTests = tests.length - 1;
158 var name = Platform.script.pathSegments.last; 172 var name = Platform.script.pathSegments.last;
159 new WebSocketVM(new WebSocketVMTarget(addr)).load() 173 runZoned(() {
160 .then((VM vm) => Future.forEach(tests, (test) { 174 new WebSocketVM(new WebSocketVMTarget(addr)).load()
161 print('Running $name [$testIndex/$totalTests]'); 175 .then((VM vm) => Future.forEach(tests, (test) {
162 testIndex++; 176 print('Running $name [$testIndex/$totalTests]');
163 return test(vm); 177 testIndex++;
164 })).then((_) => process.requestExit()); 178 return test(vm);
179 })).then((_) => process.requestExit());
180 }, onError: (e, st) {
181 if (!_isWebSocketDisconnect(e)) {
182 print('Unexpected exception in service tests: $e $st');
183 throw e;
184 }
185 });
165 }); 186 });
166 } 187 }
167 } 188 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698