Skip to content

Commit 21a517b

Browse files
authored
test: Retries flakey Bigtable test (GoogleCloudPlatform#1005)
1 parent 53b4b49 commit 21a517b

File tree

5 files changed

+25
-77
lines changed

5 files changed

+25
-77
lines changed

bigtable/phpunit.xml.dist

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
limitations under the License.
1616
-->
1717
<phpunit backupGlobals="false"
18-
strict="true"
1918
backupStaticAttributes="false"
2019
bootstrap="../testing/bootstrap.php"
2120
colors="true"
2221
processIsolation="false"
2322
stopOnFailure="false"
24-
syntaxCheck="false"
2523
timeoutForSmallTests="10"
2624
timeoutForMediumTests="30"
2725
timeoutForLargeTests="120">
@@ -41,4 +39,4 @@
4139
</exclude>
4240
</whitelist>
4341
</filter>
44-
</phpunit>
42+
</phpunit>

bigtable/test/BigtableTestTrait.php

+18
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,22 @@ public static function deleteBigtableInstance()
9595
);
9696
self::$instanceAdminClient->deleteInstance($instanceName);
9797
}
98+
99+
private static function runSnippet($sampleName, $params = [])
100+
{
101+
$sampleFile = sprintf('%s/../src/%s.php', __DIR__, $sampleName);
102+
103+
$testFunc = function () use ($sampleFile, $params) {
104+
return shell_exec(sprintf(
105+
'php %s %s',
106+
$sampleFile,
107+
implode(' ', array_map('escapeshellarg', $params))
108+
));
109+
};
110+
111+
if (isset(self::$backoff)) {
112+
return self::$backoff->execute($testFunc);
113+
}
114+
return $testFunc();
115+
}
98116
}

bigtable/test/filterTest.php

+4-52
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

2121
use Google\Cloud\Bigtable\Mutations;
2222
use PHPUnit\Framework\TestCase;
23+
use PHPUnitRetry\RetryTrait;
2324

2425
final class FilterTest extends TestCase
2526
{
2627
use BigtableTestTrait;
28+
use RetryTrait;
2729

2830
const INSTANCE_ID_PREFIX = 'phpunit-test-';
2931
const TABLE_ID_PREFIX = 'mobile-time-series-';
@@ -84,9 +86,6 @@ public static function tearDownAfterClass(): void
8486
self::deleteBigtableInstance();
8587
}
8688

