|
18 | 18 |
|
19 | 19 | class RunTestFailedCommand extends BaseGenerateCommand
|
20 | 20 | {
|
| 21 | + const DEFAULT_TEST_GROUP = 'default'; |
| 22 | + |
21 | 23 | /**
|
22 | 24 | * @var string
|
23 | 25 | */
|
24 |
| - private $testsManifestFile; |
| 26 | + private $testsReRunFile = ""; |
25 | 27 |
|
26 | 28 | /**
|
27 | 29 | * @var array
|
@@ -54,22 +56,14 @@ protected function configure()
|
54 | 56 | */
|
55 | 57 | protected function execute(InputInterface $input, OutputInterface $output): int
|
56 | 58 | {
|
57 |
| - $returnCode = $this->executeGenerateFailed($input, $output); |
58 |
| - if ($returnCode !== 0) { |
59 |
| - return $returnCode; |
60 |
| - } |
61 |
| - |
62 | 59 | $this->testsFailedFile = $this->getTestsOutputDir() . self::FAILED_FILE;
|
63 | 60 | $this->testsReRunFile = $this->getTestsOutputDir() . "rerun_tests";
|
64 | 61 |
|
65 |
| - $this->testsManifestFile= FilePathFormatter::format(TESTS_MODULE_PATH) . |
66 |
| - "_generated" . |
67 |
| - DIRECTORY_SEPARATOR . |
68 |
| - "testManifest.txt"; |
| 62 | + $failedTests = $this->readFailedTestFile($this->testsFailedFile); |
| 63 | + $testManifestList = $this->filterTestsForExecution($failedTests); |
69 | 64 |
|
70 |
| - $testManifestList = $this->readTestManifestFile(); |
71 |
| - if ($testManifestList === false) { |
72 |
| - // If there is no test manifest file then we have nothing to execute. |
| 65 | + if (empty($testManifestList)) { |
| 66 | + // If there is no tests in manifest then we have nothing to execute. |
73 | 67 | return 0;
|
74 | 68 | }
|
75 | 69 | $returnCode = 0;
|
@@ -113,51 +107,31 @@ function ($type, $buffer) use ($output) {
|
113 | 107 | }
|
114 | 108 |
|
115 | 109 | /**
|
116 |
| - * Execute generate failed tests command as a separate process, so that we can kill it and avoid high memory usage. |
| 110 | + * Returns a list of tests/suites which should have an additional run. |
117 | 111 | *
|
118 |
| - * @param InputInterface $input |
119 |
| - * @param OutputInterface $output |
120 |
| - * @return integer |
121 |
| - * |
122 |
| - * @SuppressWarnings(PHPMD.UnusedLocalVariable) |
123 |
| - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 112 | + * @param $failedTests |
| 113 | + * @return array |
124 | 114 | */
|
125 |
| - private function executeGenerateFailed(InputInterface $input, OutputInterface $output) |
| 115 | + private function filterTestsForExecution($failedTests): array |
126 | 116 | {
|
127 |
| - $returnCode = 0; |
128 |
| - $binMftf = PROJECT_ROOT . '/vendor/bin/mftf'; |
129 |
| - if (file_exists($binMftf) === false) { |
130 |
| - $binMftf = PROJECT_ROOT . '/bin/mftf'; |
131 |
| - } |
132 |
| - $forceGenerate = $input->getOption('force') ? ' -f' : ''; |
133 |
| - $mftfCommand = realpath($binMftf) . ' generate:failed' . $forceGenerate; |
134 |
| - |
135 |
| - $process = new Process($mftfCommand); |
136 |
| - $process->setWorkingDirectory(TESTS_BP); |
137 |
| - $process->setIdleTimeout(600); |
138 |
| - $process->setTimeout(0); |
139 |
| - $returnCode = max($returnCode, $process->run( |
140 |
| - function ($type, $buffer) use ($output) { |
141 |
| - $output->write($buffer); |
| 117 | + $testsOrGroupsToRerun = []; |
| 118 | + |
| 119 | + foreach ($failedTests as $test) { |
| 120 | + if (!empty($test)) { |
| 121 | + $this->writeFailedTestToFile($test, $this->testsReRunFile); |
| 122 | + $testInfo = explode(DIRECTORY_SEPARATOR, $test); |
| 123 | + $suiteName = $testInfo[count($testInfo) - 2]; |
| 124 | + list($testPath) = explode(":", $test); |
| 125 | + |
| 126 | + if ($suiteName === self::DEFAULT_TEST_GROUP) { |
| 127 | + $testsOrGroupsToRerun[] = $testPath; |
| 128 | + } else { |
| 129 | + $testsOrGroupsToRerun[] = "-g " . $suiteName; |
| 130 | + } |
142 | 131 | }
|
143 |
| - )); |
144 |
| - $process->__destruct(); |
145 |
| - unset($process); |
146 |
| - |
147 |
| - return $returnCode; |
148 |
| - } |
149 |
| - |
150 |
| - /** |
151 |
| - * Returns an array of run commands read from the manifest file created post generation |
152 |
| - * |
153 |
| - * @return array|boolean |
154 |
| - */ |
155 |
| - private function readTestManifestFile() |
156 |
| - { |
157 |
| - if (file_exists($this->testsManifestFile)) { |
158 |
| - return file($this->testsManifestFile, FILE_IGNORE_NEW_LINES); |
159 | 132 | }
|
160 |
| - return false; |
| 133 | + |
| 134 | + return $testsOrGroupsToRerun; |
161 | 135 | }
|
162 | 136 |
|
163 | 137 | /**
|
|
0 commit comments