| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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=--error_on_bad_type --error_on_bad_override | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
| 5 | 5 |
| 6 import 'test_helper.dart'; | 6 import 'test_helper.dart'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:developer'; | 8 import 'dart:developer'; |
| 9 import 'dart:isolate' as I; | 9 import 'dart:isolate' as I; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 import 'service_test_common.dart'; | 11 import 'service_test_common.dart'; |
| 12 import 'package:observatory/service.dart'; | 12 import 'package:observatory/service.dart'; |
| 13 import 'package:path/path.dart' as path; |
| 13 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
| 14 | 15 |
| 16 // Chop off the file name. |
| 17 String baseDirectory = |
| 18 path.dirname(Platform.script.path) + Platform.pathSeparator; |
| 19 |
| 20 Uri baseUri = Platform.script.replace(path: baseDirectory); |
| 21 Uri spawnUri = baseUri.resolveUri(Uri.parse('complex_reload/v1/main.dart')); |
| 22 Uri v2Uri = baseUri.resolveUri(Uri.parse('complex_reload/v2/main.dart')); |
| 23 Uri v3Uri = baseUri.resolveUri(Uri.parse('complex_reload/v3/main.dart')); |
| 24 |
| 15 testMain() async { | 25 testMain() async { |
| 26 print(baseUri); |
| 16 debugger(); // Stop here. | 27 debugger(); // Stop here. |
| 17 // Spawn the child isolate. | 28 // Spawn the child isolate. |
| 18 I.Isolate isolate = | 29 I.Isolate isolate = |
| 19 await I.Isolate.spawnUri(Uri.parse('complex_reload/v1/main.dart'), | 30 await I.Isolate.spawnUri(spawnUri, |
| 20 [], | 31 [], |
| 21 null); | 32 null); |
| 22 print(isolate); | 33 print(isolate); |
| 23 debugger(); | 34 debugger(); |
| 24 } | 35 } |
| 25 | 36 |
| 26 // Directory that we are running in. | |
| 27 String directory = (Platform.isWindows ? '' : Platform.pathSeparator) + | |
| 28 Platform.script.pathSegments.sublist( | |
| 29 0, | |
| 30 Platform.script.pathSegments.length - 1).join(Platform.pathSeparator); | |
| 31 | |
| 32 Future<String> invokeTest(Isolate isolate) async { | 37 Future<String> invokeTest(Isolate isolate) async { |
| 33 await isolate.reload(); | 38 await isolate.reload(); |
| 34 Library lib = isolate.rootLibrary; | 39 Library lib = isolate.rootLibrary; |
| 35 await lib.load(); | 40 await lib.load(); |
| 36 Instance result = await lib.evaluate('test()'); | 41 Instance result = await lib.evaluate('test()'); |
| 37 expect(result.isString, isTrue); | 42 expect(result.isString, isTrue); |
| 38 return result.valueAsString; | 43 return result.valueAsString; |
| 39 } | 44 } |
| 40 | 45 |
| 41 var tests = [ | 46 var tests = [ |
| 42 // Stopped at 'debugger' statement. | 47 // Stopped at 'debugger' statement. |
| 43 hasStoppedAtBreakpoint, | 48 hasStoppedAtBreakpoint, |
| 44 // Resume the isolate into the while loop. | 49 // Resume the isolate into the while loop. |
| 45 resumeIsolate, | 50 resumeIsolate, |
| 46 // Stop at 'debugger' statement. | 51 // Stop at 'debugger' statement. |
| 47 hasStoppedAtBreakpoint, | 52 hasStoppedAtBreakpoint, |
| 48 (Isolate mainIsolate) async { | 53 (Isolate mainIsolate) async { |
| 49 for (var i = 0; i < Platform.script.pathSegments.length; i++) { | |
| 50 print('segment $i: "${Platform.script.pathSegments[i]}"'); | |
| 51 } | |
| 52 print('Directory: $directory'); | |
| 53 // Grab the VM. | 54 // Grab the VM. |
| 54 VM vm = mainIsolate.vm; | 55 VM vm = mainIsolate.vm; |
| 55 await vm.reloadIsolates(); | 56 await vm.reloadIsolates(); |
| 56 expect(vm.isolates.length, 2); | 57 expect(vm.isolates.length, 2); |
| 57 | 58 |
| 58 // Find the slave isolate. | 59 // Find the slave isolate. |
| 59 Isolate slaveIsolate = | 60 Isolate slaveIsolate = |
| 60 vm.isolates.firstWhere((Isolate i) => i != mainIsolate); | 61 vm.isolates.firstWhere((Isolate i) => i != mainIsolate); |
| 61 expect(slaveIsolate, isNotNull); | 62 expect(slaveIsolate, isNotNull); |
| 62 | 63 |
| 63 // Invoke test in v1. | 64 // Invoke test in v1. |
| 64 String v1 = await invokeTest(slaveIsolate); | 65 String v1 = await invokeTest(slaveIsolate); |
| 65 expect(v1, 'apple'); | 66 expect(v1, 'apple'); |
| 66 | 67 |
| 67 // Reload to v2. | 68 // Reload to v2. |
| 68 var response = await slaveIsolate.reloadSources( | 69 var response = await slaveIsolate.reloadSources( |
| 69 rootLibUri: '$directory${Platform.pathSeparator}' | 70 rootLibUri: v2Uri.toString(), |
| 70 'complex_reload${Platform.pathSeparator}' | |
| 71 'v2${Platform.pathSeparator}' | |
| 72 'main.dart', | |
| 73 ); | 71 ); |
| 74 expect(response['success'], isTrue); | 72 expect(response['success'], isTrue); |
| 75 | 73 |
| 76 // Invoke test in v2. | 74 // Invoke test in v2. |
| 77 String v2 = await invokeTest(slaveIsolate); | 75 String v2 = await invokeTest(slaveIsolate); |
| 78 expect(v2, 'banana'); | 76 expect(v2, 'banana'); |
| 79 | 77 |
| 80 // Reload to v3. | 78 // Reload to v3. |
| 81 response = await slaveIsolate.reloadSources( | 79 response = await slaveIsolate.reloadSources( |
| 82 rootLibUri: '$directory${Platform.pathSeparator}' | 80 rootLibUri: v3Uri.toString(), |
| 83 'complex_reload${Platform.pathSeparator}' | |
| 84 'v3${Platform.pathSeparator}' | |
| 85 'main.dart', | |
| 86 ); | 81 ); |
| 87 expect(response['success'], isTrue); | 82 expect(response['success'], isTrue); |
| 88 | 83 |
| 89 // Invoke test in v3. | 84 // Invoke test in v3. |
| 90 String v3 = await invokeTest(slaveIsolate); | 85 String v3 = await invokeTest(slaveIsolate); |
| 91 expect(v3, 'cabbage'); | 86 expect(v3, 'cabbage'); |
| 92 } | 87 } |
| 93 ]; | 88 ]; |
| 94 | 89 |
| 95 main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain); | 90 main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain); |
| OLD | NEW |