Skip to content

Commit 74ec5c1

Browse files
authored
PHPLIB-1402: Convert retryable writes spec tests to unified test format (#1238)
Synced with mongodb/specifications@2c080e8 * Remove legacy retryable writes spec tests
1 parent 10f18d7 commit 74ec5c1

File tree

63 files changed

+7919
-5974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+7919
-5974
lines changed

tests/SpecTests/Context.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,6 @@ public static function fromRetryableReads(stdClass $test, $databaseName, $collec
185185
return $o;
186186
}
187187

188-
public static function fromRetryableWrites(stdClass $test, $databaseName, $collectionName, $useMultipleMongoses)
189-
{
190-
$o = new self($databaseName, $collectionName);
191-
192-
$clientOptions = isset($test->clientOptions) ? (array) $test->clientOptions : [];
193-
194-
if (isset($test->outcome->collection->name)) {
195-
$o->outcomeCollectionName = $test->outcome->collection->name;
196-
}
197-
198-
$o->client = self::createTestClient(FunctionalTestCase::getUri($useMultipleMongoses), $clientOptions);
199-
200-
return $o;
201-
}
202-
203188
public static function fromTransactions(stdClass $test, $databaseName, $collectionName, $useMultipleMongoses)
204189
{
205190
$o = new self($databaseName, $collectionName);

tests/SpecTests/ErrorExpectation.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,6 @@ public static function fromRetryableReads(stdClass $operation)
8484
return $o;
8585
}
8686

87-
public static function fromRetryableWrites(stdClass $outcome)
88-
{
89-
$o = new self();
90-
91-
if (isset($outcome->error)) {
92-
$o->isExpected = $outcome->error;
93-
}
94-
95-
/* outcome.result will only contain error label assertions if an error
96-
* is expected (i.e. outcome.error is true). */
97-
if ($o->isExpected && isset($outcome->result->errorLabelsContain)) {
98-
if (! self::isArrayOfStrings($outcome->result->errorLabelsContain)) {
99-
throw InvalidArgumentException::invalidType('errorLabelsContain', $outcome->result->errorLabelsContain, 'string[]');
100-
}
101-
102-
$o->includedLabels = $outcome->result->errorLabelsContain;
103-
}
104-
105-
if ($o->isExpected && isset($outcome->result->errorLabelsOmit)) {
106-
if (! self::isArrayOfStrings($outcome->result->errorLabelsOmit)) {
107-
throw InvalidArgumentException::invalidType('errorLabelsOmit', $outcome->result->errorLabelsOmit, 'string[]');
108-
}
109-
110-
$o->excludedLabels = $outcome->result->errorLabelsOmit;
111-
}
112-
113-
return $o;
114-
}
115-
11687
/** @throws InvalidArgumentException */
11788
public static function fromTransactions(stdClass $operation)
11889
{

tests/SpecTests/Operation.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,6 @@ public static function fromRetryableReads(stdClass $operation)
150150
return $o;
151151
}
152152

153-
public static function fromRetryableWrites(stdClass $operation, stdClass $outcome)
154-
{
155-
$o = new self($operation);
156-
157-
$o->errorExpectation = ErrorExpectation::fromRetryableWrites($outcome);
158-
$o->resultExpectation = ResultExpectation::fromRetryableWrites($outcome, $o->getResultAssertionType());
159-
160-
return $o;
161-
}
162-
163153
public static function fromTransactions(stdClass $operation)
164154
{
165155
$o = new self($operation);

tests/SpecTests/ResultExpectation.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,6 @@ public static function fromRetryableReads(stdClass $operation, $defaultAssertion
122122
return new self($assertionType, $expectedValue);
123123
}
124124

125-
public static function fromRetryableWrites(stdClass $outcome, $defaultAssertionType)
126-
{
127-
if (property_exists($outcome, 'result') && ! self::isErrorResult($outcome->result)) {
128-
$assertionType = $outcome->result === null ? self::ASSERT_NULL : $defaultAssertionType;
129-
$expectedValue = $outcome->result;
130-
} else {
131-
$assertionType = self::ASSERT_NOTHING;
132-
$expectedValue = null;
133-
}
134-
135-
return new self($assertionType, $expectedValue);
136-
}
137-
138125
public static function fromTransactions(stdClass $operation, $defaultAssertionType)
139126
{
140127
if (property_exists($operation, 'result') && ! self::isErrorResult($operation->result)) {

tests/SpecTests/RetryableWritesSpecTest.php

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
use MongoDB\Driver\Monitoring\CommandStartedEvent;
88
use MongoDB\Driver\Monitoring\CommandSubscriber;
99
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
10-
use stdClass;
11-
12-
use function basename;
13-
use function file_get_contents;
14-
use function glob;
1510

1611
/**
1712
* Retryable writes spec tests.
@@ -24,61 +19,6 @@ class RetryableWritesSpecTest extends FunctionalTestCase
2419
public const NOT_PRIMARY = 10107;
2520
public const SHUTDOWN_IN_PROGRESS = 91;
2621

27-
/**
28-
* Execute an individual test case from the specification.
29-
*
30-
* @dataProvider provideTests
31-
* @param stdClass $test Individual "tests[]" document
32-
* @param array $runOn Top-level "runOn" array with server requirements
33-
* @param array $data Top-level "data" array to initialize collection
34-
*/
35-
public function testRetryableWrites(stdClass $test, ?array $runOn, array $data): void
36-
{
37-
if (isset($runOn)) {
38-
$this->checkServerRequirements($runOn);
39-
}
40-
41-
// Serverless uses a load balancer fronting a single proxy (PHPLIB-757)
42-
$useMultipleMongoses = $this->isMongos() || ($this->isLoadBalanced() && ! $this->isServerless())
43-
? ($test->useMultipleMongoses ?? false)
44-
: false;
45-
46-
$context = Context::fromRetryableWrites($test, $this->getDatabaseName(), $this->getCollectionName(), $useMultipleMongoses);
47-
$this->setContext($context);
48-
49-
$this->dropTestAndOutcomeCollections();
50-
$this->insertDataFixtures($data);
51-
52-
if (isset($test->failPoint)) {
53-
$this->configureFailPoint($test->failPoint);
54-
}
55-
56-
Operation::fromRetryableWrites($test->operation, $test->outcome)->assert($this, $context);
57-
58-
if (isset($test->outcome->collection->data)) {
59-
$this->assertOutcomeCollectionData($test->outcome->collection->data);
60-
}
61-
}
62-
63-
public function provideTests()
64-
{
65-
$testArgs = [];
66-
67-
foreach (glob(__DIR__ . '/retryable-writes/*.json') as $filename) {
68-
$json = $this->decodeJson(file_get_contents($filename));
69-
$group = basename($filename, '.json');
70-
$runOn = $json->runOn ?? null;
71-
$data = $json->data ?? [];
72-
73-
foreach ($json->tests as $test) {
74-
$name = $group . ': ' . $test->description;
75-
$testArgs[$name] = [$test, $runOn, $data];
76-
}
77-
}
78-
79-
return $testArgs;
80-
}
81-
8222
/**
8323
* Prose test 3: when encountering a NoWritesPerformed error after an error with a RetryableWriteError label
8424
*/

0 commit comments

Comments
 (0)