| 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'; |
| 11 import 'package:stack_trace/stack_trace.dart'; | |
| 12 import 'service_test_common.dart'; | 11 import 'service_test_common.dart'; |
| 13 | 12 |
| 14 /// Will be set to the http address of the VM's service protocol before | 13 /// Will be set to the http address of the VM's service protocol before |
| 15 /// any tests are invoked. | 14 /// any tests are invoked. |
| 16 String serviceHttpAddress; | 15 String serviceHttpAddress; |
| 17 String serviceWebsocketAddress; | 16 String serviceWebsocketAddress; |
| 18 | 17 |
| 19 const String _TESTEE_ENV_KEY = 'SERVICE_TEST_TESTEE'; | 18 const String _TESTEE_ENV_KEY = 'SERVICE_TEST_TESTEE'; |
| 20 const Map<String, String> _TESTEE_SPAWN_ENV = const { | 19 const Map<String, String> _TESTEE_SPAWN_ENV = const { |
| 21 _TESTEE_ENV_KEY: 'true' | 20 _TESTEE_ENV_KEY: 'true' |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 List<VMTest> vmTests, | 274 List<VMTest> vmTests, |
| 276 List<IsolateTest> isolateTests, | 275 List<IsolateTest> isolateTests, |
| 277 bool pause_on_start: false, | 276 bool pause_on_start: false, |
| 278 bool pause_on_exit: false, | 277 bool pause_on_exit: false, |
| 279 bool verbose_vm: false, | 278 bool verbose_vm: false, |
| 280 bool pause_on_unhandled_exceptions: false, | 279 bool pause_on_unhandled_exceptions: false, |
| 281 bool testeeControlsServer: false, | 280 bool testeeControlsServer: false, |
| 282 bool useAuthToken: false}) { | 281 bool useAuthToken: false}) { |
| 283 var process = new _ServiceTesteeLauncher(); | 282 var process = new _ServiceTesteeLauncher(); |
| 284 bool testsDone = false; | 283 bool testsDone = false; |
| 285 process.launch(pause_on_start, pause_on_exit, | 284 runZoned(() { |
| 285 process.launch(pause_on_start, pause_on_exit, |
| 286 pause_on_unhandled_exceptions, | 286 pause_on_unhandled_exceptions, |
| 287 testeeControlsServer, | 287 testeeControlsServer, |
| 288 useAuthToken, extraArgs).then((Uri serverAddress) async { | 288 useAuthToken, extraArgs).then((Uri serverAddress) async { |
| 289 if (mainArgs.contains("--gdb")) { | 289 if (mainArgs.contains("--gdb")) { |
| 290 var pid = process.process.pid; | 290 var pid = process.process.pid; |
| 291 var wait = new Duration(seconds: 10); | 291 var wait = new Duration(seconds: 10); |
| 292 print("Testee has pid $pid, waiting $wait before continuing"); | 292 print("Testee has pid $pid, waiting $wait before continuing"); |
| 293 sleep(wait); | 293 sleep(wait); |
| 294 } | 294 } |
| 295 setupAddresses(serverAddress); | 295 setupAddresses(serverAddress); |
| 296 var name = Platform.script.pathSegments.last; | 296 var name = Platform.script.pathSegments.last; |
| 297 Chain.capture(() async { | |
| 298 var vm = | 297 var vm = |
| 299 new WebSocketVM(new WebSocketVMTarget(serviceWebsocketAddress)); | 298 new WebSocketVM(new WebSocketVMTarget(serviceWebsocketAddress)); |
| 300 print('Loading VM...'); | 299 print('Loading VM...'); |
| 301 await vm.load(); | 300 await vm.load(); |
| 302 print('Done loading VM'); | 301 print('Done loading VM'); |
| 303 | 302 |
| 304 // Run vm tests. | 303 // Run vm tests. |
| 305 if (vmTests != null) { | 304 if (vmTests != null) { |
| 306 var testIndex = 1; | 305 var testIndex = 1; |
| 307 var totalTests = vmTests.length; | 306 var totalTests = vmTests.length; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 322 vm.verbose = verbose_vm; | 321 vm.verbose = verbose_vm; |
| 323 print('Running $name [$testIndex/$totalTests]'); | 322 print('Running $name [$testIndex/$totalTests]'); |
| 324 testIndex++; | 323 testIndex++; |
| 325 await test(isolate); | 324 await test(isolate); |
| 326 } | 325 } |
| 327 } | 326 } |
| 328 | 327 |
| 329 print('All service tests completed successfully.'); | 328 print('All service tests completed successfully.'); |
| 330 testsDone = true; | 329 testsDone = true; |
| 331 await process.requestExit(); | 330 await process.requestExit(); |
| 332 }, onError: (error, stackTrace) { | |
| 333 if (testsDone) { | |
| 334 print('Ignoring late exception during process exit:\n' | |
| 335 '$error\n#stackTrace'); | |
| 336 } else { | |
| 337 process.requestExit(); | |
| 338 print('Unexpected exception in service tests: $error\n$stackTrace'); | |
| 339 throw error; | |
| 340 } | |
| 341 }); | 331 }); |
| 332 }, onError: (error, stackTrace) async { |
| 333 print('onERROR FIRED!'); |
| 334 if (testsDone) { |
| 335 print('Ignoring late exception during process exit:\n' |
| 336 '$error\n#stackTrace'); |
| 337 } else { |
| 338 await process.requestExit(); |
| 339 print('Unexpected exception in service tests: $error\n$stackTrace'); |
| 340 throw error; |
| 341 } |
| 342 }); | 342 }); |
| 343 } | 343 } |
| 344 | 344 |
| 345 | |
| 346 | |
| 347 Future<Isolate> getFirstIsolate(WebSocketVM vm) async { | 345 Future<Isolate> getFirstIsolate(WebSocketVM vm) async { |
| 348 if (vm.isolates.isNotEmpty) { | 346 if (vm.isolates.isNotEmpty) { |
| 349 var isolate = await vm.isolates.first.load(); | 347 var isolate = await vm.isolates.first.load(); |
| 350 if (isolate is Isolate) { | 348 if (isolate is Isolate) { |
| 351 return isolate; | 349 return isolate; |
| 352 } | 350 } |
| 353 } | 351 } |
| 354 | 352 |
| 355 Completer completer = new Completer(); | 353 Completer completer = new Completer(); |
| 356 vm.getEventStream(VM.kIsolateStream).then((stream) { | 354 vm.getEventStream(VM.kIsolateStream).then((stream) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 new _ServiceTesterRunner().run( | 479 new _ServiceTesterRunner().run( |
| 482 mainArgs: mainArgs, | 480 mainArgs: mainArgs, |
| 483 extraArgs: extraArgs, | 481 extraArgs: extraArgs, |
| 484 vmTests: tests, | 482 vmTests: tests, |
| 485 pause_on_start: pause_on_start, | 483 pause_on_start: pause_on_start, |
| 486 pause_on_exit: pause_on_exit, | 484 pause_on_exit: pause_on_exit, |
| 487 verbose_vm: verbose_vm, | 485 verbose_vm: verbose_vm, |
| 488 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); | 486 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); |
| 489 } | 487 } |
| 490 } | 488 } |
| OLD | NEW |