Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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 /// Integration test that runs the incremental compiler, runs the compiled | 5 /// Integration test that runs the incremental compiler, runs the compiled |
| 6 /// program, incrementally rebuild portions of the app, and triggers a hot | 6 /// program, incrementally rebuild portions of the app, and triggers a hot |
| 7 /// reload on the running program. | 7 /// reload on the running program. |
| 8 library front_end.incremental.hot_reload_e2e_test; | 8 library front_end.incremental.hot_reload_e2e_test; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 tearDown(() async { | 46 tearDown(() async { |
| 47 outDir.deleteSync(recursive: true); | 47 outDir.deleteSync(recursive: true); |
| 48 lines = null; | 48 lines = null; |
| 49 }); | 49 }); |
| 50 | 50 |
| 51 /// Start the VM with the first version of the program compiled by the | 51 /// Start the VM with the first version of the program compiled by the |
| 52 /// incremental compiler. | 52 /// incremental compiler. |
| 53 startProgram(int reloadCount) async { | 53 startProgram(int reloadCount) async { |
| 54 var vmArgs = [ | 54 var vmArgs = [ |
| 55 '--enable-vm-service=0', // Note: use 0 to avoid port collisions. | 55 '--enable-vm-service=0', // Note: use 0 to avoid port collisions. |
| 56 '--platform=${platformFile.toFilePath()}', | 56 '--kernel-binaries=${sdkRoot.toFilePath()}', |
| 57 outputUri.toFilePath() | 57 outputUri.toFilePath() |
| 58 ]; | 58 ]; |
| 59 vmArgs.add('$reloadCount'); | 59 vmArgs.add('$reloadCount'); |
| 60 var vm = await Process.start(Platform.executable, vmArgs); | 60 var vm = await Process.start(Platform.executable, vmArgs); |
| 61 var splitter = new LineSplitter(); | 61 var splitter = new LineSplitter(); |
| 62 | 62 |
| 63 /// The program prints at most 2 + reloadCount lines: | 63 /// The program prints at most 2 + reloadCount lines: |
| 64 /// - a line displaying the observatory port | 64 /// - a line displaying the observatory port |
| 65 /// - a line before waiting for a reload | 65 /// - a line before waiting for a reload |
| 66 /// - a line after each hot-reload | 66 /// - a line after each hot-reload |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 91 var port = int.parse(match.group(1)); | 91 var port = int.parse(match.group(1)); |
| 92 var reloader = new VmReloader(port); | 92 var reloader = new VmReloader(port); |
| 93 var reloadResult = await reloader.reload(outputUri); | 93 var reloadResult = await reloader.reload(outputUri); |
| 94 expect(reloadResult['success'], isTrue); | 94 expect(reloadResult['success'], isTrue); |
| 95 await reloader.disconnect(); | 95 await reloader.disconnect(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 test('initial program is valid', () async { | 98 test('initial program is valid', () async { |
| 99 await startProgram(0); | 99 await startProgram(0); |
| 100 await programIsDone; | 100 await programIsDone; |
| 101 expect(await lines.skip(1).first, "part1 part2"); | 101 expect(await lines[1], "part1 part2"); |
| 102 }); | 102 }); |
| 103 | 103 |
| 104 test('reload after leaf library modification', () async { | 104 test('reload after leaf library modification', () async { |
| 105 await startProgram(1); | 105 await startProgram(1); |
| 106 expect(await lines[1], "part1 part2"); | 106 expect(await lines[1], "part1 part2"); |
| 107 | 107 |
| 108 writeFile(fs, 'b.dart', sourceB.replaceAll("part1", "part3")); | 108 writeFile(fs, 'b.dart', sourceB.replaceAll("part1", "part3")); |
| 109 await rebuild(compiler, outputUri); | 109 await rebuild(compiler, outputUri); |
| 110 await hotReload(); | 110 await hotReload(); |
| 111 await programIsDone; | 111 await programIsDone; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 writeFile(fs, 'a.dart', sourceA.replaceAll("part2", "part8")); | 149 writeFile(fs, 'a.dart', sourceA.replaceAll("part2", "part8")); |
| 150 await rebuild(compiler, outputUri); | 150 await rebuild(compiler, outputUri); |
| 151 await hotReload(); | 151 await hotReload(); |
| 152 await programIsDone; | 152 await programIsDone; |
| 153 expect(await lines[3], "part7 part8"); | 153 expect(await lines[3], "part7 part8"); |
| 154 }); | 154 }); |
| 155 } | 155 } |
| 156 | 156 |
| 157 var dartVm = Uri.base.resolve(Platform.resolvedExecutable); | 157 var dartVm = Uri.base.resolve(Platform.resolvedExecutable); |
| 158 var sdkRoot = dartVm.resolve("patched_sdk/"); | 158 var sdkRoot = dartVm.resolve("patched_sdk/"); |
| 159 var platformFile = sdkRoot.resolve('platform.dill'); | |
| 160 | 159 |
| 161 Future<IncrementalKernelGenerator> createIncrementalCompiler( | 160 Future<IncrementalKernelGenerator> createIncrementalCompiler( |
| 162 String entry, FileSystem fs) { | 161 String entry, FileSystem fs) { |
| 163 var entryUri = Uri.base.resolve(entry); | 162 var entryUri = Uri.base.resolve(entry); |
| 164 var options = new CompilerOptions() | 163 var options = new CompilerOptions() |
| 165 ..sdkRoot = sdkRoot | 164 ..sdkRoot = sdkRoot |
| 166 ..sdkSummary = sdkRoot.resolve('outline.dill') | 165 ..sdkSummary = sdkRoot.resolve('outline.dill') |
| 167 ..packagesFileUri = Uri.parse('file:///.packages') | 166 ..packagesFileUri = Uri.parse('file:///.packages') |
| 168 ..strongMode = false | 167 ..strongMode = false |
| 169 ..dartLibraries = loadDartLibraries() | 168 ..dartLibraries = loadDartLibraries() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 } | 206 } |
| 208 | 207 |
| 209 /// This program calls a function periodically and tracks when the function | 208 /// This program calls a function periodically and tracks when the function |
| 210 /// returns a different value than before (which only happens after a | 209 /// returns a different value than before (which only happens after a |
| 211 /// hot-reload). The program exits after certain number of reloads, specified as | 210 /// hot-reload). The program exits after certain number of reloads, specified as |
| 212 /// an argument to main. | 211 /// an argument to main. |
| 213 const sourceA = r''' | 212 const sourceA = r''' |
| 214 import 'dart:async'; | 213 import 'dart:async'; |
| 215 import 'b.dart'; | 214 import 'b.dart'; |
| 216 | 215 |
| 217 void main(List<String> args) { | 216 void main(List<String> args) async { |
| 217 // Note: this short delay is used to ensure the VM can initialize observatory | |
| 218 // first and we can obtain the port number as the first line in the output. | |
| 219 // If this becomes a source of flakiness, we can make the isolate pause on | |
| 220 // start and start the program via observatory instead. | |
|
ahe
2017/07/10 13:59:35
Let's to that proactively.
Siggi Cherem (dart-lang)
2017/07/10 19:31:11
Done.
| |
| 221 await new Future.delayed(new Duration(milliseconds: 100)); | |
| 218 var last = f(); | 222 var last = f(); |
| 219 print(last); | 223 print(last); |
| 220 | 224 |
| 221 // The argument indicates how many "visible" hot-reloads to run | 225 // The argument indicates how many "visible" hot-reloads to run |
| 222 int reloadCount = 0; | 226 int reloadCount = 0; |
| 223 if (args.length > 0) { | 227 if (args.length > 0) { |
| 224 reloadCount = int.parse(args[0]); | 228 reloadCount = int.parse(args[0]); |
| 225 } | 229 } |
| 226 if (reloadCount == 0) return; | 230 if (reloadCount == 0) return; |
| 227 | 231 |
| 228 new Timer.periodic(new Duration(milliseconds: 100), (timer) { | 232 new Timer.periodic(new Duration(milliseconds: 100), (timer) { |
| 229 var result = f(); | 233 var result = f(); |
| 230 if (last != result) { | 234 if (last != result) { |
| 231 print(result); | 235 print(result); |
| 232 last = result; | 236 last = result; |
| 233 if (--reloadCount == 0) timer.cancel(); | 237 if (--reloadCount == 0) timer.cancel(); |
| 234 } | 238 } |
| 235 }); | 239 }); |
| 236 } | 240 } |
| 237 | 241 |
| 238 f() => "$line part2"; | 242 f() => "$line part2"; |
| 239 '''; | 243 '''; |
| 240 | 244 |
| 241 const sourceB = r''' | 245 const sourceB = r''' |
| 242 get line => "part1"; | 246 get line => "part1"; |
| 243 '''; | 247 '''; |
| 244 | 248 |
| 245 RegExp observatoryPortRegExp = | 249 RegExp observatoryPortRegExp = |
| 246 new RegExp("Observatory listening on http://127.0.0.1:\([0-9]*\)/"); | 250 new RegExp("Observatory listening on http://127.0.0.1:\([0-9]*\)/"); |
| OLD | NEW |