87-
/**
88-
* @runInSeparateProcess
89-
*/
9089
public function testFilterLimitRowSample()
9190
{
9291
$output = self::runSnippet('filter_snippets', [
@@ -99,9 +98,6 @@ public function testFilterLimitRowSample()
9998
$this->assertContains($result, trim($output));
10099
}
101100

102-
/**
103-
* @runInSeparateProcess
104-
*/
105101
public function testFilterLimitRowRegex()
106102
{
107103
$output = self::runSnippet('filter_snippets', [
@@ -132,9 +128,6 @@ public function testFilterLimitRowRegex()
132128
$this->assertEquals($result, trim($output));
133129
}
134130

135-
/**
136-
* @runInSeparateProcess
137-
*/
138131
public function testFilterLimitCellsPerCol()
139132
{
140133
$output = self::runSnippet('filter_snippets', [
@@ -189,9 +182,6 @@ public function testFilterLimitCellsPerCol()
189182
$this->assertEquals($result, trim($output));
190183
}
191184

192-
/**
193-
* @runInSeparateProcess
194-
*/
195185
public function testFilterLimitCellsPerRow()
196186
{
197187
$output = self::runSnippet('filter_snippets', [
@@ -233,9 +223,6 @@ public function testFilterLimitCellsPerRow()
233223
$this->assertEquals($result, trim($output));
234224
}
235225

236-
/**
237-
* @runInSeparateProcess
238-
*/
239226
public function testFilterLimitCellsPerRowOffset()
240227
{
241228
$output = self::runSnippet('filter_snippets', [
@@ -276,9 +263,6 @@ public function testFilterLimitCellsPerRowOffset()
276263
$this->assertEquals($result, trim($output));
277264
}
278265

279-
/**
280-
* @runInSeparateProcess
281-
*/
282266
public function testFilterLimitColFamilyRegex()
283267
{
284268
$output = self::runSnippet('filter_snippets', [
@@ -321,9 +305,6 @@ public function testFilterLimitColFamilyRegex()
321305
$this->assertEquals($result, trim($output));
322306
}
323307

324-
/**
325-
* @runInSeparateProcess
326-
*/
327308
public function testFilterLimitColQualifierRegex()
328309
{
329310
$output = self::runSnippet('filter_snippets', [
@@ -361,9 +342,6 @@ public function testFilterLimitColQualifierRegex()
361342
$this->assertEquals($result, trim($output));
362343
}
363344

364-
/**
365-
* @runInSeparateProcess
366-
*/
367345
public function testFilterLimitColRange()
368346
{
369347
$output = self::runSnippet('filter_snippets', [
@@ -390,9 +368,6 @@ public function testFilterLimitColRange()
390368
$this->assertEquals($result, trim($output));
391369
}
392370

393-
/**
394-
* @runInSeparateProcess
395-
*/
396371
public function testFilterLimitValueRange()
397372
{
398373
$output = self::runSnippet('filter_snippets', [
@@ -413,9 +388,6 @@ public function testFilterLimitValueRange()
413388
$this->assertEquals($result, trim($output));
414389
}
415390

416-
/**
417-
* @runInSeparateProcess
418-
*/
419391
public function testFilterLimitValueRegex()
420392
{
421393
$output = self::runSnippet('filter_snippets', [
@@ -449,7 +421,8 @@ public function testFilterLimitValueRegex()
449421
}
450422

451423
/**
452-
* @runInSeparateProcess
424+
* @retryAttempts 3
425+
* @retryDelaySeconds 10
453426
*/
454427
public function testFilterLimitTimestampRange()
455428
{
@@ -467,9 +440,6 @@ public function testFilterLimitTimestampRange()
467440
$this->assertEquals($result, trim($output));
468441
}
469442

470-
/**
471-
* @runInSeparateProcess
472-
*/
473443
public function testFilterLimitBlockAll()
474444
{
475445
$output = self::runSnippet('filter_snippets', [
@@ -484,9 +454,6 @@ public function testFilterLimitBlockAll()
484454
$this->assertEquals($result, trim($output));
485455
}
486456

487-
/**
488-
* @runInSeparateProcess
489-
*/
490457
public function testFilterLimitPassAll()
491458
{
492459
$output = self::runSnippet('filter_snippets', [
@@ -541,9 +508,6 @@ public function testFilterLimitPassAll()
541508
$this->assertEquals($result, trim($output));
542509
}
543510

544-
/**
545-
* @runInSeparateProcess
546-
*/
547511
public function testFilterModifyStripValue()
548512
{
549513
$output = self::runSnippet('filter_snippets', [
@@ -598,9 +562,6 @@ public function testFilterModifyStripValue()
598562
$this->assertEquals($result, trim($output));
599563
}
600564

601-
/**
602-
* @runInSeparateProcess
603-
*/
604565
public function testFilterModifyApplyLabel()
605566
{
606567
$output = self::runSnippet('filter_snippets', [
@@ -655,9 +616,6 @@ public function testFilterModifyApplyLabel()
655616
$this->assertEquals($result, trim($output));
656617
}
657618

658-
/**
659-
* @runInSeparateProcess
660-
*/
661619
public function testFilterComposingChain()
662620
{
663621
$output = self::runSnippet('filter_snippets', [
@@ -691,9 +649,6 @@ public function testFilterComposingChain()
691649
$this->assertEquals($result, trim($output));
692650
}
693651

694-
/**
695-
* @runInSeparateProcess
696-
*/
697652
public function testFilterComposingInterleave()
698653
{
699654
$output = self::runSnippet('filter_snippets', [
@@ -745,9 +700,6 @@ public function testFilterComposingInterleave()
745700
$this->assertEquals($result, trim($output));
746701
}
747702

748-
/**
749-
* @runInSeparateProcess
750-
*/
751703
public function testFilterComposingCondition()
752704
{
753705
$output = self::runSnippet('filter_snippets', [

bigtable/test/readTest.php

-21
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ public static function tearDownAfterClass(): void
7272
self::deleteBigtableInstance();
7373
}
7474

75-
/**
76-
* @runInSeparateProcess
77-
*/
7875
public function testReadRow()
7976
{
8077
$output = self::runSnippet('read_snippets', [
@@ -93,9 +90,6 @@ public function testReadRow()
9390
$this->assertEquals($result, trim($output));
9491
}
9592

96-
/**
97-
* @runInSeparateProcess
98-
*/
9993
public function testReadRowPartial()
10094
{
10195
$output = self::runSnippet('read_snippets', [
@@ -112,9 +106,6 @@ public function testReadRowPartial()
112106
$this->assertEquals($result, trim($output));
113107
}
114108

115-
/**
116-
* @runInSeparateProcess
117-
*/
118109
public function testReadRows()
119110
{
120111
$output = self::runSnippet('read_snippets', [
@@ -139,9 +130,6 @@ public function testReadRows()
139130
$this->assertEquals($result, trim($output));
140131
}
141132

142-
/**
143-
* @runInSeparateProcess
144-
*/
145133
public function testReadRowRange()
146134
{
147135
$output = self::runSnippet('read_snippets', [
@@ -172,9 +160,6 @@ public function testReadRowRange()
172160
$this->assertEquals($result, trim($output));
173161
}
174162

175-
/**
176-
* @runInSeparateProcess
177-
*/
178163
public function testReadRowRanges()
179164
{
180165
$output = self::runSnippet('read_snippets', [
@@ -217,9 +202,6 @@ public function testReadRowRanges()
217202
$this->assertEquals($result, trim($output));
218203
}
219204

220-
/**
221-
* @runInSeparateProcess
222-
*/
223205
public function testReadPrefix()
224206
{
225207
$output = self::runSnippet('read_snippets', [
@@ -262,9 +244,6 @@ public function testReadPrefix()
262244
$this->assertEquals($result, trim($output));
263245
}
264246

265-
/**
266-
* @runInSeparateProcess
267-
*/
268247
public function testReadFilter()
269248
{
270249
$output = self::runSnippet('read_snippets', [

testing/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"require-dev": {
33
"google/cloud-tools": "dev-master",
4-
"phpunit/phpunit": "^7"
4+
"phpunit/phpunit": "^7",
5+
"bshaffer/phpunit-retry-annotations": "^0.1.0"
56
}
67
}

0 commit comments

Comments
 (0)