diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index 4458a5fffe89..9959b5eec87d 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -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' }} diff --git a/Spanner/composer.json b/Spanner/composer.json index 92284fdad439..6e9b0e9ce40e 100644 --- a/Spanner/composer.json +++ b/Spanner/composer.json @@ -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", @@ -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": { diff --git a/Spanner/src/Session/SessionCache.php b/Spanner/src/Session/SessionCache.php index 815f80a28e23..217debc1e8e4 100644 --- a/Spanner/src/Session/SessionCache.php +++ b/Spanner/src/Session/SessionCache.php @@ -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( @@ -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/') ); @@ -207,6 +207,7 @@ public function __debugInfo() { return [ 'session' => $this->session, + 'cacheKey' => $this->cacheKey, 'cacheItemPool' => $this->cacheItemPool, ]; } diff --git a/Spanner/tests/System/SystemTestCaseTrait.php b/Spanner/tests/System/SystemTestCaseTrait.php index b036d7313bc4..ab0e8ac4a3ab 100644 --- a/Spanner/tests/System/SystemTestCaseTrait.php +++ b/Spanner/tests/System/SystemTestCaseTrait.php @@ -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 { @@ -71,7 +70,6 @@ private static function getClient() $clientConfig = [ 'keyFilePath' => $keyFilePath, - 'cacheItemPool' => self::getCacheItemPool(), ]; $serviceAddress = getenv('SPANNER_SERVICE_ADDRESS'); @@ -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' - ); - } } diff --git a/Spanner/tests/Unit/InstanceTest.php b/Spanner/tests/Unit/InstanceTest.php index 518ce9776449..253f04ffc22e 100644 --- a/Spanner/tests/Unit/InstanceTest.php +++ b/Spanner/tests/Unit/InstanceTest.php @@ -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()); diff --git a/Spanner/tests/Unit/Session/SessionCacheTest.php b/Spanner/tests/Unit/Session/SessionCacheTest.php index 7d073fcfcf20..2f509f36e9a0 100644 --- a/Spanner/tests/Unit/Session/SessionCacheTest.php +++ b/Spanner/tests/Unit/Session/SessionCacheTest.php @@ -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; /** @@ -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() @@ -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); @@ -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]); diff --git a/Spanner/tests/Unit/Session/lock_test_process.php b/Spanner/tests/Unit/Session/lock_test_process.php index 9179c5873e9f..ae4903c62b24 100644 --- a/Spanner/tests/Unit/Session/lock_test_process.php +++ b/Spanner/tests/Unit/Session/lock_test_process.php @@ -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. @@ -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 @@ -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(); diff --git a/composer.json b/composer.json index 4b8e9a1aac35..2fd3b28728ca 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -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": {