| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 for (var test in vmTests) { | 308 for (var test in vmTests) { |
| 309 vm.verbose = verbose_vm; | 309 vm.verbose = verbose_vm; |
| 310 print('Running $name [$testIndex/$totalTests]'); | 310 print('Running $name [$testIndex/$totalTests]'); |
| 311 testIndex++; | 311 testIndex++; |
| 312 await test(vm); | 312 await test(vm); |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 | 315 |
| 316 // Run isolate tests. | 316 // Run isolate tests. |
| 317 if (isolateTests != null) { | 317 if (isolateTests != null) { |
| 318 var isolate = await vm.isolates.first.load(); | 318 var isolate = await getFirstIsolate(vm); |
| 319 var testIndex = 1; | 319 var testIndex = 1; |
| 320 var totalTests = isolateTests.length; | 320 var totalTests = isolateTests.length; |
| 321 for (var test in isolateTests) { | 321 for (var test in isolateTests) { |
| 322 vm.verbose = verbose_vm; | 322 vm.verbose = verbose_vm; |
| 323 print('Running $name [$testIndex/$totalTests]'); | 323 print('Running $name [$testIndex/$totalTests]'); |
| 324 testIndex++; | 324 testIndex++; |
| 325 await test(isolate); | 325 await test(isolate); |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 print('All service tests completed successfully.'); | 329 print('All service tests completed successfully.'); |
| 330 testsDone = true; | 330 testsDone = true; |
| 331 await process.requestExit(); | 331 await process.requestExit(); |
| 332 }, onError: (error, stackTrace) { | 332 }, onError: (error, stackTrace) { |
| 333 if (testsDone) { | 333 if (testsDone) { |
| 334 print('Ignoring late exception during process exit:\n' | 334 print('Ignoring late exception during process exit:\n' |
| 335 '$error\n#stackTrace'); | 335 '$error\n#stackTrace'); |
| 336 } else { | 336 } else { |
| 337 process.requestExit(); | 337 process.requestExit(); |
| 338 print('Unexpected exception in service tests: $error\n$stackTrace'); | 338 print('Unexpected exception in service tests: $error\n$stackTrace'); |
| 339 throw error; | 339 throw error; |
| 340 } | 340 } |
| 341 }); | 341 }); |
| 342 }); | 342 }); |
| 343 } | 343 } |
| 344 |
| 345 |
| 346 |
| 347 Future<Isolate> getFirstIsolate(WebSocketVM vm) async { |
| 348 if (vm.isolates.isNotEmpty) { |
| 349 var isolate = await vm.isolates.first.load(); |
| 350 if (isolate is Isolate) { |
| 351 return isolate; |
| 352 } |
| 353 } |
| 354 |
| 355 Completer completer = new Completer(); |
| 356 vm.getEventStream(VM.kIsolateStream).then((stream) { |
| 357 var subscription; |
| 358 subscription = stream.listen((ServiceEvent event) async { |
| 359 if (completer == null) { |
| 360 subscription.cancel(); |
| 361 return; |
| 362 } |
| 363 if (event.kind == ServiceEvent.kIsolateRunnable) { |
| 364 if (vm.isolates.isNotEmpty) { |
| 365 vm.isolates.first.load().then((result) { |
| 366 if (result is Isolate) { |
| 367 subscription.cancel(); |
| 368 completer.complete(result); |
| 369 completer = null; |
| 370 } |
| 371 }); |
| 372 } |
| 373 } |
| 374 }); |
| 375 }); |
| 376 |
| 377 // The isolate may have started before we subscribed. |
| 378 if (vm.isolates.isNotEmpty) { |
| 379 vm.isolates.first.reload().then((result) async { |
| 380 if (completer != null && result is Isolate) { |
| 381 completer.complete(result); |
| 382 completer = null; |
| 383 } |
| 384 }); |
| 385 } |
| 386 return await completer.future; |
| 387 } |
| 344 } | 388 } |
| 345 | 389 |
| 346 /// Runs [tests] in sequence, each of which should take an [Isolate] and | 390 /// Runs [tests] in sequence, each of which should take an [Isolate] and |
| 347 /// return a [Future]. Code for setting up state can run before and/or | 391 /// return a [Future]. Code for setting up state can run before and/or |
| 348 /// concurrently with the tests. Uses [mainArgs] to determine whether | 392 /// concurrently with the tests. Uses [mainArgs] to determine whether |
| 349 /// to run tests or testee in this invokation of the script. | 393 /// to run tests or testee in this invokation of the script. |
| 350 Future runIsolateTests(List<String> mainArgs, | 394 Future runIsolateTests(List<String> mainArgs, |
| 351 List<IsolateTest> tests, | 395 List<IsolateTest> tests, |
| 352 {testeeBefore(), | 396 {testeeBefore(), |
| 353 testeeConcurrent(), | 397 testeeConcurrent(), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 new _ServiceTesterRunner().run( | 481 new _ServiceTesterRunner().run( |
| 438 mainArgs: mainArgs, | 482 mainArgs: mainArgs, |
| 439 extraArgs: extraArgs, | 483 extraArgs: extraArgs, |
| 440 vmTests: tests, | 484 vmTests: tests, |
| 441 pause_on_start: pause_on_start, | 485 pause_on_start: pause_on_start, |
| 442 pause_on_exit: pause_on_exit, | 486 pause_on_exit: pause_on_exit, |
| 443 verbose_vm: verbose_vm, | 487 verbose_vm: verbose_vm, |
| 444 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); | 488 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); |
| 445 } | 489 } |
| 446 } | 490 } |
| OLD | NEW |