From 2bf3ca15d9b62f78e0975946147e71f6d6a5b76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Thu, 26 Oct 2023 13:31:22 +0200 Subject: [PATCH] Introduced RetryChoiceListFactory to deal with parallelism issues (#91) (#92) * Introduced RetryChoiceListFactory to deal with parallelism issues * Fixes * Fixes2 * Added exponential retry --- .../Subscriber/StartScenarioSubscriber.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/bundle/Subscriber/StartScenarioSubscriber.php b/src/bundle/Subscriber/StartScenarioSubscriber.php index 01f25da9..42e808b0 100644 --- a/src/bundle/Subscriber/StartScenarioSubscriber.php +++ b/src/bundle/Subscriber/StartScenarioSubscriber.php @@ -14,6 +14,8 @@ use Facebook\WebDriver\Exception\UnknownErrorException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelInterface; +use Symfony\Component\Lock\LockFactory; +use Symfony\Component\Lock\Store\FlockStore; class StartScenarioSubscriber implements EventSubscriberInterface { @@ -50,7 +52,20 @@ public function resizeWindow(BeforeScenarioTested $event): void $session = $this->kernel->getContainer()->get('behat.mink.default_session'); if (!$session->isStarted()) { - $session->start(); + + $store = new FlockStore(sys_get_temp_dir()); + $factory = new LockFactory($store); + + $lock = $factory->createLock('session-start'); + + if ($lock->acquire(true)) { + try { + $session->start(); + } + finally { + $lock->release(); + } + } } $this->executeWithRetry(function () use ($session): void {