From b3fc8eb5109120081ecfbdbdcc515489a98bb882 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:37:31 +0000 Subject: [PATCH 1/3] feat: custom eventually assertion --- tests/extensions/Async.php | 14 +++++++ tests/extensions/Async/Eventually.php | 54 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/extensions/Async.php create mode 100644 tests/extensions/Async/Eventually.php diff --git a/tests/extensions/Async.php b/tests/extensions/Async.php new file mode 100644 index 0000000000..0fb9c8eea6 --- /dev/null +++ b/tests/extensions/Async.php @@ -0,0 +1,14 @@ +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'; + } +} \ No newline at end of file From c4657eadaf1232a325bb47a29dafcd9c82a72519 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:41:37 +0000 Subject: [PATCH 2/3] fix: phone verification flaky test --- tests/e2e/Services/Account/AccountCustomClientTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index d3fc13bd17..84b740a988 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -2247,12 +2247,10 @@ class AccountCustomClientTest extends Scope $this->assertEmpty($response['body']['secret']); $this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['expire'])); - \sleep(10); - $smsRequest = $this->getLastRequest(); return \array_merge($data, [ - 'token' => $smsRequest['data']['secret'] + 'token' => \substr($smsRequest['data']['message'], 0, 6) ]); } From 4ba92e2591f85fc662e0bfa0f623d9befacfe174 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:43:58 +0000 Subject: [PATCH 3/3] Revert "feat: custom eventually assertion" This reverts commit b3fc8eb5109120081ecfbdbdcc515489a98bb882. --- tests/extensions/Async.php | 14 ------- tests/extensions/Async/Eventually.php | 54 --------------------------- 2 files changed, 68 deletions(-) delete mode 100644 tests/extensions/Async.php delete mode 100644 tests/extensions/Async/Eventually.php diff --git a/tests/extensions/Async.php b/tests/extensions/Async.php deleted file mode 100644 index 0fb9c8eea6..0000000000 --- a/tests/extensions/Async.php +++ /dev/null @@ -1,14 +0,0 @@ -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'; - } -} \ No newline at end of file