Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,7 @@ jobs:
timeout_minutes: 10
max_attempts: 3
command: composer --no-interaction --no-ansi --no-progress update
- if: ${{ matrix.platform == 'windows-latest' }}
name: Run Unit Test Suite (Windows)
run: |
vendor/bin/phpunit -c phpunit.xml.dist
if ( "$?" -ne "0" )
{
echo "*** RETRYING FLAKEY PHPUNIT ON WINDOWS ***"
vendor/bin/phpunit -c phpunit.xml.dist
}
- if: ${{ matrix.platform != 'windows-latest' }}
name: Run Unit Test Suite
- name: Run Unit Test Suite ${{ matrix.platform != 'windows-latest' || '(Windows)' }}
run: |
vendor/bin/phpunit -c phpunit.xml.dist
- if: ${{ matrix.platform != 'windows-latest' }}
Expand Down
3 changes: 1 addition & 2 deletions Spanner/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": "^8.1",
"ext-grpc": "*",
"google/cloud-core": "^1.68",
"google/gax": "^1.38.0"
"google/gax": "^1.38.1"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
Expand All @@ -19,7 +19,6 @@
"google/cloud-pubsub": "^2.0",
"dg/bypass-finals": "^1.7",
"dms/phpunit-arraysubset-asserts": "^0.5.0",
"symfony/cache": "^6.4",
"symfony/process": "^6.4"
},
"suggest": {
Expand Down
7 changes: 4 additions & 3 deletions Spanner/src/Session/SessionCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(
throw new RuntimeException('Invalid database name');
}

$this->cacheKey = preg_replace(
$this->cacheKey = rtrim(preg_replace(
self::CACHE_KEY_VALIDATION_REGEX,
'',
sprintf(
Expand All @@ -89,11 +89,11 @@ public function __construct(
$identity['database'],
$this->databaseRole,
)
);
), '.');

$this->routeToLeader = $options['routeToLeader'] ?? false;
$this->cacheItemPool = $options['cacheItemPool'] ?? (
extension_loaded('sysvshm')
extension_loaded('sysvshm') && extension_loaded('sysvsem')
? new SysVCacheItemPool()
: new FileSystemCacheItemPool(sys_get_temp_dir() . '/spanner_cache/')
);
Expand Down Expand Up @@ -207,6 +207,7 @@ public function __debugInfo()
{
return [
'session' => $this->session,
'cacheKey' => $this->cacheKey,
'cacheItemPool' => $this->cacheItemPool,
];
}
Expand Down
9 changes: 0 additions & 9 deletions Spanner/tests/System/SystemTestCaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Google\Cloud\Spanner\SpannerClient;
use Google\Cloud\Spanner\V1\Client\SpannerClient as SpannerGapicClient;
use Google\Cloud\Spanner\Admin\Database\V1\DatabaseDialect;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

trait SystemTestCaseTrait
{
Expand Down Expand Up @@ -71,7 +70,6 @@ private static function getClient()

$clientConfig = [
'keyFilePath' => $keyFilePath,
'cacheItemPool' => self::getCacheItemPool(),
];

$serviceAddress = getenv('SPANNER_SERVICE_ADDRESS');
Expand Down Expand Up @@ -192,11 +190,4 @@ private static function getDatabaseFromInstance($instance, $dbName, $options = [
$instance = self::getClient()->instance($instance);
return $instance->database($dbName, $options);
}

private static function getCacheItemPool()
{
return new FilesystemAdapter(
directory: __DIR__ . '/../../../.cache'
);
}
}
2 changes: 1 addition & 1 deletion Spanner/tests/Unit/InstanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function setUp(): void
'create_time' => new Timestamp(['seconds' => time()]),
]))->serializeToString());

$cacheKey = 'session_cache.testproject.instancename.databasename.';
$cacheKey = 'session_cache.testproject.instancename.databasename';
$this->cacheItemPool = $this->prophesize(CacheItemPoolInterface::class);
$this->cacheItemPool->getItem($cacheKey)
->willReturn($cacheItem->reveal());
Expand Down
10 changes: 3 additions & 7 deletions Spanner/tests/Unit/Session/SessionCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Process\Process;

