mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Revert "feat: custom eventually assertion"
This reverts commit b3fc8eb510.
This commit is contained in:
parent
c4657eadaf
commit
4ba92e2591
2 changed files with 0 additions and 68 deletions
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Tests;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\Assert;
|
|
||||||
use Appwrite\Tests\Async\Eventually;
|
|
||||||
|
|
||||||
trait Async
|
|
||||||
{
|
|
||||||
public static function assertEventually(callable $probe, int $timeoutMilliseconds = 10000, int $waitMilliseconds = 500): void
|
|
||||||
{
|
|
||||||
Assert::assertThat($probe, new Eventually($timeoutMilliseconds, $waitMilliseconds));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Appwrite\Tests\Async;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\Constraint\Constraint;
|
|
||||||
|
|
||||||
final class Eventually extends Constraint
|
|
||||||
{
|
|
||||||
private int $timeoutMs;
|
|
||||||
private int $waitMs;
|
|
||||||
|
|
||||||
public function __construct(int $timeoutMs = 10000, int $waitMs = 500)
|
|
||||||
{
|
|
||||||
$this->timeoutMs = $timeoutMs;
|
|
||||||
$this->waitMs = $waitMs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function evaluate(mixed $probe, string $description = '', bool $returnResult = false): ?bool
|
|
||||||
{
|
|
||||||
if (!is_callable($probe)) {
|
|
||||||
throw new \Exception('Probe must be a callable');
|
|
||||||
}
|
|
||||||
|
|
||||||
$start = microtime(true);
|
|
||||||
$lastException = null;
|
|
||||||
|
|
||||||
do {
|
|
||||||
try {
|
|
||||||
$probe();
|
|
||||||
return true;
|
|
||||||
} catch (\Exception $exception) {
|
|
||||||
$lastException = $exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep($this->waitMs * 1000);
|
|
||||||
} while (microtime(true) - $start < $this->timeoutMs / 1000);
|
|
||||||
|
|
||||||
if ($returnResult) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $lastException;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function failureDescription(mixed $other): string
|
|
||||||
{
|
|
||||||
return 'the given probe was satisfied within the provided timeout';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toString(): string
|
|
||||||
{
|
|
||||||
return 'Eventually';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue