Skip to content

Commit 7209c36

Browse files
Merge branch '3.4'
* 3.4: (23 commits) [DI] Allow dumping inline services in Yaml fixed CS [2.8] Modify 2.8 upgrade doc - key option is deprecated. Fix lock failling test [Debug] Correctly detect methods not from the same vendor [HttpKernel] Deprecated commands auto-registration Fix minors in date caster [FrameworkBundle] Catch Fatal errors in commands registration [Debug] Detect internal and deprecated methods [Profiler] Make the validator toolbar item consistent with the form one [DebugBundle] Reword an outdated comment about var dumper wiring updated CHANGELOG [HttpFoundation] Remove length limit on ETag [DI] Fix some docblocks [DI] Fix some docblocks Fixed the exception page design in responsive mode [Console] Log exit codes as debug messages instead of errors Fixed UPGRADE-4.0 about Container::set Ignore memcached missing key error on dession destroy [FrameworkBundle] Allow micro kernel to subscribe events easily ...
2 parents 533993c + 0efb1ed commit 7209c36

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

Tests/Store/BlockingStoreTestTrait.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,51 @@ abstract protected function getStore();
3535
public function testBlockingLocks()
3636
{
3737
// Amount a microsecond used to order async actions
38-
$clockDelay = 200000;
38+
$clockDelay = 50000;
3939

4040
/** @var StoreInterface $store */
4141
$store = $this->getStore();
4242
$key = new Key(uniqid(__METHOD__, true));
43+
$parentPID = posix_getpid();
4344

44-
if ($childPID1 = pcntl_fork()) {
45-
// give time to fork to start
46-
usleep(1 * $clockDelay);
45+
// Block SIGHUP signal
46+
pcntl_sigprocmask(SIG_BLOCK, array(SIGHUP));
47+
48+
if ($childPID = pcntl_fork()) {
49+
// Wait the start of the child
50+
pcntl_sigwaitinfo(array(SIGHUP), $info);
4751

4852
try {
49-
// This call should failed given the lock should already by acquired by the child #1
53+
// This call should failed given the lock should already by acquired by the child
5054
$store->save($key);
5155
$this->fail('The store saves a locked key.');
5256
} catch (LockConflictedException $e) {
5357
}
5458

59+
// send the ready signal to the child
60+
posix_kill($childPID, SIGHUP);
61+
5562
// This call should be blocked by the child #1
5663
$store->waitAndSave($key);
5764
$this->assertTrue($store->exists($key));
5865
$store->delete($key);
5966

6067
// Now, assert the child process worked well
61-
pcntl_waitpid($childPID1, $status1);
68+
pcntl_waitpid($childPID, $status1);
6269
$this->assertSame(0, pcntl_wexitstatus($status1), 'The child process couldn\'t lock the resource');
6370
} else {
71+
// Block SIGHUP signal
72+
pcntl_sigprocmask(SIG_BLOCK, array(SIGHUP));
6473
try {
6574
$store->save($key);
66-
// Wait 2 ClockDelay to let parent process to finish
67-
usleep(2 * $clockDelay);
75+
// send the ready signal to the parent
76+
posix_kill($parentPID, SIGHUP);
77+
78+
// Wait for the parent to be ready
79+
pcntl_sigwaitinfo(array(SIGHUP), $info);
80+
81+
// Wait ClockDelay to let parent assert to finish
82+
usleep($clockDelay);
6883
$store->delete($key);
6984
exit(0);
7085
} catch (\Exception $e) {

0 commit comments

Comments
 (0)