Skip to content

Commit d395093

Browse files
authored
chore: update to latest google/auth and use sysv cache in tests (#8707)
1 parent f761da5 commit d395093

8 files changed

Lines changed: 33 additions & 46 deletions

File tree

.github/workflows/unit-tests.yaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,7 @@ jobs:
4949
timeout_minutes: 10
5050
max_attempts: 3
5151
command: composer --no-interaction --no-ansi --no-progress update
52-
- if: ${{ matrix.platform == 'windows-latest' }}
53-
name: Run Unit Test Suite (Windows)
54-
run: |
55-
vendor/bin/phpunit -c phpunit.xml.dist
56-
if ( "$?" -ne "0" )
57-
{
58-
echo "*** RETRYING FLAKEY PHPUNIT ON WINDOWS ***"
59-
vendor/bin/phpunit -c phpunit.xml.dist
60-
}
61-
- if: ${{ matrix.platform != 'windows-latest' }}
62-
name: Run Unit Test Suite
52+
- name: Run Unit Test Suite ${{ matrix.platform != 'windows-latest' || '(Windows)' }}
6353
run: |
6454
vendor/bin/phpunit -c phpunit.xml.dist
6555
- if: ${{ matrix.platform != 'windows-latest' }}

Spanner/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"php": "^8.1",
88
"ext-grpc": "*",
99
"google/cloud-core": "^1.68",
10-
"google/gax": "^1.38.0"
10+
"google/gax": "^1.38.1"
1111
},
1212
"require-dev": {
1313
"phpunit/phpunit": "^9.6",
@@ -19,7 +19,6 @@
1919
"google/cloud-pubsub": "^2.0",
2020
"dg/bypass-finals": "^1.7",
2121
"dms/phpunit-arraysubset-asserts": "^0.5.0",
22-
"symfony/cache": "^6.4",
2322
"symfony/process": "^6.4"
2423
},
2524
"suggest": {

Spanner/src/Session/SessionCache.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
throw new RuntimeException('Invalid database name');
8080
}
8181

82-
$this->cacheKey = preg_replace(
82+
$this->cacheKey = rtrim(preg_replace(
8383
self::CACHE_KEY_VALIDATION_REGEX,
8484
'',
8585
sprintf(
@@ -89,11 +89,11 @@ public function __construct(
8989
$identity['database'],
9090
$this->databaseRole,
9191
)
92-
);
92+
), '.');
9393

9494
$this->routeToLeader = $options['routeToLeader'] ?? false;
9595
$this->cacheItemPool = $options['cacheItemPool'] ?? (
96-
extension_loaded('sysvshm')
96+
extension_loaded('sysvshm') && extension_loaded('sysvsem')
9797
? new SysVCacheItemPool()
9898
: new FileSystemCacheItemPool(sys_get_temp_dir() . '/spanner_cache/')
9999
);
@@ -207,6 +207,7 @@ public function __debugInfo()
207207
{
208208
return [
209209
'session' => $this->session,
210+
'cacheKey' => $this->cacheKey,
210211
'cacheItemPool' => $this->cacheItemPool,
211212
];
212213
}

Spanner/tests/System/SystemTestCaseTrait.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Google\Cloud\Spanner\SpannerClient;
2424
use Google\Cloud\Spanner\V1\Client\SpannerClient as SpannerGapicClient;
2525
use Google\Cloud\Spanner\Admin\Database\V1\DatabaseDialect;
26-
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2726

2827
trait SystemTestCaseTrait
2928
{
@@ -71,7 +70,6 @@ private static function getClient()
7170

7271
$clientConfig = [
7372
'keyFilePath' => $keyFilePath,
74-
'cacheItemPool' => self::getCacheItemPool(),
7573
];
7674

7775
$serviceAddress = getenv('SPANNER_SERVICE_ADDRESS');
@@ -192,11 +190,4 @@ private static function getDatabaseFromInstance($instance, $dbName, $options = [
192190
$instance = self::getClient()->instance($instance);
193191
return $instance->database($dbName, $options);
194192
}
195-
196-
private static function getCacheItemPool()
197-
{
198-
return new FilesystemAdapter(
199-
directory: __DIR__ . '/../../../.cache'
200-
);
201-
}
202193
}

Spanner/tests/Unit/InstanceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function setUp(): void
112112
'create_time' => new Timestamp(['seconds' => time()]),
113113
]))->serializeToString());
114114

115-
$cacheKey = 'session_cache.testproject.instancename.databasename.';
115+
$cacheKey = 'session_cache.testproject.instancename.databasename';
116116
$this->cacheItemPool = $this->prophesize(CacheItemPoolInterface::class);
117117
$this->cacheItemPool->getItem($cacheKey)
118118
->willReturn($cacheItem->reveal());

