Skip to content

Remove unknown fields in isMaster cmd #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/libmongoc/tests/test-mongoc-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ test_large_ismaster_helper (mongoc_async_cmd_t *acmd,
}
ASSERT_CMPINT (result, ==, MONGOC_ASYNC_CMD_SUCCESS);

ASSERT_HAS_FIELD(bson, "ismaster");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this here since previously we didn't print the BSON object if the line below failed.

BSON_ASSERT (bson_iter_init_find (&iter, bson, "ismaster"));
BSON_ASSERT (BSON_ITER_HOLDS_BOOL (&iter) && bson_iter_bool (&iter));
}
Expand All @@ -244,22 +245,21 @@ test_large_ismaster (void *ctx)
{
mongoc_async_t *async;
mongoc_stream_t *sock_stream;
int i = 0;
bson_t q = BSON_INITIALIZER;
char buf[1024 * 1024];

#ifdef MONGOC_ENABLE_SSL
mongoc_ssl_opt_t ssl_opts;
#endif

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

sock_stream = get_localhost_stream (test_framework_get_port ());

Expand Down
16 changes: 12 additions & 4 deletions src/libmongoc/tests/test-mongoc-topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -2081,10 +2081,18 @@ test_request_scan_on_error ()
true /* should_mark_unknown */,
"node is recovering");
/* write concern errors are also checked. */
TEST_BOTH ("{'ok': 1, 'writeConcernError': { 'errmsg': 'not master' }}",
true, /* should_scan */
true /* should_mark_unknown */,
"not master");
_test_request_scan_on_error (
1,
"{'ok': 1, 'writeConcernError': { 'errmsg': 'not master' }}",
1,
1,
"not master");
_test_request_scan_on_error (
0,
"{'ok': 1, 'writeConcernError': { 'errmsg': 'not master' }}",
1,
1,
"not master");
Comment on lines +2084 to +2095
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format

TEST_BOTH ("{'ok': 1, 'writeConcernError': { 'code': 10107 }}",
true, /* should_scan */
true /* should_mark_unknown */,
Expand Down