Stiphle\Storage\ApcTest::testLockRespectsLockWaitTimeoutValue PHP Method

testLockRespectsLockWaitTimeoutValue() public method

    public function testLockRespectsLockWaitTimeoutValue()
    {
        if (!ini_get('apc.enable_cli') && !ini_get('apcu.enable_cli')) {
            $this->markTestSkipped('APC and APCu needs enabling for the cli via apc.enable_cli=1 or apcu.enable_cli=1');
        }
        /**
         * Test we can do this 
         */
        $this->storage->lock('dave');
        try {
            $start = microtime(1);
            $this->storage->lock('dave');
        } catch (LockWaitTimeoutException $e) {
            $caught = microtime(1);
            $diff = $caught - $start;
            if (round($diff) != 1) {
                $this->markTestSkipped("Don't think the timings will be accurate enough, expected exception after 1 second, was {$diff}");
            }
        }
        $this->storage->setLockWaitTimeout(2000);
        try {
            $start = microtime(1);
            $this->storage->lock('dave');
            $this->fail("should not get to this point");
        } catch (LockWaitTimeoutException $e) {
            $caught = microtime(1);
            $diff = $caught - $start;
            $this->assertEquals(2, round($diff), "Exception thrown after approximately 2000 milliseconds");
        }
    }