Skip to content

Commit ea68fc7

Browse files
committed
CDRIVER-838 simplify killCursors test
1 parent fcb6e62 commit ea68fc7

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

tests/test-mongoc-cursor.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -448,37 +448,33 @@ _test_client_kill_cursor (bool has_primary,
448448
{
449449
mock_rs_t *rs;
450450
mongoc_client_t *client;
451-
mongoc_collection_t *collection;
452451
mongoc_read_prefs_t *read_prefs;
453-
mongoc_cursor_t *cursor;
454-
const bson_t *doc;
452+
bson_error_t error;
455453
future_t *future;
456454
request_t *request;
457455

458-
/* maybe a primary, definitely a secondary and no arbiter */
459456
rs = mock_rs_with_autoismaster (wire_version_4 ? 4 : 3,
460-
has_primary,
461-
1,
462-
0);
457+
has_primary, /* maybe a primary*/
458+
1, /* definitely a secondary */
459+
0); /* no arbiter */
463460
mock_rs_run (rs);
464461
client = mongoc_client_new_from_uri (mock_rs_get_uri (rs));
465-
collection = mongoc_client_get_collection (client, "test", "test");
466462
read_prefs = mongoc_read_prefs_new (MONGOC_READ_SECONDARY);
467-
cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0,
468-
0, tmp_bson ("{}"), NULL, read_prefs);
469463

470-
future = future_cursor_next (cursor, &doc);
464+
/* make client open a connection - it won't open one to kill a cursor */
465+
future = future_client_command_simple (client, "admin",
466+
tmp_bson ("{'foo': 1}"),
467+
read_prefs, NULL, &error);
471468

472-
request = mock_rs_receives_request (rs);
473-
mock_rs_replies_to_find (request, MONGOC_QUERY_SLAVE_OK, 123, 1, "test.test",
474-
"{'a': 1}", wire_version_4);
469+
request = mock_rs_receives_command (rs, "admin",
470+
MONGOC_QUERY_SLAVE_OK, NULL);
475471

476-
assert (future_get_bool (future)); /* mongoc_cursor_next returned true */
477-
future_destroy (future);
472+
mock_rs_replies_simple (request, "{'ok': 1}");
473+
ASSERT_OR_PRINT (future_get_bool (future), error);
478474
request_destroy (request);
475+
future_destroy (future);
479476

480477
future = future_client_kill_cursor (client, 123);
481-
482478
mock_rs_set_request_timeout_msec (rs, 100);
483479

484480
/* we don't pass namespace so client always sends legacy OP_KILLCURSORS */
@@ -497,14 +493,8 @@ _test_client_kill_cursor (bool has_primary,
497493
}
498494

499495
future_wait (future); /* no return value */
500-
501496
future_destroy (future);
502-
503-
/* clean up memory, but don't send killCursors command */
504-
cursor->rpc.reply.cursor_id = 0;
505-
mongoc_cursor_destroy (cursor);
506497
mongoc_read_prefs_destroy (read_prefs);
507-
mongoc_collection_destroy (collection);
508498
mongoc_client_destroy (client);
509499
mock_rs_destroy (rs);
510500
}

0 commit comments

Comments
 (0)