Spanner/tests/Unit/Session/SessionCacheTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use Prophecy\PhpUnit\ProphecyTrait;
2727
use Psr\Cache\CacheItemInterface;
2828
use Psr\Cache\CacheItemPoolInterface;
29-
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
3029
use Symfony\Component\Process\Process;
3130

3231
/**
@@ -64,7 +63,7 @@ public function testEnsureValidSessionCacheHit()
6463
'create_time' => new Timestamp(['seconds' => time()]),
6564
]))->serializeToString());
6665

67-
$cacheKey = 'session_cache.myawesomeproject.myinstance.mydatabase.';
66+
$cacheKey = 'session_cache.myawesomeproject.myinstance.mydatabase';
6867
$cacheItemPool = $this->prophesize(CacheItemPoolInterface::class);
6968
$cacheItemPool->getItem($cacheKey)
7069
->shouldBeCalledOnce()
@@ -73,9 +72,7 @@ public function testEnsureValidSessionCacheHit()
7372
$session = new SessionCache(
7473
$this->spannerClient->reveal(),
7574
$this->databaseName,
76-
[
77-
'cacheItemPool' => $cacheItemPool->reveal(),
78-
]
75+
['cacheItemPool' => $cacheItemPool->reveal()]
7976
);
8077
$name = $session->name();
8178
$this->assertEquals($this->sessionName, $name);
@@ -179,8 +176,7 @@ public function testCacheLocking()
179176
$databaseName = SpannerClient::databaseName(self::PROJECT, self::INSTANCE, $databaseId);
180177
$sessionCache = new SessionCache(
181178
$this->spannerClient->reveal(),
182-
$databaseName,
183-
['cacheItemPool' => new FilesystemAdapter($databaseId)]
179+
$databaseName
184180
);
185181

186182
$process = new Process(['php', __DIR__ . '/lock_test_process.php', $databaseName]);

Spanner/tests/Unit/Session/lock_test_process.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Google\Cloud\Spanner\Tests\Unit\Session;
44

55
use DG\BypassFinals;
6+
use Exception;
7+
use Google\Auth\Cache\FileSystemCacheItemPool;
68
use Google\Cloud\Spanner\Session\SessionCache;
79
use Google\Cloud\Spanner\V1\Client\SpannerClient;
810
use Prophecy\Argument;
911
use Prophecy\PhpUnit\ProphecyTrait;
10-
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1112

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

19-
if (file_exists(__DIR__ . '/../../../vendor/autoload.php')) {
20+
$spannerAutoload = __DIR__ . '/../../../vendor/autoload.php';
21+
$googleCloudAutoload = __DIR__ . '/../../../../vendor/autoload.php';
22+
23+
if (file_exists($spannerAutoload) && file_exists($googleCloudAutoload)) {
24+
throw new Exception('Both autoloaders exist, please remove one');
25+
}
26+
27+
if (file_exists($spannerAutoload)) {
2028
// google/cloud-spanner autoload
21-
require __DIR__ . '/../../../vendor/autoload.php';
22-
} elseif (file_exists(__DIR__ . '/../../../../vendor/autoload.php')) {
29+
require $spannerAutoload;
30+
} elseif (file_exists($googleCloudAutoload)) {
2331
// google/cloud autoload
24-
require __DIR__ . '/../../../../vendor/autoload.php';
32+
require $googleCloudAutoload;
33+
} else {
34+
throw new Exception('no autoloader found');
2535
}
2636

2737
BypassFinals::enable();
2838

29-
$acquireSession = new class($argv[1]) {
39+
[$_cmd, $databaseName] = $argv;
40+
41+
$acquireSession = new class($databaseName) {
3042
use ProphecyTrait;
3143

32-
public function __construct(private string $databaseName)
33-
{
44+
public function __construct(
45+
private string $databaseName,
46+
) {
3447
}
3548

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

44-
$parts = explode('/', $this->databaseName);
4557
$sessionCache = new SessionCache(
4658
$spannerClient->reveal(),
47-
$this->databaseName,
48-
['cacheItemPool' => new FilesystemAdapter(array_pop($parts))]
59+
$this->databaseName
4960
);
5061

5162
return $sessionCache->name();

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"psr/http-message": "^1.0|^2.0",
6565
"ramsey/uuid": "^4.0",
6666
"google/common-protos": "^4.4",
67-
"google/gax": "^1.38.0",
67+
"google/gax": "^1.38.1",
6868
"google/auth": "^1.42"
6969
},
7070
"require-dev": {
@@ -80,7 +80,6 @@
8080
"dg/bypass-finals": "^1.7",
8181
"squizlabs/php_codesniffer": "3.*",
8282
"dms/phpunit-arraysubset-asserts": "^0.5.0",
83-
"symfony/cache": "^6.4",
8483
"symfony/process": "^6.4"
8584
},
8685
"replace": {

0 commit comments

Comments
 (0)