Skip to content

Commit 28190a7

Browse files
committed
Add prose test 4 and drop RequiresPhpExtension from backpressure tests
- Add Prose4: test that maxAdaptiveRetries=1 limits retries to 2 total attempts - Remove #[RequiresPhpExtension('mongodb', '>= 2.3.0dev')] from all three backpressure prose tests since ext-mongodb ^2.3 is now required in composer.json
1 parent 224d2d9 commit 28190a7

3 files changed

Lines changed: 73 additions & 6 deletions

File tree

tests/SpecTests/ClientBackpressure/Prose1_OpRetryExponentialBackoffTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
use MongoDB\Operation\WithTransaction;
88
use MongoDB\Tests\SpecTests\FunctionalTestCase;
99
use MongoDB\Tests\UnifiedSpecTests\Util;
10-
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
1110

1211
use function abs;
1312
use function hrtime;
1413

1514
/**
1615
* Prose test 1: Retry operation uses exponential backoff
1716
*
18-
* @see https://github.com/mongodb/specifications/blob/master/source/client-backpressure/tests/README.md
17+
* @see https://github.com/mongodb/specifications/blob/master/source/client-backpressure/tests/README.md#test-1-operation-retry-uses-exponential-backoff
1918
*/
20-
#[RequiresPhpExtension('mongodb', '>= 2.3.0dev')]
2119
class Prose1_OpRetryExponentialBackoffTest extends FunctionalTestCase
2220
{
2321
public function testOperationRetryUsesExponentialBackoff(): void

tests/SpecTests/ClientBackpressure/Prose3_OverloadErrorMaxRetryTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
use MongoDB\Driver\Monitoring\CommandSubscriber;
99
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
1010
use MongoDB\Tests\SpecTests\FunctionalTestCase;
11-
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
1211

1312
/**
1413
* Prose test 3: Overload Errors are Retried a Maximum of MAX_RETRIES times
1514
*
16-
* @see https://github.com/mongodb/specifications/blob/master/source/client-backpressure/tests/README.md
15+
* @see https://github.com/mongodb/specifications/blob/master/source/client-backpressure/tests/README.md#test-3-overload-errors-are-retried-a-maximum-of-max_retries-times
1716
*/
18-
#[RequiresPhpExtension('mongodb', '>= 2.3.0dev')]
1917
class Prose3_OverloadErrorMaxRetryTest extends FunctionalTestCase
2018
{
2119
private const MAX_RETRIES = 2;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace MongoDB\Tests\SpecTests\ClientBackpressure;
4+
5+
use MongoDB\Driver\Exception\RuntimeException;
6+
use MongoDB\Driver\Monitoring\CommandFailedEvent;
7+
use MongoDB\Driver\Monitoring\CommandStartedEvent;
8+
use MongoDB\Driver\Monitoring\CommandSubscriber;
9+
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
10+
use MongoDB\Tests\SpecTests\FunctionalTestCase;
11+
12+
/**
13+
* Prose test 4: Overload Errors are Retried a Maximum of maxAdaptiveRetries times when configured
14+
*
15+
* @see https://github.com/mongodb/specifications/blob/master/source/client-backpressure/tests/README.md#test-4-overload-errors-are-retried-a-maximum-of-maxadaptiveretries-times-when-configured
16+
*/
17+
class Prose4_OverloadErrorMaxAdaptiveRetriesTest extends FunctionalTestCase
18+
{
19+
private const MAX_ADAPTIVE_RETRIES = 1;
20+
21+
public function testOverloadErrorsAreRetriedMaxAdaptiveRetryTimes(): void
22+
{
23+
$this->skipIfServerVersion('<', '4.3.1', 'Test requires configureFailPoint to support errorLabels');
24+
25+
$client = self::createTestClient(options: ['maxAdaptiveRetries' => self::MAX_ADAPTIVE_RETRIES]);
26+
$collection = $client->selectCollection($this->getDatabaseName(), $this->getCollectionName());
27+
28+
$subscriber = new class implements CommandSubscriber {
29+
public int $findCommandsStarted = 0;
30+
31+
public function commandStarted(CommandStartedEvent $event): void
32+
{
33+
if ($event->getCommandName() === 'find') {
34+
$this->findCommandsStarted++;
35+
}
36+
}
37+
38+
public function commandSucceeded(CommandSucceededEvent $event): void
39+
{
40+
}
41+
42+
public function commandFailed(CommandFailedEvent $event): void
43+
{
44+
}
45+
};
46+
47+
$client->addSubscriber($subscriber);
48+
49+
$this->configureFailPoint([
50+
'configureFailPoint' => 'failCommand',
51+
'mode' => 'alwaysOn',
52+
'data' => [
53+
'failCommands' => ['find'],
54+
'errorCode' => 462, // IngressRequestRateLimitExceeded
55+
'errorLabels' => ['SystemOverloadedError', 'RetryableError'],
56+
],
57+
]);
58+
59+
try {
60+
$collection->find([]);
61+
$this->fail('Expected RuntimeException was not thrown');
62+
} catch (RuntimeException $e) {
63+
$this->assertTrue($e->hasErrorLabel('RetryableError'));
64+
$this->assertTrue($e->hasErrorLabel('SystemOverloadedError'));
65+
}
66+
67+
$client->removeSubscriber($subscriber);
68+
69+
$this->assertSame(self::MAX_ADAPTIVE_RETRIES + 1, $subscriber->findCommandsStarted);
70+
}
71+
}

0 commit comments

Comments
 (0)