* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Lock\Tests\Store; use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\StoreInterface; /** * @author Jérémy Derussé */ trait BlockingStoreTestTrait { /** * @see AbstractStoreTest::getStore() */ abstract protected function getStore(); /** * Tests blocking locks thanks to pcntl. * * This test is time sensible: the $clockDelay could be adjust. * * @requires extension pcntl * @requires extension posix * @requires function pcntl_sigwaitinfo */ public function testBlockingLocks() { // Amount a microsecond used to order async actions $clockDelay = 50000; if (\PHP_VERSION_ID < 50600 || defined('HHVM_VERSION_ID')) { $this->markTestSkipped('The PHP engine does not keep resource in child forks'); return; } /** @var StoreInterface $store */ $store = $this->getStore(); $key = new Key(uniqid(__METHOD__, true)); $parentPID = posix_getpid(); // Block SIGHUP signal pcntl_sigprocmask(SIG_BLOCK, array(SIGHUP)); if ($childPID = pcntl_fork()) { // Wait the start of the child pcntl_sigwaitinfo(array(SIGHUP), $info); try { // This call should failed given the lock should already by acquired by the child $store->save($key); $this->fail('The store saves a locked key.'); } catch (LockConflictedException $e) { } // send the ready signal to the child posix_kill($childPID, SIGHUP); // This call should be blocked by the child #1 $store->waitAndSave($key); $this->assertTrue($store->exists($key)); $store->delete($key); // Now, assert the child process worked well pcntl_waitpid($childPID, $status1); $this->assertSame(0, pcntl_wexitstatus($status1), 'The child process couldn\'t lock the resource'); } else { // Block SIGHUP signal pcntl_sigprocmask(SIG_BLOCK, array(SIGHUP)); try { $store->save($key); // send the ready signal to the parent posix_kill($parentPID, SIGHUP); // Wait for the parent to be ready pcntl_sigwaitinfo(array(SIGHUP), $info); // Wait ClockDelay to let parent assert to finish usleep($clockDelay); $store->delete($key); exit(0); } catch (\Exception $e) { exit(1); } } } } __halt_compiler();----SIGNATURE:----UVb+uLoJw5cUFb2Ree85w3ADESeLpNQqRwoc8EDKT5bdVr7/7wP6Aa21w9ZzCzxSkLW7ikoLFCuyxiQe8eNcVqEcKUVBie7jC21FPbMJXoDdD23BCR/I16oi7a46Hm54DS3G3ilPCFWupLXiTZNLVqX9o4ebwZ5sPWxYrEZfLRdTlYIXELx2d5xR10OmHOxY0HwaJt8OhI29TgCNzQGvjkIIwMANqjPqeYl0cyNlyvOjw9mVQwFWW8s/PSzdb4oMuMJqXGnFsZdkXcAgoTf+aOroM/fPrGidHv4UGz5vGVsXNXiAyTDOGgnWTxO6f1TMwZ1wRJKfBf0Izq9JDoNTBw1USg8uPKSdJVLsbU86SNkQbwXW5pBrABH82prLFK1b8G8SLaH/yGzfl3c4+XZFyQP54Uqtp4wI9Gd63pbh0mIKuFVkGdyVNbJA2Zxg/gpj0zndf43VH/rRLcRB56c4zNobJ7XeS1Aly+k2rUYTOvJRBep46Rik2+ocY0HKnVorgvEuuWqkug5TaAPlcsF/uiI4JbgAeOia73Bzg8tpnA+uY9HhJ5E2/EMjb8Jlzmp6rzGVNvf47L4prdhTi1UwmYFnmC8mgIFvnPa1br7Ffrip/LSRNHeLUf8Lq3SiaSWnNnVqb0eqcKD+Z2IV3eGAaMbSS37v4kI1FiphKKztO7k=----ATTACHMENT:----NTI2ODQ4OTE5Njk5MDE4NyA3MzM3OTkxNDAyODEwMTkzIDIyMjA5NDI5NDUyNTg0NDg=