Skip to content

Commit c68d5bf

Browse files
committed
remove wait calls
1 parent 2d65f95 commit c68d5bf

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

src/Spanner/Session/CacheSessionPool.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Google\Cloud\Core\Lock\SemaphoreLock;
2424
use Google\Cloud\Core\SysvTrait;
2525
use Google\Cloud\Spanner\Database;
26+
use Grpc\UnaryCall;
2627
use Psr\Cache\CacheItemPoolInterface;
2728

2829
/**
@@ -118,6 +119,11 @@ class CacheSessionPool implements SessionPoolInterface
118119
*/
119120
private $database;
120121

122+
/**
123+
* @var UnaryCall[]
124+
*/
125+
private $deleteCalls = [];
126+
121127
/**
122128
* @var array
123129
*/
@@ -756,19 +762,18 @@ private function validateConfig()
756762
*/
757763
private function deleteSessions(array $sessions)
758764
{
759-
$calls = [];
765+
// gRPC calls appear to cancel when the corresponding UnaryCall object
766+
// goes out of scope. Keeping the calls in scope allows time for the
767+
// calls to complete at the expense of a small memory footprint.
768+
$this->deleteCalls = [];
760769

761770
foreach ($sessions as $session) {
762-
$calls[] = $this->database->connection()
771+
$this->deleteCalls[] = $this->database->connection()
763772
->deleteSessionAsync([
764773
'name' => $session['name'],
765774
'database' => $this->database->name()
766775
]);
767776
}
768-
769-
foreach ($calls as $call) {
770-
$call->wait();
771-
}
772777
}
773778

774779
/**

tests/unit/Spanner/Session/CacheSessionPoolTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -288,33 +288,6 @@ public function downsizeDataProvider()
288288
];
289289
}
290290

291-
public function testDownsizeFails()
292-
{
293-
$time = time() + 3600;
294-
$pool = new CacheSessionPoolStub($this->getCacheItemPool([
295-
'queue' => [
296-
[
297-
'name' => 'session0',
298-
'expiration' => $time
299-
],
300-
[
301-
'name' => 'session1',
302-
'expiration' => $time
303-
]
304-
],
305-
'inUse' => [],
306-
'toCreate' => [],
307-
'windowStart' => $this->time,
308-
'maxInUseSessions' => 1
309-
]));
310-
$pool->setDatabase($this->getDatabase());
311-
$response = $pool->downsize(100);
312-
313-
$this->assertEquals(0, $response['deleted']);
314-
$this->assertEquals(1, count($response['failed']));
315-
$this->assertContainsOnlyInstancesOf(Session::class, $response['failed']);
316-
}
317-
318291
/**
319292
* @dataProvider invalidPercentDownsizeDataProvider
320293
*/

0 commit comments

Comments
 (0)