OLD | NEW |
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'; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 subscription.cancel(); | 230 subscription.cancel(); |
231 completer.complete(); | 231 completer.complete(); |
232 } | 232 } |
233 }); | 233 }); |
234 }); | 234 }); |
235 isolate.resume(); | 235 isolate.resume(); |
236 return completer.future; | 236 return completer.future; |
237 } | 237 } |
238 | 238 |
239 | 239 |
| 240 Future resumeAndAwaitEvent(Isolate isolate, stream, onEvent) async { |
| 241 Completer completer = new Completer(); |
| 242 var sub; |
| 243 sub = await isolate.vm.listenEventStream( |
| 244 stream, |
| 245 (ServiceEvent event) { |
| 246 var r = onEvent(event); |
| 247 if (r is! Future) { |
| 248 r = new Future.value(r); |
| 249 } |
| 250 r.then((x) => sub.cancel().then((_) { |
| 251 completer.complete(); |
| 252 })); |
| 253 }); |
| 254 await isolate.resume(); |
| 255 return completer.future; |
| 256 } |
| 257 |
| 258 IsolateTest resumeIsolateAndAwaitEvent(stream, onEvent) { |
| 259 return (Isolate isolate) async => |
| 260 resumeAndAwaitEvent(isolate, stream, onEvent); |
| 261 } |
| 262 |
| 263 |
240 Future<Class> getClassFromRootLib(Isolate isolate, String className) async { | 264 Future<Class> getClassFromRootLib(Isolate isolate, String className) async { |
241 Library rootLib = await isolate.rootLibrary.load(); | 265 Library rootLib = await isolate.rootLibrary.load(); |
242 for (var i = 0; i < rootLib.classes.length; i++) { | 266 for (var i = 0; i < rootLib.classes.length; i++) { |
243 Class cls = rootLib.classes[i]; | 267 Class cls = rootLib.classes[i]; |
244 if (cls.name == className) { | 268 if (cls.name == className) { |
245 return cls; | 269 return cls; |
246 } | 270 } |
247 } | 271 } |
248 return null; | 272 return null; |
249 } | 273 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 }, onError: (e, st) { | 312 }, onError: (e, st) { |
289 process.requestExit(); | 313 process.requestExit(); |
290 if (!_isWebSocketDisconnect(e)) { | 314 if (!_isWebSocketDisconnect(e)) { |
291 print('Unexpected exception in service tests: $e $st'); | 315 print('Unexpected exception in service tests: $e $st'); |
292 throw e; | 316 throw e; |
293 } | 317 } |
294 }); | 318 }); |
295 }); | 319 }); |
296 } | 320 } |
297 } | 321 } |
OLD | NEW |