Skip to content

Commit

Permalink
Merge pull request #4 from srjlewis/master
Browse files Browse the repository at this point in the history
Update for multi instance test and driver fix
  • Loading branch information
Geolim4 authored Apr 29, 2024
2 parents 2a979bb + 8d738e6 commit c445d4e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ protected function handleForkedProcess(): void
}

if (static::$prepareToForkPPID) {
if (\version_compare(static::$extVersion, '4.2.0', '<') && static::$prepareToForkPPID !== \posix_getpid()) {
if (\version_compare(static::$extVersion, '4.2.0', '<') && static::$prepareToForkPPID !== $this->currentParentPID) {
$this->currentParentPID = static::$prepareToForkPPID;
$this->connect(\posix_getppid());
}

Expand All @@ -189,9 +190,8 @@ protected function handleForkedProcess(): void
} else {
Cluster::notifyFork(ForkEvent::CHILD);
}
static::$prepareToForkPPID = 0;
}

static::$prepareToForkPPID = 0;
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions tests/Couchbasev4.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@

$testHelper->printInfoText('Running forking success process test');

$config = (include $configFileName)
->setUseStaticItemCaching(false);
$config1 = (include $configFileName)->setUseStaticItemCaching(false);
$config2 = (include $configFileName)->setUseStaticItemCaching(false)->setUsername('test2');

$cacheInstance = CacheManager::getInstance('Couchbasev4', $config);
$cache1 = new Psr16Adapter(CacheManager::getInstance('Couchbasev4', $config1));
$cache2 = new Psr16Adapter(CacheManager::getInstance('Couchbasev4', $config2));

$cache = new Psr16Adapter($cacheInstance);
$value = \random_int(1, 254);
$value1 = \random_int(1, 125);
$value2 = \random_int(1, 125);

$cache->set('forkSuccessTestKey', $value);
$cache1->set('forkSuccessTestKey1', $value1);
$cache2->set('forkSuccessTestKey2', $value2);

try {
\Phpfastcache\Extensions\Drivers\Couchbasev4\Driver::prepareToFork();
Expand All @@ -77,13 +79,13 @@
$testHelper->runAsyncProcess('php "' . __DIR__ . '/Scripts/monitor_fork.php" ' . $pid);
\pcntl_wait($status);
} else {
exit($cache->get('forkSuccessTestKey'));
exit($cache1->get('forkSuccessTestKey1') + $cache2->get('forkSuccessTestKey2'));
}

if ($value === \pcntl_wexitstatus($status)) {
$testHelper->assertPass('The exit code is the one expected');
if (($value1 + $value2) === \pcntl_wexitstatus($status)) {
$testHelper->assertPass('The success fork was a success and returned correctly');
} else {
$testHelper->assertFail('The exit code is unexpected');
$testHelper->assertFail('The success fork failed');
}
} catch (PhpfastcacheDriverCheckException) {
if(\version_compare($extensionVersion, '4.2.0', '=')) {
Expand Down
7 changes: 7 additions & 0 deletions tests/Scripts/install_couchbase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export CB_PACKAGE=couchbase-server-community_7.2.2-linux_amd64.deb
export SERVICES="kv,n1ql,index,fts"

export USERNAME=test
export USERNAME2=test2
export PASSWORD=phpfastcache

export MEMORY_QUOTA=256
Expand Down Expand Up @@ -75,5 +76,11 @@ curl -i "http://127.0.0.1:8091/pools/default/buckets" \
-d flushEnabled=1 \
-u ${USERNAME}:${PASSWORD} \

curl -i -X PUT "http://127.0.0.1:8091/settings/rbac/users/local/${USERNAME2}" \
-d password=${PASSWORD} \
-d roles=bucket_full_access[*] \
-u ${USERNAME}:${PASSWORD}



echo "# Couchbase running successfully"

0 comments on commit c445d4e

Please sign in to comment.