Skip to content

Commit

Permalink
Test various lock storages based on environment
Browse files Browse the repository at this point in the history
  • Loading branch information
digilist committed Oct 20, 2018
1 parent c353886 commit 285c06c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/Unit/PreventOverlappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Lock\Store\FlockStore;
use Symfony\Component\Lock\Store\SemaphoreStore;
use Symfony\Component\Lock\StoreInterface;

final class PreventOverlappingTest extends TestCase
Expand Down Expand Up @@ -70,15 +71,20 @@ public function testPreventOverlapping(StoreInterface $store = null)
$this->assertTrue($event2->isLocked());

// Wait until the process finished
$start = time();
while ($event1->isLocked()) {
// Verify the events are still locked
// Verify the events are still locked while the process is running
$this->assertEquals([], $schedule1->dueEvents(new \DateTimeZone(date_default_timezone_get())));
$this->assertEquals([], $schedule2->dueEvents(new \DateTimeZone(date_default_timezone_get())));
$this->assertTrue($event1->isLocked());
$this->assertTrue($event2->isLocked());

$eventRunner->manageStartedEvents();
usleep(50000);

if (time() - $start > 5) {
$this->fail('Lock was not released after 5 seconds, something is wrong here.');
}
}

// Assert both locks were removed
Expand All @@ -88,10 +94,16 @@ public function testPreventOverlapping(StoreInterface $store = null)

public function lockDataProvider()
{
return [
[null], // Default file locking
[new FlockStore()],
];
// File based lock storage in sys_get_temp_dir()
yield [null];

// Symfony lock with file based lock store
yield [new FlockStore()];

if (extension_loaded('sysvsem')) {
// Symfony lock with semaphore store
yield [new SemaphoreStore()];
}
}
}

Expand Down

0 comments on commit 285c06c

Please sign in to comment.