Skip to content

Commit 26321ea

Browse files
authored
Remove unknown fields in isMaster cmd (#755)
1 parent 27f1d6e commit 26321ea

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/libmongoc/tests/test-mongoc-async.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ test_large_ismaster_helper (mongoc_async_cmd_t *acmd,
235235
}
236236
ASSERT_CMPINT (result, ==, MONGOC_ASYNC_CMD_SUCCESS);
237237

238+
ASSERT_HAS_FIELD(bson, "ismaster");
238239
BSON_ASSERT (bson_iter_init_find (&iter, bson, "ismaster"));
239240
BSON_ASSERT (BSON_ITER_HOLDS_BOOL (&iter) && bson_iter_bool (&iter));
240241
}
@@ -244,22 +245,21 @@ test_large_ismaster (void *ctx)
244245
{
245246
mongoc_async_t *async;
246247
mongoc_stream_t *sock_stream;
247-
int i = 0;
248248
bson_t q = BSON_INITIALIZER;
249+
char buf[1024 * 1024];
249250

250251
#ifdef MONGOC_ENABLE_SSL
251252
mongoc_ssl_opt_t ssl_opts;
252253
#endif
253254

254-
/* Inflate the size of the isMaster message with other fields to ~1MB.
255-
* mongod should ignore them, but this tests that CDRIVER-2483 is fixed.
255+
/* Inflate the size of the isMaster message to ~1MB. This tests that
256+
* CDRIVER-2483 is fixed. Because mongod 4.9+ errors on unknown and duplicate
257+
* fields (see SERVER-53150) we add a ~1MB comment.
256258
*/
257259
BSON_ASSERT (bson_append_int32 (&q, "isMaster", 8, 1));
258-
while (q.len < 1024 * 1024) {
259-
char buf[11];
260-
bson_snprintf (buf, sizeof (buf), "key_%06d", i++);
261-
BSON_APPEND_INT32 (&q, buf, 0);
262-
}
260+
/* size of comment string = (1024 * 1024) - 1 (for null terminator) */
261+
bson_snprintf(buf, sizeof (buf), "%01048575d", 0);
262+
BSON_APPEND_UTF8(&q, "comment", buf);
263263

264264
sock_stream = get_localhost_stream (test_framework_get_port ());
265265

src/libmongoc/tests/test-mongoc-topology.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,10 +2081,18 @@ test_request_scan_on_error ()
20812081
true /* should_mark_unknown */,
20822082
"node is recovering");
20832083
/* write concern errors are also checked. */
2084-
TEST_BOTH ("{'ok': 1, 'writeConcernError': { 'errmsg': 'not master' }}",
2085-
true, /* should_scan */
2086-
true /* should_mark_unknown */,
2087-
"not master");
2084+
_test_request_scan_on_error (
2085+
1,
2086+
"{'ok': 1, 'writeConcernError': { 'errmsg': 'not master' }}",
2087+
1,
2088+
1,
2089+
"not master");
2090+
_test_request_scan_on_error (
2091+
0,
2092+
"{'ok': 1, 'writeConcernError': { 'errmsg': 'not master' }}",
2093+
1,
2094+
1,
2095+
"not master");
20882096
TEST_BOTH ("{'ok': 1, 'writeConcernError': { 'code': 10107 }}",
20892097
true, /* should_scan */
20902098
true /* should_mark_unknown */,

0 commit comments

Comments
 (0)