Skip to content

Commit 2bea375

Browse files
jmikolaajdavis
authored andcommitted
CDRIVER-775: Set wtimeoutms for all replica acknowledged write concerns
1 parent d15b0e4 commit 2bea375

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/mongoc/mongoc-uri.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,9 @@ _mongoc_uri_build_write_concern (mongoc_uri_t *uri) /* IN */
890890
default:
891891
if (value > 0) {
892892
mongoc_write_concern_set_w (write_concern, value);
893+
if (value > 1) {
894+
mongoc_write_concern_set_wtimeout (write_concern, wtimeoutms);
895+
}
893896
break;
894897
}
895898
MONGOC_WARNING ("Unsupported w value [w=%d].", value);
@@ -902,6 +905,7 @@ _mongoc_uri_build_write_concern (mongoc_uri_t *uri) /* IN */
902905
mongoc_write_concern_set_wmajority (write_concern, wtimeoutms);
903906
} else {
904907
mongoc_write_concern_set_wtag (write_concern, str);
908+
mongoc_write_concern_set_wtimeout (write_concern, wtimeoutms);
905909
}
906910
} else {
907911
BSON_ASSERT (false);

tests/test-mongoc-uri.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ typedef struct
649649
bool parses;
650650
int32_t w;
651651
const char *wtag;
652+
int32_t wtimeoutms;
652653
} write_concern_test;
653654

654655

@@ -676,6 +677,9 @@ test_mongoc_uri_write_concern (void)
676677
{ "mongodb://localhost/?w=0&journal=true", false, MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED },
677678
{ "mongodb://localhost/?w=-1&journal=true", false, MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED },
678679
{ "mongodb://localhost/?w=1&journal=true", true, 1 },
680+
{ "mongodb://localhost/?w=2&wtimeoutms=1000", true, 2, NULL, 1000 },
681+
{ "mongodb://localhost/?w=majority&wtimeoutms=1000", true, MONGOC_WRITE_CONCERN_W_MAJORITY, NULL, 1000 },
682+
{ "mongodb://localhost/?w=mytag&wtimeoutms=1000", true, MONGOC_WRITE_CONCERN_W_TAG, "mytag", 1000 },
679683
{ NULL }
680684
};
681685

@@ -703,6 +707,10 @@ test_mongoc_uri_write_concern (void)
703707
assert (0 == strcmp (t->wtag, mongoc_write_concern_get_wtag (wr)));
704708
}
705709

710+
if (t->wtimeoutms) {
711+
assert (t->wtimeoutms == mongoc_write_concern_get_wtimeout (wr));
712+
}
713+
706714
mongoc_uri_destroy (uri);
707715
}
708716
}

0 commit comments

Comments
 (0)