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