Skip to content

Commit

Permalink
Extract helper method to create failpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Nov 24, 2023
1 parent b6f7647 commit e53cbb6
Showing 1 changed file with 20 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ public function testInsertErrorKeepsFailingInsertions(): void
$this->uow->persist($friendUser);

// Add failpoint to let the first insert command fail. This affects the ForumUser documents
$this->dm->getClient()->selectDatabase('admin')->command([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'errorCode' => 192, // FailPointEnabled
'failCommands' => ['insert'],
],
]);
$this->createFailpoint('insert');

try {
$this->uow->commit();
Expand Down Expand Up @@ -163,14 +156,7 @@ public function testUpsertErrorDropsFailingUpserts(): void
$user->username = 'alcaeus';
$this->uow->persist($user);

$this->dm->getClient()->selectDatabase('admin')->command([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'errorCode' => 192, // FailPointEnabled
'failCommands' => ['update'],
],
]);
$this->createFailpoint('update');

try {
$this->uow->commit();
Expand Down Expand Up @@ -198,14 +184,7 @@ public function testUpdateErrorKeepsFailingUpdate(): void
$user->username = 'jmikola';

// Make sure update command fails once
$this->dm->getClient()->selectDatabase('admin')->command([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'errorCode' => 192, // FailPointEnabled
'failCommands' => ['update'],
],
]);
$this->createFailpoint('update');

try {
$this->uow->commit();
Expand Down Expand Up @@ -235,14 +214,7 @@ public function testUpdateErrorWithNewEmbeddedDocumentKeepsFailingChangeset(): v
$address->setCity('Olching');
$user->setAddress($address);

$this->dm->getClient()->selectDatabase('admin')->command([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'errorCode' => 192, // FailPointEnabled
'failCommands' => ['update'],
],
]);
$this->createFailpoint('update');

try {
$this->uow->commit();
Expand Down Expand Up @@ -290,14 +262,7 @@ public function testUpdateErrorWithEmbeddedDocumentKeepsFailingChangeset(): void

$address->setCity('Munich');

$this->dm->getClient()->selectDatabase('admin')->command([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'errorCode' => 192, // FailPointEnabled
'failCommands' => ['update'],
],
]);
$this->createFailpoint('update');

try {
$this->uow->commit();
Expand Down Expand Up @@ -347,14 +312,7 @@ public function testUpdateErrorWithRemovedEmbeddedDocumentKeepsFailingChangeset(

$user->removeAddress();

$this->dm->getClient()->selectDatabase('admin')->command([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'errorCode' => 192, // FailPointEnabled
'failCommands' => ['update'],
],
]);
$this->createFailpoint('update');

try {
$this->uow->commit();
Expand Down Expand Up @@ -402,14 +360,7 @@ public function testDeleteErrorKeepsFailingDelete(): void
$this->uow->remove($user);

// Make sure delete command fails once
$this->dm->getClient()->selectDatabase('admin')->command([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'errorCode' => 192, // FailPointEnabled
'failCommands' => ['delete'],
],
]);
$this->createFailpoint('delete');

try {
$this->uow->commit();
Expand Down Expand Up @@ -441,14 +392,7 @@ public function testDeleteErrorWithEmbeddedDocumentKeepsChangeset(): void
$this->uow->remove($user);

// Make sure delete command fails once
$this->dm->getClient()->selectDatabase('admin')->command([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'errorCode' => 192, // FailPointEnabled
'failCommands' => ['delete'],
],
]);
$this->createFailpoint('delete');

try {
$this->uow->commit();
Expand Down Expand Up @@ -499,4 +443,16 @@ protected static function createTestDocumentManager(): DocumentManager

return DocumentManager::create($client, $config);
}

private function createFailpoint(string $commandName): void
{
$this->dm->getClient()->selectDatabase('admin')->command([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => [
'errorCode' => 192, // FailPointEnabled
'failCommands' => [$commandName],
],
]);
}
}

0 comments on commit e53cbb6

Please sign in to comment.