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'; | 11 import 'package:stack_trace/stack_trace.dart'; |
12 import 'service_test_common.dart'; | 12 import 'service_test_common.dart'; |
13 | 13 |
14 /// Will be set to the http address of the VM's service protocol before | 14 /// Will be set to the http address of the VM's service protocol before |
15 /// any tests are invoked. | 15 /// any tests are invoked. |
16 String serviceHttpAddress; | 16 String serviceHttpAddress; |
17 String serviceWebsocketAddress; | 17 String serviceWebsocketAddress; |
18 | 18 |
19 bool _isWebSocketDisconnect(e) { | |
20 return e is NetworkRpcException; | |
21 } | |
22 | |
23 | |
24 const String _TESTEE_ENV_KEY = 'SERVICE_TEST_TESTEE'; | 19 const String _TESTEE_ENV_KEY = 'SERVICE_TEST_TESTEE'; |
25 const Map<String, String> _TESTEE_SPAWN_ENV = const { | 20 const Map<String, String> _TESTEE_SPAWN_ENV = const { |
26 _TESTEE_ENV_KEY: 'true' | 21 _TESTEE_ENV_KEY: 'true' |
27 }; | 22 }; |
28 bool _isTestee() { | 23 bool _isTestee() { |
29 return Platform.environment.containsKey(_TESTEE_ENV_KEY); | 24 return Platform.environment.containsKey(_TESTEE_ENV_KEY); |
30 } | 25 } |
31 | 26 |
32 const String _SKY_SHELL_ENV_KEY = 'SERVICE_TEST_SKY_SHELL'; | 27 const String _SKY_SHELL_ENV_KEY = 'SERVICE_TEST_SKY_SHELL'; |
33 bool _shouldLaunchSkyShell() { | 28 bool _shouldLaunchSkyShell() { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 var isolate = await vm.isolates.first.load(); | 291 var isolate = await vm.isolates.first.load(); |
297 var testIndex = 1; | 292 var testIndex = 1; |
298 var totalTests = isolateTests.length; | 293 var totalTests = isolateTests.length; |
299 for (var test in isolateTests) { | 294 for (var test in isolateTests) { |
300 vm.verbose = verbose_vm; | 295 vm.verbose = verbose_vm; |
301 print('Running $name [$testIndex/$totalTests]'); | 296 print('Running $name [$testIndex/$totalTests]'); |
302 testIndex++; | 297 testIndex++; |
303 await test(isolate); | 298 await test(isolate); |
304 } | 299 } |
305 } | 300 } |
306 }, onError: (e, st) { | 301 }, onError: (error, stackTrace) { |
307 if (!_isWebSocketDisconnect(e)) { | 302 print('Unexpected exception in service tests: $error\n$stackTrace'); |
308 print('Unexpected exception in service tests: $e $st'); | |
309 throw e; | |
310 } | |
311 }); | 303 }); |
312 } | 304 } |
313 } | 305 } |
314 | 306 |
315 void suppressWarning() { | 307 void suppressWarning() { |
316 new _FlutterDeviceServiceTesterRunner(); | 308 new _FlutterDeviceServiceTesterRunner(); |
317 } | 309 } |
318 | 310 |
319 class _ServiceTesterRunner { | 311 class _ServiceTesterRunner { |
320 void run({List<String> mainArgs, | 312 void run({List<String> mainArgs, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 var totalTests = isolateTests.length; | 357 var totalTests = isolateTests.length; |
366 for (var test in isolateTests) { | 358 for (var test in isolateTests) { |
367 vm.verbose = verbose_vm; | 359 vm.verbose = verbose_vm; |
368 print('Running $name [$testIndex/$totalTests]'); | 360 print('Running $name [$testIndex/$totalTests]'); |
369 testIndex++; | 361 testIndex++; |
370 await test(isolate); | 362 await test(isolate); |
371 } | 363 } |
372 } | 364 } |
373 | 365 |
374 await process.requestExit(); | 366 await process.requestExit(); |
375 }, onError: (e, st) { | 367 }, onError: (error, stackTrace) { |
376 process.requestExit(); | 368 process.requestExit(); |
377 // TODO: remove this workaround. | 369 print('Unexpected exception in service tests: $error\n$stackTrace'); |
378 // This is necessary due to non awaited operations. | 370 throw error; |
379 // E.G. object.dart (398~402) | |
380 // When an exception is thrown inside a test (directly or via await) the | |
381 // stacktrace is non-null and shows where the exception has been thrown. | |
382 // If vice versa the exception is due to an error in a non-awaited | |
383 // Future the stacktrace is null. | |
384 if (st != null || !_isWebSocketDisconnect(e)) { | |
385 print('Unexpected exception in service tests: $e $st'); | |
386 throw e; | |
387 } | |
388 }); | 371 }); |
389 }); | 372 }); |
390 } | 373 } |
391 } | 374 } |
392 | 375 |
393 /// Runs [tests] in sequence, each of which should take an [Isolate] and | 376 /// Runs [tests] in sequence, each of which should take an [Isolate] and |
394 /// return a [Future]. Code for setting up state can run before and/or | 377 /// return a [Future]. Code for setting up state can run before and/or |
395 /// concurrently with the tests. Uses [mainArgs] to determine whether | 378 /// concurrently with the tests. Uses [mainArgs] to determine whether |
396 /// to run tests or testee in this invokation of the script. | 379 /// to run tests or testee in this invokation of the script. |
397 Future runIsolateTests(List<String> mainArgs, | 380 Future runIsolateTests(List<String> mainArgs, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 mainArgs: mainArgs, | 469 mainArgs: mainArgs, |
487 vmTests: tests, | 470 vmTests: tests, |
488 pause_on_start: pause_on_start, | 471 pause_on_start: pause_on_start, |
489 pause_on_exit: pause_on_exit, | 472 pause_on_exit: pause_on_exit, |
490 trace_service: trace_service, | 473 trace_service: trace_service, |
491 trace_compiler: trace_compiler, | 474 trace_compiler: trace_compiler, |
492 verbose_vm: verbose_vm, | 475 verbose_vm: verbose_vm, |
493 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); | 476 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); |
494 } | 477 } |
495 } | 478 } |
OLD | NEW |