| 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 | 4 |
| 5 library test_helper; | 5 library test_helper; |
| 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 import 'package:observatory/service_io.dart'; | 10 import 'package:observatory/service_io.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 Platform.script.toFilePath(), | 26 Platform.script.toFilePath(), |
| 27 _TESTEE_MODE_FLAG] {} | 27 _TESTEE_MODE_FLAG] {} |
| 28 | 28 |
| 29 Future<int> launch(bool pause_on_start, | 29 Future<int> launch(bool pause_on_start, |
| 30 bool pause_on_exit, | 30 bool pause_on_exit, |
| 31 bool pause_on_unhandled_exceptions, | 31 bool pause_on_unhandled_exceptions, |
| 32 bool trace_service) { | 32 bool trace_service) { |
| 33 assert(pause_on_start != null); | 33 assert(pause_on_start != null); |
| 34 assert(pause_on_exit != null); | 34 assert(pause_on_exit != null); |
| 35 assert(trace_service != null); | 35 assert(trace_service != null); |
| 36 // TODO(turnidge): I have temporarily turned on service tracing for |
| 37 // all tests to help diagnose flaky tests. |
| 38 trace_service = true; |
| 36 String dartExecutable = Platform.executable; | 39 String dartExecutable = Platform.executable; |
| 37 var fullArgs = []; | 40 var fullArgs = []; |
| 38 if (trace_service) { | 41 if (trace_service) { |
| 39 fullArgs.add('--trace-service'); | 42 fullArgs.add('--trace-service'); |
| 40 } | 43 } |
| 41 if (pause_on_start) { | 44 if (pause_on_start) { |
| 42 fullArgs.add('--pause-isolates-on-start'); | 45 fullArgs.add('--pause-isolates-on-start'); |
| 43 } | 46 } |
| 44 if (pause_on_exit) { | 47 if (pause_on_exit) { |
| 45 fullArgs.add('--pause-isolates-on-exit'); | 48 fullArgs.add('--pause-isolates-on-exit'); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 276 |
| 274 Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) { | 277 Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) { |
| 275 return hasPausedFor(isolate, ServiceEvent.kPauseBreakpoint); | 278 return hasPausedFor(isolate, ServiceEvent.kPauseBreakpoint); |
| 276 } | 279 } |
| 277 | 280 |
| 278 Future<Isolate> hasStoppedWithUnhandledException(Isolate isolate) { | 281 Future<Isolate> hasStoppedWithUnhandledException(Isolate isolate) { |
| 279 return hasPausedFor(isolate, ServiceEvent.kPauseException); | 282 return hasPausedFor(isolate, ServiceEvent.kPauseException); |
| 280 } | 283 } |
| 281 | 284 |
| 282 Future<Isolate> hasPausedAtStart(Isolate isolate) { | 285 Future<Isolate> hasPausedAtStart(Isolate isolate) { |
| 283 // Set up a listener to wait for breakpoint events. | 286 return hasPausedFor(isolate, ServiceEvent.kPauseStart); |
| 284 Completer completer = new Completer(); | |
| 285 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { | |
| 286 var subscription; | |
| 287 subscription = stream.listen((ServiceEvent event) { | |
| 288 if (event.kind == ServiceEvent.kPauseStart) { | |
| 289 print('Paused at isolate start'); | |
| 290 subscription.cancel(); | |
| 291 if (completer != null) { | |
| 292 // Reload to update isolate.pauseEvent. | |
| 293 completer.complete(isolate.reload()); | |
| 294 completer = null; | |
| 295 } | |
| 296 } | |
| 297 }); | |
| 298 | |
| 299 // Pause may have happened before we subscribed. | |
| 300 isolate.reload().then((_) { | |
| 301 if ((isolate.pauseEvent != null) && | |
| 302 (isolate.pauseEvent.kind == ServiceEvent.kPauseStart)) { | |
| 303 print('Paused at isolate start'); | |
| 304 subscription.cancel(); | |
| 305 if (completer != null) { | |
| 306 completer.complete(isolate); | |
| 307 completer = null; | |
| 308 } | |
| 309 } | |
| 310 }); | |
| 311 }); | |
| 312 | |
| 313 return completer.future; | |
| 314 } | 287 } |
| 315 | 288 |
| 316 | |
| 317 // Currying is your friend. | 289 // Currying is your friend. |
| 318 IsolateTest setBreakpointAtLine(int line) { | 290 IsolateTest setBreakpointAtLine(int line) { |
| 319 return (Isolate isolate) async { | 291 return (Isolate isolate) async { |
| 320 print("Setting breakpoint for line $line"); | 292 print("Setting breakpoint for line $line"); |
| 321 Library lib = await isolate.rootLibrary.load(); | 293 Library lib = await isolate.rootLibrary.load(); |
| 322 Script script = lib.scripts.single; | 294 Script script = lib.scripts.single; |
| 323 | 295 |
| 324 Breakpoint bpt = await isolate.addBreakpoint(script, line); | 296 Breakpoint bpt = await isolate.addBreakpoint(script, line); |
| 325 print("Breakpoint is $bpt"); | 297 print("Breakpoint is $bpt"); |
| 326 expect(bpt, isNotNull); | 298 expect(bpt, isNotNull); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 }, onError: (e, st) { | 441 }, onError: (e, st) { |
| 470 process.requestExit(); | 442 process.requestExit(); |
| 471 if (!_isWebSocketDisconnect(e)) { | 443 if (!_isWebSocketDisconnect(e)) { |
| 472 print('Unexpected exception in service tests: $e $st'); | 444 print('Unexpected exception in service tests: $e $st'); |
| 473 throw e; | 445 throw e; |
| 474 } | 446 } |
| 475 }); | 447 }); |
| 476 }); | 448 }); |
| 477 } | 449 } |
| 478 } | 450 } |
| OLD | NEW |