/**
Expand Down Expand Up @@ -64,7 +63,7 @@ public function testEnsureValidSessionCacheHit()
'create_time' => new Timestamp(['seconds' => time()]),
]))->serializeToString());

$cacheKey = 'session_cache.myawesomeproject.myinstance.mydatabase.';
$cacheKey = 'session_cache.myawesomeproject.myinstance.mydatabase';
$cacheItemPool = $this->prophesize(CacheItemPoolInterface::class);
$cacheItemPool->getItem($cacheKey)
->shouldBeCalledOnce()
Expand All @@ -73,9 +72,7 @@ public function testEnsureValidSessionCacheHit()
$session = new SessionCache(
$this->spannerClient->reveal(),
$this->databaseName,
[
'cacheItemPool' => $cacheItemPool->reveal(),
]
['cacheItemPool' => $cacheItemPool->reveal()]
);
$name = $session->name();
$this->assertEquals($this->sessionName, $name);
Expand Down Expand Up @@ -179,8 +176,7 @@ public function testCacheLocking()
$databaseName = SpannerClient::databaseName(self::PROJECT, self::INSTANCE, $databaseId);
$sessionCache = new SessionCache(
$this->spannerClient->reveal(),
$databaseName,
['cacheItemPool' => new FilesystemAdapter($databaseId)]
$databaseName
);

$process = new Process(['php', __DIR__ . '/lock_test_process.php', $databaseName]);
Expand Down
33 changes: 22 additions & 11 deletions Spanner/tests/Unit/Session/lock_test_process.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Google\Cloud\Spanner\Tests\Unit\Session;

use DG\BypassFinals;
use Exception;
use Google\Auth\Cache\FileSystemCacheItemPool;
use Google\Cloud\Spanner\Session\SessionCache;
use Google\Cloud\Spanner\V1\Client\SpannerClient;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

/**
* Runs a process which is designed to wait while a session is acquired.
Expand All @@ -16,21 +17,33 @@
die('Usage: lock_test_process.php DATABASE_NAME' . PHP_EOL);
}

if (file_exists(__DIR__ . '/../../../vendor/autoload.php')) {
$spannerAutoload = __DIR__ . '/../../../vendor/autoload.php';
$googleCloudAutoload = __DIR__ . '/../../../../vendor/autoload.php';

if (file_exists($spannerAutoload) && file_exists($googleCloudAutoload)) {
throw new Exception('Both autoloaders exist, please remove one');
}

if (file_exists($spannerAutoload)) {
// google/cloud-spanner autoload
require __DIR__ . '/../../../vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../../vendor/autoload.php')) {
require $spannerAutoload;
} elseif (file_exists($googleCloudAutoload)) {
// google/cloud autoload
require __DIR__ . '/../../../../vendor/autoload.php';
require $googleCloudAutoload;
} else {
throw new Exception('no autoloader found');
}

BypassFinals::enable();

$acquireSession = new class($argv[1]) {
[$_cmd, $databaseName] = $argv;

$acquireSession = new class($databaseName) {
use ProphecyTrait;

public function __construct(private string $databaseName)
{
public function __construct(
private string $databaseName,
) {
}

public function run(): string
Expand All @@ -41,11 +54,9 @@ public function run(): string
throw new \Exception('createSession called in child process - this shouldn\'t happen');
});

$parts = explode('/', $this->databaseName);
$sessionCache = new SessionCache(
$spannerClient->reveal(),
$this->databaseName,
['cacheItemPool' => new FilesystemAdapter(array_pop($parts))]
$this->databaseName
);

return $sessionCache->name();
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"psr/http-message": "^1.0|^2.0",
"ramsey/uuid": "^4.0",
"google/common-protos": "^4.4",
"google/gax": "^1.38.0",
"google/gax": "^1.38.1",
"google/auth": "^1.42"
},
"require-dev": {
Expand All @@ -80,7 +80,6 @@
"dg/bypass-finals": "^1.7",
"squizlabs/php_codesniffer": "3.*",
"dms/phpunit-arraysubset-asserts": "^0.5.0",
"symfony/cache": "^6.4",
"symfony/process": "^6.4"
},
"replace": {
Expand Down
Loading