-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for testing scheduler and process manager
- Loading branch information
Showing
8 changed files
with
133 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\PhpRunnerBundle\Test; | ||
|
||
use Revolt\EventLoop\Driver\StreamSelectDriver; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
final class ProcessTest extends KernelTestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
if (\is_file($file = $this->getContainer()->getParameter('process_status_file'))) { | ||
\unlink($file); | ||
} | ||
} | ||
|
||
public function testProcessIsLive(): void | ||
{ | ||
$content = $this->getProcessStatusFileContent() ?? $this->fail('Process status file is not found'); | ||
|
||
$this->assertTrue((int) $content > \time() - 4, 'Process started more than 4 seconds ago'); | ||
} | ||
|
||
private function getProcessStatusFileContent(): string|null | ||
{ | ||
$file = $this->getContainer()->getParameter('process_status_file'); | ||
$eventLoop = new StreamSelectDriver(); | ||
$suspension = $eventLoop->getSuspension(); | ||
$eventLoop->delay(3, fn() => $suspension->resume()); | ||
$eventLoop->repeat(0.5, function () use ($file, $suspension) { | ||
if ((\file_exists($file) && $content = @\file_get_contents($file))) { | ||
$suspension->resume($content); | ||
} | ||
}); | ||
|
||
return $suspension->suspend(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luzrain\PhpRunnerBundle\Test; | ||
|
||
use Revolt\EventLoop\Driver\StreamSelectDriver; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
final class TaskTest extends KernelTestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
if (\is_file($file = $this->getContainer()->getParameter('task_status_file'))) { | ||
\unlink($file); | ||
} | ||
} | ||
|
||
public function testTaskIsRunning(): void | ||
{ | ||
$content = $this->getTaskStatusFileContent() ?? $this->fail('Task status file is not found'); | ||
|
||
$this->assertTrue((int) $content > \time() - 4, 'Task was called more than 4 seconds ago'); | ||
} | ||
|
||
private function getTaskStatusFileContent(): string|null | ||
{ | ||
$file = $this->getContainer()->getParameter('task_status_file'); | ||
$eventLoop = new StreamSelectDriver(); | ||
$suspension = $eventLoop->getSuspension(); | ||
$eventLoop->delay(3, fn() => $suspension->resume()); | ||
$eventLoop->repeat(0.5, function () use ($file, $suspension) { | ||
if ((\file_exists($file) && $content = @\file_get_contents($file))) { | ||
$suspension->resume($content); | ||
} | ||
}); | ||
|
||
return $suspension->suspend(); | ||
} | ||
} |