|
30 | 30 | from pymongo.operations import IndexModel, InsertOne |
31 | 31 | from pymongo.read_concern import ReadConcern |
32 | 32 | from pymongo.write_concern import WriteConcern |
33 | | -from test import client_context, unittest |
| 33 | +from test import (client_context, |
| 34 | + IntegrationTest, |
| 35 | + unittest) |
34 | 36 | from test.utils import (EventListener, |
35 | 37 | disable_replication, |
36 | 38 | enable_replication, |
|
43 | 45 | os.path.dirname(os.path.realpath(__file__)), 'read_write_concern') |
44 | 46 |
|
45 | 47 |
|
46 | | -class TestReadWriteConcernSpec(unittest.TestCase): |
| 48 | +class TestReadWriteConcernSpec(IntegrationTest): |
47 | 49 |
|
48 | | - @client_context.require_connection |
49 | 50 | def test_omit_default_read_write_concern(self): |
50 | 51 | listener = EventListener() |
51 | 52 | # Client with default readConcern and writeConcern |
@@ -171,6 +172,44 @@ def test_raise_wtimeout(self): |
171 | 172 | self.assertWriteOpsRaise(WriteConcern(w=client_context.w, wtimeout=1), |
172 | 173 | WTimeoutError) |
173 | 174 |
|
| 175 | + @client_context.require_failCommand_fail_point |
| 176 | + def test_error_includes_errInfo(self): |
| 177 | + expected_wce = { |
| 178 | + "code": 100, |
| 179 | + "codeName": "UnsatisfiableWriteConcern", |
| 180 | + "errmsg": "Not enough data-bearing nodes", |
| 181 | + "errInfo": { |
| 182 | + "writeConcern": { |
| 183 | + "w": 2, |
| 184 | + "wtimeout": 0, |
| 185 | + "provenance": "clientSupplied" |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + cause_wce = { |
| 190 | + "configureFailPoint": "failCommand", |
| 191 | + "mode": {"times": 2}, |
| 192 | + "data": { |
| 193 | + "failCommands": ["insert"], |
| 194 | + "writeConcernError": expected_wce |
| 195 | + }, |
| 196 | + } |
| 197 | + with self.fail_point(cause_wce): |
| 198 | + # Write concern error on insert includes errInfo. |
| 199 | + with self.assertRaises(WriteConcernError) as ctx: |
| 200 | + self.db.test.insert_one({}) |
| 201 | + self.assertEqual(ctx.exception.details, expected_wce) |
| 202 | + |
| 203 | + # Test bulk_write as well. |
| 204 | + with self.assertRaises(BulkWriteError) as ctx: |
| 205 | + self.db.test.bulk_write([InsertOne({})]) |
| 206 | + expected_details = { |
| 207 | + 'writeErrors': [], |
| 208 | + 'writeConcernErrors': [expected_wce], |
| 209 | + 'nInserted': 1, 'nUpserted': 0, 'nMatched': 0, 'nModified': 0, |
| 210 | + 'nRemoved': 0, 'upserted': []} |
| 211 | + self.assertEqual(ctx.exception.details, expected_details) |
| 212 | + |
174 | 213 |
|
175 | 214 | def normalize_write_concern(concern): |
176 | 215 | result = {} |
|
0 commit comments