1
0
mirror of https://github.com/danog/process.git synced 2024-11-30 04:39:04 +01:00

Test spawning many processes

This commit is contained in:
Aaron Piotrowski 2017-12-06 13:00:08 -06:00
parent 55bf848767
commit 04a4c8cea2
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -258,4 +258,33 @@ class ProcessTest extends TestCase {
$process = new Process(self::CMD_PROCESS);
$this->assertSame([], $process->getOptions());
}
public function getProcessCounts(): array {
return \array_map(function (int $count): array {
return [$count];
}, \range(1, 31, 2));
}
/**
* @dataProvider getProcessCounts
*
* @param int $count
*/
public function testSpawnMultipleProcesses(int $count) {
Loop::run(function () use ($count) {
$processes = [];
for ($i = 0; $i < $count; ++$i) {
$command = \DIRECTORY_SEPARATOR === "\\" ? "cmd /c exit $i" : "exit $i";
$processes[] = new Process(self::CMD_PROCESS_SLOW . " && " . $command);
}
$promises = [];
foreach ($processes as $process) {
$process->start();
$promises[] = $process->join();
}
$this->assertSame(\range(0, $count - 1), yield $promises);
});
}
}