| 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 scheduled_test.scheduled_process; | 5 library scheduled_test.scheduled_process; |
| 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 | 10 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // process is running, we want the schedule to move to the onException | 169 // process is running, we want the schedule to move to the onException |
| 170 // queue where the process will be killed, rather than blocking the tasks | 170 // queue where the process will be killed, rather than blocking the tasks |
| 171 // queue waiting for the process to exit. | 171 // queue waiting for the process to exit. |
| 172 _process.then((p) => p.exitCode).then((exitCode) { | 172 _process.then((p) => p.exitCode).then((exitCode) { |
| 173 if (_endExpected) { | 173 if (_endExpected) { |
| 174 exitCodeCompleter.complete(exitCode); | 174 exitCodeCompleter.complete(exitCode); |
| 175 return; | 175 return; |
| 176 } | 176 } |
| 177 | 177 |
| 178 wrapFuture(pumpEventQueue().then((_) { | 178 wrapFuture(pumpEventQueue().then((_) { |
| 179 if (currentSchedule.currentTask != _taskBeforeEnd) return; | 179 if (currentSchedule.currentTask != _taskBeforeEnd) return null; |
| 180 // If we're one task before the end was scheduled, wait for that task | 180 // If we're one task before the end was scheduled, wait for that task |
| 181 // to complete and pump the event queue so that _endExpected will be | 181 // to complete and pump the event queue so that _endExpected will be |
| 182 // set. | 182 // set. |
| 183 return _taskBeforeEnd.result.then((_) => pumpEventQueue()); | 183 return _taskBeforeEnd.result.then((_) => pumpEventQueue()); |
| 184 }).then((_) { | 184 }).then((_) { |
| 185 exitCodeCompleter.complete(exitCode); | 185 exitCodeCompleter.complete(exitCode); |
| 186 | 186 |
| 187 if (!_endExpected) { | 187 if (!_endExpected) { |
| 188 fail("Process '$description' ended earlier than scheduled " | 188 fail("Process '$description' ended earlier than scheduled " |
| 189 "with exit code $exitCode."); | 189 "with exit code $exitCode."); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 209 .transform(new LineSplitter())); | 209 .transform(new LineSplitter())); |
| 210 } | 210 } |
| 211 | 211 |
| 212 /// Schedule an exception handler that will clean up the process and provide | 212 /// Schedule an exception handler that will clean up the process and provide |
| 213 /// debug information if an error occurs. | 213 /// debug information if an error occurs. |
| 214 void _scheduleExceptionCleanup() { | 214 void _scheduleExceptionCleanup() { |
| 215 currentSchedule.onException.schedule(() { | 215 currentSchedule.onException.schedule(() { |
| 216 _stdoutCanceller(); | 216 _stdoutCanceller(); |
| 217 _stderrCanceller(); | 217 _stderrCanceller(); |
| 218 | 218 |
| 219 if (!_process.hasValue) return; | 219 if (!_process.hasValue) return null; |
| 220 | 220 |
| 221 var killedPrematurely = false; | 221 var killedPrematurely = false; |
| 222 if (!_exitCode.hasValue) { | 222 if (!_exitCode.hasValue) { |
| 223 killedPrematurely = true; | 223 killedPrematurely = true; |
| 224 _endExpected = true; | 224 _endExpected = true; |
| 225 _process.value.kill(ProcessSignal.SIGKILL); | 225 _process.value.kill(ProcessSignal.SIGKILL); |
| 226 // Ensure that the onException queue waits for the process to actually | 226 // Ensure that the onException queue waits for the process to actually |
| 227 // exit after being killed. | 227 // exit after being killed. |
| 228 wrapFuture(_process.value.exitCode, "waiting for process " | 228 wrapFuture(_process.value.exitCode, "waiting for process " |
| 229 "'$description' to die"); | 229 "'$description' to die"); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 schedule(() { | 348 schedule(() { |
| 349 _endExpected = true; | 349 _endExpected = true; |
| 350 return _exitCode.then((exitCode) { | 350 return _exitCode.then((exitCode) { |
| 351 if (expectedExitCode != null) { | 351 if (expectedExitCode != null) { |
| 352 expect(exitCode, equals(expectedExitCode)); | 352 expect(exitCode, equals(expectedExitCode)); |
| 353 } | 353 } |
| 354 }); | 354 }); |
| 355 }, "waiting for process '$description' to exit"); | 355 }, "waiting for process '$description' to exit"); |
| 356 } | 356 } |
| 357 } | 357 } |
| OLD | NEW |