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:path/path.dart' as path; |
14 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
15 | 15 |
16 // Chop off the file name. | 16 // Chop off the file name. |
17 String baseDirectory = path.dirname(Platform.script.path) + '/'; | 17 String baseDirectory = |
| 18 path.dirname(Platform.script.path) + '/'; |
18 | 19 |
19 Uri baseUri = Platform.script.replace(path: baseDirectory); | 20 Uri baseUri = Platform.script.replace(path: baseDirectory); |
20 Uri spawnUri = baseUri.resolveUri(Uri.parse('complex_reload/v1/main.dart')); | 21 Uri spawnUri = baseUri.resolveUri(Uri.parse('complex_reload/v1/main.dart')); |
21 Uri v2Uri = baseUri.resolveUri(Uri.parse('complex_reload/v2/main.dart')); | 22 Uri v2Uri = baseUri.resolveUri(Uri.parse('complex_reload/v2/main.dart')); |
22 Uri v3Uri = baseUri.resolveUri(Uri.parse('complex_reload/v3/main.dart')); | 23 Uri v3Uri = baseUri.resolveUri(Uri.parse('complex_reload/v3/main.dart')); |
23 | 24 |
24 testMain() async { | 25 testMain() async { |
25 print(baseUri); | 26 print(baseUri); |
26 debugger(); // Stop here. | 27 debugger(); // Stop here. |
27 // Spawn the child isolate. | 28 // Spawn the child isolate. |
28 I.Isolate isolate = await I.Isolate.spawnUri(spawnUri, [], null); | 29 I.Isolate isolate = |
| 30 await I.Isolate.spawnUri(spawnUri, |
| 31 [], |
| 32 null); |
29 print(isolate); | 33 print(isolate); |
30 debugger(); | 34 debugger(); |
31 } | 35 } |
32 | 36 |
33 Future<String> invokeTest(Isolate isolate) async { | 37 Future<String> invokeTest(Isolate isolate) async { |
34 await isolate.reload(); | 38 await isolate.reload(); |
35 Library lib = isolate.rootLibrary; | 39 Library lib = isolate.rootLibrary; |
36 await lib.load(); | 40 await lib.load(); |
37 Instance result = await lib.evaluate('test()'); | 41 Instance result = await lib.evaluate('test()'); |
38 expect(result.isString, isTrue); | 42 expect(result.isString, isTrue); |
(...skipping 17 matching lines...) Expand all Loading... |
56 Isolate slaveIsolate = | 60 Isolate slaveIsolate = |
57 vm.isolates.firstWhere((Isolate i) => i != mainIsolate); | 61 vm.isolates.firstWhere((Isolate i) => i != mainIsolate); |
58 expect(slaveIsolate, isNotNull); | 62 expect(slaveIsolate, isNotNull); |
59 | 63 |
60 // Invoke test in v1. | 64 // Invoke test in v1. |
61 String v1 = await invokeTest(slaveIsolate); | 65 String v1 = await invokeTest(slaveIsolate); |
62 expect(v1, 'apple'); | 66 expect(v1, 'apple'); |
63 | 67 |
64 // Reload to v2. | 68 // Reload to v2. |
65 var response = await slaveIsolate.reloadSources( | 69 var response = await slaveIsolate.reloadSources( |
66 rootLibUri: v2Uri.toString(), | 70 rootLibUri: v2Uri.toString(), |
67 ); | 71 ); |
68 expect(response['success'], isTrue); | 72 expect(response['success'], isTrue); |
69 | 73 |
70 // Invoke test in v2. | 74 // Invoke test in v2. |
71 String v2 = await invokeTest(slaveIsolate); | 75 String v2 = await invokeTest(slaveIsolate); |
72 expect(v2, 'banana'); | 76 expect(v2, 'banana'); |
73 | 77 |
74 // Reload to v3. | 78 // Reload to v3. |
75 response = await slaveIsolate.reloadSources( | 79 response = await slaveIsolate.reloadSources( |
76 rootLibUri: v3Uri.toString(), | 80 rootLibUri: v3Uri.toString(), |
77 ); | 81 ); |
78 expect(response['success'], isTrue); | 82 expect(response['success'], isTrue); |
79 | 83 |
80 // Invoke test in v3. | 84 // Invoke test in v3. |
81 String v3 = await invokeTest(slaveIsolate); | 85 String v3 = await invokeTest(slaveIsolate); |
82 expect(v3, 'cabbage'); | 86 expect(v3, 'cabbage'); |
83 } | 87 } |
84 ]; | 88 ]; |
85 | 89 |
86 main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain); | 90 main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain); |
OLD | NEW |