-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for forking failure and lockup of child process
- Loading branch information
Showing
3 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. | ||
* | ||
* @author Georges.L (Geolim4) <[email protected]> | ||
* @author Steven Lewis (srjlewis) https://github.com/srjlewis | ||
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors | ||
*/ | ||
|
||
|
@@ -17,7 +18,6 @@ | |
use Phpfastcache\Exceptions\PhpfastcacheDriverConnectException; | ||
use Phpfastcache\Helper\Psr16Adapter; | ||
use Phpfastcache\Tests\Helper\TestHelper; | ||
use Webmozart\Assert\Assert; | ||
|
||
chdir(__DIR__); | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
@@ -28,6 +28,37 @@ | |
$configFileName = __DIR__ . '/Configs/github-actions.php'; | ||
} | ||
|
||
$testHelper->printInfoText('Running forking failure process test'); | ||
|
||
$config = (new CouchbaseConfig(include $configFileName)) | ||
->setDoPosixCheck(false) | ||
->setUseStaticItemCaching(false); | ||
|
||
$cacheInstance = CacheManager::getInstance('Couchbasev4', $config); | ||
|
||
$cache = new Psr16Adapter($cacheInstance); | ||
$value = random_int(0, 254); | ||
|
||
$cache->set('forkFailTestKey', $value); | ||
|
||
$pid = pcntl_fork(); | ||
if ($pid == -1) { | ||
$testHelper->assertFail('Unable to fork'); | ||
} else if ($pid) { | ||
$testHelper->runAsyncProcess('php "'.__DIR__ . '/Scripts/monitor_fork.php" ' . $pid); | ||
pcntl_wait($status); | ||
} else { | ||
exit($cache->get('forkFailTestKey')); | ||
} | ||
|
||
if ($value === pcntl_wexitstatus($status)) { | ||
$testHelper->assertFail('The fork was a success was meant to lockup'); | ||
} else { | ||
$testHelper->assertPass('The forked process locked up has expected'); | ||
} | ||
|
||
$testHelper->printInfoText('Running forking success process test'); | ||
|
||
$config = (new CouchbaseConfig(include $configFileName)) | ||
->setDoPosixCheck(true) | ||
->setUseStaticItemCaching(false); | ||
|
@@ -37,15 +68,16 @@ | |
$cache = new Psr16Adapter($cacheInstance); | ||
$value = random_int(0, 254); | ||
|
||
$cache->set('key1', $value); | ||
$cache->set('forkSuccessTestKey', $value); | ||
|
||
$pid = pcntl_fork(); | ||
if ($pid == -1) { | ||
die('could not fork'); | ||
$testHelper->assertFail('Unable to fork'); | ||
} else if ($pid) { | ||
$testHelper->runAsyncProcess('php "'.__DIR__ . '/Scripts/monitor_fork.php" ' . $pid); | ||
pcntl_wait($status); | ||
} else { | ||
exit($cache->get('key1')); | ||
exit($cache->get('forkSuccessTestKey')); | ||
} | ||
|
||
if ($value === pcntl_wexitstatus($status)) { | ||
|
@@ -58,7 +90,6 @@ | |
$testHelper->runCRUDTests($cacheInstance); | ||
} catch (PhpfastcacheDriverConnectException $e) { | ||
$testHelper->assertSkip('Couchbase server unavailable: ' . $e->getMessage()); | ||
$testHelper->terminateTest(); | ||
} | ||
$testHelper->terminateTest(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
$pid = (int)$argv[1] ?? 0; | ||
sleep(2); | ||
if (posix_kill($pid, 0)) { | ||
posix_kill($pid, SIGKILL); | ||
} |