From 04a4c8cea2a4d8efdad9bd2d0ddeec805a14eb97 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Wed, 6 Dec 2017 13:00:08 -0600 Subject: [PATCH] Test spawning many processes --- test/ProcessTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/ProcessTest.php b/test/ProcessTest.php index bf4c071..d6c7daa 100644 --- a/test/ProcessTest.php +++ b/test/ProcessTest.php @@ -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); + }); + } }