File tree Expand file tree Collapse file tree 2 files changed +11
-33
lines changed
tests/unit/Spanner/Session Expand file tree Collapse file tree 2 files changed +11
-33
lines changed Original file line number Diff line number Diff line change 2323use Google \Cloud \Core \Lock \SemaphoreLock ;
2424use Google \Cloud \Core \SysvTrait ;
2525use Google \Cloud \Spanner \Database ;
26+ use Grpc \UnaryCall ;
2627use 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 /**
Original file line number Diff line number Diff 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 */
You can’t perform that action at this time.
0 commit comments