Skip to content

remove batchSize and limit from isMaster #750

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 1 commit into from
Mar 9, 2021
Merged
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
20 changes: 13 additions & 7 deletions src/libmongoc/tests/test-mongoc-cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

typedef mongoc_cursor_t *(*make_cursor_fn) (mongoc_collection_t *);

static mongoc_cursor_t *
_make_cmd_deprecated_cursor (mongoc_collection_t *coll);

Comment on lines +47 to +49
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forward declared so we can reference it on lines 314 and 328.

static mongoc_cursor_t *
_make_array_cursor (mongoc_collection_t *coll);

Expand Down Expand Up @@ -150,16 +153,17 @@ _test_common_clone_w_concerns (void *ctx)
mongoc_read_concern_destroy (cursor->read_concern);
cursor->read_concern = read_concern;
/* don't call mongoc_cursor_next (), since the test may run against a version
* of MongoDB that doesn't support read/write concerns, and we are only
* interested in testing if the clone process works. */
* of MongoDB that doesn't support read/write concerns, and we are only
* interested in testing if the clone process works. */
Comment on lines +156 to +157
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

cloned = mongoc_cursor_clone (cursor);
/* test cloned read_concern. */
ASSERT (!mongoc_read_concern_is_default (cloned->read_concern));
ASSERT_CMPSTR (mongoc_read_concern_get_level (cloned->read_concern),
MONGOC_READ_CONCERN_LEVEL_LOCAL);
/* test cloned write_concern. */
ASSERT (mongoc_write_concern_get_wmajority (cloned->write_concern));
ASSERT (mongoc_write_concern_get_wtimeout_int64 (cloned->write_concern) == 1000);
ASSERT (mongoc_write_concern_get_wtimeout_int64 (cloned->write_concern) ==
1000);
Comment on lines +165 to +166
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

ASSERT (mongoc_write_concern_get_w (cloned->write_concern) ==
MONGOC_WRITE_CONCERN_W_MAJORITY);
/* check generated bson in cloned cursor. */
Expand Down Expand Up @@ -305,8 +309,9 @@ _test_common_opts (void *ctx)
BSON_ASSERT (mongoc_cursor_set_hint (cursor, sd->id));
ASSERT_CMPINT (mongoc_cursor_get_hint (cursor), ==, sd->id);

/* listDatabases prohibits limit and batchSize */
if ((make_cursor_fn) ctx != _make_array_cursor) {
/* listDatabases and isMaster prohibits limit and batchSize */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added "isMaster".

The issue was caused by the if guards changed below. _make_cmd_deprecated_cursor creates a cursor with an "isMaster" command. Since "isMaster" commands - like the "listDatabases" referenced here - do not accept a "batchSize" or "limit", the server errored with the message (paraphrased) "batchSize (or limit) option not found".

if ((make_cursor_fn) ctx != _make_array_cursor &&
(make_cursor_fn) ctx != _make_cmd_deprecated_cursor) {
mongoc_cursor_set_batch_size (cursor, 1);
ASSERT_CMPINT (mongoc_cursor_get_batch_size (cursor), ==, 1);
BSON_ASSERT (mongoc_cursor_set_limit (cursor, 2));
Expand All @@ -316,10 +321,11 @@ _test_common_opts (void *ctx)
mongoc_cursor_set_max_await_time_ms (cursor, 3);
ASSERT_CMPINT (mongoc_cursor_get_max_await_time_ms (cursor), ==, 3);
/* prime the cursor. */
BSON_ASSERT (mongoc_cursor_next (cursor, &doc));
ASSERT_OR_PRINT (mongoc_cursor_next (cursor, &doc), cursor->error);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This helped debug the issue. If this fails again, we'd definitely want the cursor's error message.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

/* options should be unchanged. */
ASSERT_CMPINT (mongoc_cursor_get_hint (cursor), ==, sd->id);
if ((make_cursor_fn) ctx != _make_array_cursor) {
if ((make_cursor_fn) ctx != _make_array_cursor &&
(make_cursor_fn) ctx != _make_cmd_deprecated_cursor) {
ASSERT_CMPINT (mongoc_cursor_get_batch_size (cursor), ==, 1);
ASSERT_CMPINT ((int) mongoc_cursor_get_limit (cursor), ==, 2);
/* limit cannot be set again. */
Expand Down