| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * Classes and methods for executing tests. | 6 * Classes and methods for executing tests. |
| 7 * | 7 * |
| 8 * This module includes: | 8 * This module includes: |
| 9 * - Managing parallel execution of tests, including timeout checks. | 9 * - Managing parallel execution of tests, including timeout checks. |
| 10 * - Evaluating the output of each test as pass/fail/crash/timeout. | 10 * - Evaluating the output of each test as pass/fail/crash/timeout. |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 Date startTime; | 499 Date startTime; |
| 500 Timer timeoutTimer; | 500 Timer timeoutTimer; |
| 501 List<String> stdout; | 501 List<String> stdout; |
| 502 List<String> stderr; | 502 List<String> stderr; |
| 503 List<Function> handlers; | 503 List<Function> handlers; |
| 504 bool allowRetries; | 504 bool allowRetries; |
| 505 | 505 |
| 506 /** Which command of [testCase.commands] is currently being executed. */ | 506 /** Which command of [testCase.commands] is currently being executed. */ |
| 507 int currentStep; | 507 int currentStep; |
| 508 | 508 |
| 509 static final int kErrorStartingProcess = -171717; // Chosen arbitrarily. |
| 510 |
| 509 RunningProcess(TestCase this.testCase, | 511 RunningProcess(TestCase this.testCase, |
| 510 [this.allowRetries = false, this.processQueue]); | 512 [this.allowRetries = false, this.processQueue]); |
| 511 | 513 |
| 512 /** | 514 /** |
| 513 * Called when all commands are executed. [exitCode] is 0 if all command | 515 * Called when all commands are executed. [exitCode] is 0 if all command |
| 514 * succeded, otherwise it will have the exit code of the first failing | 516 * succeded, otherwise it will have the exit code of the first failing |
| 515 * command. | 517 * command. |
| 516 */ | 518 */ |
| 517 void testComplete(int exitCode) { | 519 void testComplete(int exitCode) { |
| 518 new TestOutput.fromCase(testCase, exitCode, timedOut, stdout, | 520 new TestOutput.fromCase(testCase, exitCode, timedOut, stdout, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 void runCommand(Command command, | 595 void runCommand(Command command, |
| 594 void exitHandler(int exitCode)) { | 596 void exitHandler(int exitCode)) { |
| 595 if (Platform.operatingSystem() == 'windows') { | 597 if (Platform.operatingSystem() == 'windows') { |
| 596 // Windows can't handle the first command if it is a .bat file or the like | 598 // Windows can't handle the first command if it is a .bat file or the like |
| 597 // with the slashes going the other direction. | 599 // with the slashes going the other direction. |
| 598 // TODO(efortuna): Remove this when fixed (Issue 1306). | 600 // TODO(efortuna): Remove this when fixed (Issue 1306). |
| 599 command.executable = command.executable.replaceAll('/', '\\'); | 601 command.executable = command.executable.replaceAll('/', '\\'); |
| 600 } | 602 } |
| 601 process = new Process.start(command.executable, command.arguments); | 603 process = new Process.start(command.executable, command.arguments); |
| 602 process.onExit = exitHandler; | 604 process.onExit = exitHandler; |
| 605 process.onError = (error) { exitHandler(kErrorStartingProcess); }; |
| 603 startTime = new Date.now(); | 606 startTime = new Date.now(); |
| 604 InputStream stdoutStream = process.stdout; | 607 InputStream stdoutStream = process.stdout; |
| 605 InputStream stderrStream = process.stderr; | 608 InputStream stderrStream = process.stderr; |
| 606 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); | 609 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); |
| 607 StringInputStream stderrStringStream = new StringInputStream(stderrStream); | 610 StringInputStream stderrStringStream = new StringInputStream(stderrStream); |
| 608 stdoutStringStream.onLine = | 611 stdoutStringStream.onLine = |
| 609 makeReadHandler(stdoutStringStream, stdout); | 612 makeReadHandler(stdoutStringStream, stdout); |
| 610 stderrStringStream.onLine = | 613 stderrStringStream.onLine = |
| 611 makeReadHandler(stderrStringStream, stderr); | 614 makeReadHandler(stderrStringStream, stderr); |
| 612 timeoutTimer = new Timer(1000 * testCase.timeout, timeoutHandler); | 615 if (timeoutTimer == null) { |
| 616 // Create one timeout timer when starting test case, remove it at end. |
| 617 timeoutTimer = new Timer(1000 * testCase.timeout, timeoutHandler); |
| 618 } |
| 613 } | 619 } |
| 614 | 620 |
| 615 void timeoutHandler(Timer unusedTimer) { | 621 void timeoutHandler(Timer unusedTimer) { |
| 616 timedOut = true; | 622 timedOut = true; |
| 617 process.kill(); | 623 process.kill(); |
| 618 } | 624 } |
| 619 } | 625 } |
| 620 | 626 |
| 621 class BatchRunnerProcess { | 627 class BatchRunnerProcess { |
| 622 String _executable; | 628 String _executable; |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 if (_listTests) { | 1100 if (_listTests) { |
| 1095 final String tab = '\t'; | 1101 final String tab = '\t'; |
| 1096 String outcomes = | 1102 String outcomes = |
| 1097 Strings.join(new List.from(test.expectedOutcomes), ','); | 1103 Strings.join(new List.from(test.expectedOutcomes), ','); |
| 1098 print(test.displayName + tab + outcomes + tab + test.isNegative + | 1104 print(test.displayName + tab + outcomes + tab + test.isNegative + |
| 1099 tab + Strings.join(test.commands.last().arguments, tab)); | 1105 tab + Strings.join(test.commands.last().arguments, tab)); |
| 1100 return; | 1106 return; |
| 1101 } | 1107 } |
| 1102 if (test.usesWebDriver && _needsSelenium && !_isSeleniumAvailable) { | 1108 if (test.usesWebDriver && _needsSelenium && !_isSeleniumAvailable) { |
| 1103 // The server is not ready to run Selenium tests. Put the test back in | 1109 // The server is not ready to run Selenium tests. Put the test back in |
| 1104 // the queue. | 1110 // the queue. Avoid spin-polling by using a timeout. |
| 1105 _tests.addFirst(test); | 1111 _tests.add(test); |
| 1112 new Timer(1000, (timer) {_tryRunTest();}); // Don't lose a process. |
| 1106 return; | 1113 return; |
| 1107 } | 1114 } |
| 1108 if (_verbose) { | 1115 if (_verbose) { |
| 1109 int i = 1; | 1116 int i = 1; |
| 1110 for (Command command in test.commands) { | 1117 for (Command command in test.commands) { |
| 1111 print('$i. ${command.commandLine}'); | 1118 print('$i. ${command.commandLine}'); |
| 1112 i++; | 1119 i++; |
| 1113 } | 1120 } |
| 1114 } | 1121 } |
| 1115 _progress.start(test); | 1122 _progress.start(test); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1132 // the developer doesn't waste his or her time trying to fix a bunch of | 1139 // the developer doesn't waste his or her time trying to fix a bunch of |
| 1133 // tests that appear to be broken but were actually just flakes that | 1140 // tests that appear to be broken but were actually just flakes that |
| 1134 // didn't get retried because there had already been one failure. | 1141 // didn't get retried because there had already been one failure. |
| 1135 bool allowRetry = _MAX_FAILED_NO_RETRY > _progress.numFailedTests; | 1142 bool allowRetry = _MAX_FAILED_NO_RETRY > _progress.numFailedTests; |
| 1136 new RunningProcess(test, allowRetry, this).start(); | 1143 new RunningProcess(test, allowRetry, this).start(); |
| 1137 } | 1144 } |
| 1138 _numProcesses++; | 1145 _numProcesses++; |
| 1139 } | 1146 } |
| 1140 } | 1147 } |
| 1141 } | 1148 } |
| OLD | NEW |