From a4de523aeaa69bf75362e8dba790c36b926e2ddc Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi <41103328+SwikritiT@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:31:38 +0545 Subject: [PATCH] [tests-only][full-ci]Retry listing notifications (#6839) * Retry listing notifications * use loop instaed * use loop instaed * throw exception * use do while loop --- .../bootstrap/NotificationContext.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/features/bootstrap/NotificationContext.php b/tests/acceptance/features/bootstrap/NotificationContext.php index ff4396b1b9b..cf8e764d7cc 100644 --- a/tests/acceptance/features/bootstrap/NotificationContext.php +++ b/tests/acceptance/features/bootstrap/NotificationContext.php @@ -315,10 +315,26 @@ public function filterResponseByNotificationSubjectAndResource(string $subject, * @param TableNode $table * * @return void + * @throws Exception */ public function userShouldGetANotificationWithMessage(string $user, string $subject, TableNode $table):void { - $this->userListAllNotifications($user); - $actualMessage = str_replace(["\r", "\n"], " ", $this->filterResponseAccordingToNotificationSubject($subject)->message); + $count = 0; + // sometimes the test might try to get notification before the notification is created by the server + // in order to prevent test from failing because of that try to list the notifications again + do { + if ($count > 0) { + \sleep(1); + } + $this->featureContext->setResponse(null); + $this->userListAllNotifications($user); + $this->featureContext->theHTTPStatusCodeShouldBe(200); + ++$count; + } while (!isset($this->filterResponseAccordingToNotificationSubject($subject)->message) && $count <= 5); + if (isset($this->filterResponseAccordingToNotificationSubject($subject)->message)) { + $actualMessage = str_replace(["\r", "\n"], " ", $this->filterResponseAccordingToNotificationSubject($subject)->message); + } else { + throw new \Exception("Notification was not found even after retrying for 5 seconds."); + } $expectedMessage = $table->getColumnsHash()[0]['message']; Assert::assertSame( $expectedMessage,