Skip to content

Commit 84635b3

Browse files
committed
CDRIVER-3575 prose test for writeconcernerr
1 parent 3927ae8 commit 84635b3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/libmongoc/tests/test-mongoc-read-write-concern.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,44 @@ test_rw_concern_document (bson_t *scenario)
230230
}
231231
}
232232

233+
static void
234+
errinfo_propagated (void *unused)
235+
{
236+
mongoc_client_t *client;
237+
bool ret;
238+
bson_error_t error;
239+
mongoc_collection_t *coll;
240+
bson_t reply;
241+
const char *failpoint =
242+
"{'configureFailPoint':'failCommand','data':{'failCommands':['insert'],'"
243+
"writeConcernError':{'code':100,'codeName':'UnsatisfiableWriteConcern','"
244+
"errmsg':'Not enough data-bearing "
245+
"nodes','errInfo':{'writeConcern':{'w':2,'wtimeout':0,'provenance':'"
246+
"clientSupplied'}}}},'mode':{'times':1}}";
247+
248+
249+
client = test_framework_client_new ();
250+
ret = mongoc_client_command_simple (client,
251+
"admin",
252+
tmp_bson (failpoint),
253+
NULL /* read prefs */,
254+
NULL /* reply */,
255+
&error);
256+
ASSERT_OR_PRINT (ret, error);
257+
coll = get_test_collection (client, "rwc_errinfo");
258+
ret = mongoc_collection_insert_one (
259+
coll, tmp_bson ("{'x': 1}"), NULL /* opts */, &reply, &error);
260+
BSON_ASSERT (!ret);
261+
assert_match_bson (&reply,
262+
tmp_bson ("{'writeConcernErrors': [ { 'errInfo' : { "
263+
"'writeConcern' : { 'w' : 2, 'wtimeout' : 0, "
264+
"'provenance' : 'clientSupplied' } } } ] }"),
265+
false);
266+
267+
bson_destroy (&reply);
268+
mongoc_collection_destroy (coll);
269+
mongoc_client_destroy (client);
270+
}
233271

234272
void
235273
test_read_write_concern_install (TestSuite *suite)
@@ -243,4 +281,11 @@ test_read_write_concern_install (TestSuite *suite)
243281
test_framework_resolve_path (JSON_DIR "/read_write_concern/document",
244282
resolved);
245283
install_json_test_suite (suite, resolved, &test_rw_concern_document);
284+
TestSuite_AddFull (suite,
285+
"/read_write_concern/errinfo_propagated",
286+
errinfo_propagated,
287+
NULL /* dtor */,
288+
NULL /* ctx */,
289+
test_framework_skip_if_max_wire_version_less_than_7,
290+
test_framework_skip_if_no_failpoint);
246291
}

0 commit comments

Comments
 (0)