|
2 | 2 |
|
3 | 3 | namespace MongoDB\Tests\SpecTests;
|
4 | 4 |
|
| 5 | +use MongoDB\Client; |
| 6 | +use MongoDB\Driver\Exception\BulkWriteException; |
5 | 7 | use stdClass;
|
6 | 8 | use function basename;
|
7 | 9 | use function file_get_contents;
|
@@ -111,4 +113,44 @@ public function provideTests()
|
111 | 113 |
|
112 | 114 | return $testArgs;
|
113 | 115 | }
|
| 116 | + |
| 117 | + /** |
| 118 | + * Prose test 1: "errInfo" is propagated |
| 119 | + */ |
| 120 | + public function testErrInfoIsPropagated() |
| 121 | + { |
| 122 | + $runOn = [(object) ['minServerVersion' => '4.0.0']]; |
| 123 | + $this->checkServerRequirements($runOn); |
| 124 | + |
| 125 | + $errInfo = (object) [ |
| 126 | + 'writeConcern' => (object) [ |
| 127 | + 'w' => 2, |
| 128 | + 'wtimeout' => 0, |
| 129 | + 'provenance' => 'clientSupplied', |
| 130 | + ], |
| 131 | + ]; |
| 132 | + |
| 133 | + $this->configureFailPoint([ |
| 134 | + 'configureFailPoint' => 'failCommand', |
| 135 | + 'mode' => ['times' => 1], |
| 136 | + 'data' => [ |
| 137 | + 'failCommands' => ['insert'], |
| 138 | + 'writeConcernError' => [ |
| 139 | + 'code' => 100, |
| 140 | + 'codeName' => 'UnsatisfiableWriteConcern', |
| 141 | + 'errmsg' => 'Not enough data-bearing nodes', |
| 142 | + 'errInfo' => $errInfo, |
| 143 | + ], |
| 144 | + ], |
| 145 | + ]); |
| 146 | + |
| 147 | + $client = new Client(static::getUri()); |
| 148 | + |
| 149 | + try { |
| 150 | + $client->selectCollection($this->getDatabaseName(), $this->getCollectionName())->insertOne(['fail' => 1]); |
| 151 | + $this->fail('Expected insert command to fail'); |
| 152 | + } catch (BulkWriteException $e) { |
| 153 | + self::assertEquals($errInfo, $e->getWriteResult()->getWriteConcernError()->getInfo()); |
| 154 | + } |
| 155 | + } |
114 | 156 | }
|
0 commit comments