Skip to content

Commit

Permalink
Make sure only one session is started at the time
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon committed Nov 2, 2023
1 parent 138b37c commit 1a50fd0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/bundle/Subscriber/StartScenarioSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -50,7 +52,18 @@ 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 {
Expand Down

0 comments on commit 1a50fd0

Please sign in to comment.