Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPLIB-1402: Convert retryable writes spec tests to unified test format #1238

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions tests/SpecTests/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,6 @@ public static function fromRetryableReads(stdClass $test, $databaseName, $collec
return $o;
}

public static function fromRetryableWrites(stdClass $test, $databaseName, $collectionName, $useMultipleMongoses)
{
$o = new self($databaseName, $collectionName);

$clientOptions = isset($test->clientOptions) ? (array) $test->clientOptions : [];

if (isset($test->outcome->collection->name)) {
$o->outcomeCollectionName = $test->outcome->collection->name;
}

$o->client = self::createTestClient(FunctionalTestCase::getUri($useMultipleMongoses), $clientOptions);

return $o;
}

public static function fromTransactions(stdClass $test, $databaseName, $collectionName, $useMultipleMongoses)
{
$o = new self($databaseName, $collectionName);
Expand Down
29 changes: 0 additions & 29 deletions tests/SpecTests/ErrorExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,6 @@ public static function fromRetryableReads(stdClass $operation)
return $o;
}

public static function fromRetryableWrites(stdClass $outcome)
{
$o = new self();

if (isset($outcome->error)) {
$o->isExpected = $outcome->error;
}

/* outcome.result will only contain error label assertions if an error
* is expected (i.e. outcome.error is true). */
if ($o->isExpected && isset($outcome->result->errorLabelsContain)) {
if (! self::isArrayOfStrings($outcome->result->errorLabelsContain)) {
throw InvalidArgumentException::invalidType('errorLabelsContain', $outcome->result->errorLabelsContain, 'string[]');
}

$o->includedLabels = $outcome->result->errorLabelsContain;
}

if ($o->isExpected && isset($outcome->result->errorLabelsOmit)) {
if (! self::isArrayOfStrings($outcome->result->errorLabelsOmit)) {
throw InvalidArgumentException::invalidType('errorLabelsOmit', $outcome->result->errorLabelsOmit, 'string[]');
}

$o->excludedLabels = $outcome->result->errorLabelsOmit;
}

return $o;
}

/** @throws InvalidArgumentException */
public static function fromTransactions(stdClass $operation)
{
Expand Down
10 changes: 0 additions & 10 deletions tests/SpecTests/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,6 @@ public static function fromRetryableReads(stdClass $operation)
return $o;
}

public static function fromRetryableWrites(stdClass $operation, stdClass $outcome)
{
$o = new self($operation);

$o->errorExpectation = ErrorExpectation::fromRetryableWrites($outcome);
$o->resultExpectation = ResultExpectation::fromRetryableWrites($outcome, $o->getResultAssertionType());

return $o;
}

public static function fromTransactions(stdClass $operation)
{
$o = new self($operation);
Expand Down
13 changes: 0 additions & 13 deletions tests/SpecTests/ResultExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,6 @@ public static function fromRetryableReads(stdClass $operation, $defaultAssertion
return new self($assertionType, $expectedValue);
}

public static function fromRetryableWrites(stdClass $outcome, $defaultAssertionType)
{
if (property_exists($outcome, 'result') && ! self::isErrorResult($outcome->result)) {
$assertionType = $outcome->result === null ? self::ASSERT_NULL : $defaultAssertionType;
$expectedValue = $outcome->result;
} else {
$assertionType = self::ASSERT_NOTHING;
$expectedValue = null;
}

return new self($assertionType, $expectedValue);
}

public static function fromTransactions(stdClass $operation, $defaultAssertionType)
{
if (property_exists($operation, 'result') && ! self::isErrorResult($operation->result)) {
Expand Down
60 changes: 0 additions & 60 deletions tests/SpecTests/RetryableWritesSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use stdClass;

use function basename;
use function file_get_contents;
use function glob;

/**
* Retryable writes spec tests.
Expand All @@ -24,61 +19,6 @@ class RetryableWritesSpecTest extends FunctionalTestCase
public const NOT_PRIMARY = 10107;
public const SHUTDOWN_IN_PROGRESS = 91;

/**
* Execute an individual test case from the specification.
*
* @dataProvider provideTests
* @param stdClass $test Individual "tests[]" document
* @param array $runOn Top-level "runOn" array with server requirements
* @param array $data Top-level "data" array to initialize collection
*/
public function testRetryableWrites(stdClass $test, ?array $runOn, array $data): void
{
if (isset($runOn)) {
$this->checkServerRequirements($runOn);
}

// Serverless uses a load balancer fronting a single proxy (PHPLIB-757)
$useMultipleMongoses = $this->isMongos() || ($this->isLoadBalanced() && ! $this->isServerless())
? ($test->useMultipleMongoses ?? false)
: false;

$context = Context::fromRetryableWrites($test, $this->getDatabaseName(), $this->getCollectionName(), $useMultipleMongoses);
$this->setContext($context);

$this->dropTestAndOutcomeCollections();
$this->insertDataFixtures($data);

if (isset($test->failPoint)) {
$this->configureFailPoint($test->failPoint);
}

Operation::fromRetryableWrites($test->operation, $test->outcome)->assert($this, $context);

if (isset($test->outcome->collection->data)) {
$this->assertOutcomeCollectionData($test->outcome->collection->data);
}
}

public function provideTests()
{
$testArgs = [];

foreach (glob(__DIR__ . '/retryable-writes/*.json') as $filename) {
$json = $this->decodeJson(file_get_contents($filename));
$group = basename($filename, '.json');
$runOn = $json->runOn ?? null;
$data = $json->data ?? [];

foreach ($json->tests as $test) {
$name = $group . ': ' . $test->description;
$testArgs[$name] = [$test, $runOn, $data];
}
}

return $testArgs;
}

/**
* Prose test 3: when encountering a NoWritesPerformed error after an error with a RetryableWriteError label
*/
Expand Down
Loading
Loading