Skip to content

Commit cd137af

Browse files
committed
Respect limits for subtasks as well
1 parent 244f22b commit cd137af

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

.github/nightly.php

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,31 +166,41 @@ function (): iterable {
166166

167167
printMutex("Done cloning repos!");
168168

169-
printMutex("Running tests (max $parallel processes)...");
169+
printMutex("Preparing repos (max $parallel processes)...");
170170
foreach ($repos as $dir => [$repo, $branch, $prepare, $command, $repeat]) {
171+
chdir(sys_get_temp_dir()."/$dir");
172+
$rev = e("git rev-parse HEAD", $dir);
173+
171174
$pid = pcntl_fork();
172175
if ($pid) {
173-
$parentPids[$pid] = "test $dir";
176+
$parentPids[$pid] = "prepare $dir ($rev)";
174177
if (count($parentPids) >= $parallel) {
175178
$waitOne();
176179
}
177180
continue;
178181
}
179182

180-
chdir(sys_get_temp_dir()."/$dir");
181-
$rev = e("git rev-parse HEAD");
182183
e("composer i --ignore-platform-reqs", $dir);
183184
if ($prepare) {
184185
$prepare();
185186
}
187+
}
188+
$waitAll();
189+
190+
printMutex("Done preparing repos!");
191+
192+
printMutex("Running tests (max $parallel processes)...");
193+
foreach ($repos as $dir => [$repo, $branch, $prepare, $command, $repeat]) {
194+
chdir(sys_get_temp_dir()."/$dir");
195+
$rev = e("git rev-parse HEAD", $dir);
196+
186197
if ($command instanceof Closure) {
187-
$commands = $command();
198+
$commands = iterator_to_array($command());
188199
} else {
189200
$commands = [$command];
190201
}
191-
$pids = [];
192-
$idx = 0;
193-
foreach ($commands as $cmd) {
202+
203+
foreach ($commands as $idx => $cmd) {
194204
$cmd = array_merge([
195205
'php',
196206
'--repeat',
@@ -200,21 +210,30 @@ function (): iterable {
200210
], $cmd);
201211

202212
$cmdStr = implode(" ", $cmd);
213+
214+
$pid = pcntl_fork();
215+
if ($pid) {
216+
$parentPids[$pid] = "test $dir ($rev): $cmdStr";
217+
if (count($parentPids) >= $parallel) {
218+
$waitOne();
219+
}
220+
continue;
221+
}
222+
223+
$output = sys_get_temp_dir()."/out_{$dir}_$idx.txt";
224+
203225
$p = proc_open($cmd, [
204226
["pipe", "r"],
205-
["file", sys_get_temp_dir()."/out_{$dir}_$idx.txt", "a"],
206-
["file", sys_get_temp_dir()."/out_{$dir}_$idx.txt", "a"]
227+
["file", $output, "a"],
228+
["file", $output, "a"]
207229
], $pipes, sys_get_temp_dir()."/$dir");
230+
208231
if ($p === false) {
209232
printMutex("Failure starting $cmdStr");
210233
exit(1);
211234
}
212-
$pids[$cmdStr] = [$p, sys_get_temp_dir()."/out_{$dir}_$idx.txt"];
213-
$idx++;
214-
}
215-
216-
$final = 0;
217-
foreach ($pids as $cmd => [$p, $result]) {
235+
236+
$final = 0;
218237
$status = proc_close($p);
219238
if ($status !== 0) {
220239
if ($status > 128) {
@@ -225,10 +244,9 @@ function (): iterable {
225244
.file_get_contents($result).PHP_EOL
226245
);
227246
}
228-
}
229247

230-
printMutex("$dir: exiting with status $final");
231-
exit($final);
248+
exit($final);
249+
}
232250
}
233251

234252
$waitAll();

0 commit comments

Comments
 (0)