4
#include <sys/socket.h>
5
#include "libmongo-private.h"
8
test_mongo_sync_cmd_kill_cursors_net_secondary (void)
11
mongo_sync_connection *conn;
14
mongo_reply_packet_header rh;
17
skip (!config.secondary_host, 1,
18
"Secondary server not configured");
20
conn = mongo_sync_connect (config.secondary_host, config.secondary_port,
23
bson_append_string (b, "test-name", __FILE__, -1);
26
p = mongo_sync_cmd_query (conn, config.ns,
27
MONGO_WIRE_FLAG_QUERY_NO_CURSOR_TIMEOUT,
30
mongo_wire_reply_packet_get_header (p, &rh);
32
mongo_wire_packet_free (p);
34
ok (mongo_sync_cmd_kill_cursors (conn, 1, cid) == TRUE,
35
"mongo_sync_cmd_kill_cursors() works on secondary too");
37
mongo_sync_disconnect (conn);
43
test_mongo_sync_cmd_kill_cursors_net (void)
46
mongo_sync_connection *conn;
49
mongo_reply_packet_header rh;
52
begin_network_tests (3);
54
conn = mongo_sync_connect (config.primary_host, config.primary_port, TRUE);
55
mongo_sync_conn_set_auto_reconnect (conn, TRUE);
58
for (i = 0; i < 40; i++)
61
bson_append_string (b, "test-name", __FILE__, -1);
62
bson_append_int32 (b, "seq", i);
65
mongo_sync_cmd_insert (conn, config.ns, b, NULL);
70
bson_append_string (b, "test-name", __FILE__, -1);
73
p = mongo_sync_cmd_query (conn, config.ns,
74
MONGO_WIRE_FLAG_QUERY_NO_CURSOR_TIMEOUT,
76
mongo_wire_reply_packet_get_header (p, &rh);
78
mongo_wire_packet_free (p);
80
ok (mongo_sync_cmd_kill_cursors (conn, 1, cid) == TRUE,
81
"mongo_sync_kill_cursors() works");
83
p = mongo_sync_cmd_query (conn, config.ns,
84
MONGO_WIRE_FLAG_QUERY_NO_CURSOR_TIMEOUT,
87
mongo_wire_reply_packet_get_header (p, &rh);
89
mongo_wire_packet_free (p);
90
shutdown (conn->super.fd, SHUT_RDWR);
93
ok (mongo_sync_cmd_kill_cursors (conn, 1, cid) == TRUE,
94
"mongo_sync_cmd_kill_cursors() automatically reconnects");
96
mongo_sync_disconnect (conn);
98
test_mongo_sync_cmd_kill_cursors_net_secondary ();
100
end_network_tests ();
104
test_mongo_sync_cmd_kill_cursors (void)
106
mongo_sync_connection *c;
108
c = test_make_fake_sync_conn (-1, FALSE);
110
ok (mongo_sync_cmd_kill_cursors (NULL, 1, (gint64)1234) == FALSE,
111
"mongo_sync_cmd_kill_cursors() fails with a NULL connection");
112
ok (mongo_sync_cmd_kill_cursors (c, 0, (gint64)1234) == FALSE,
113
"mongo_sync_cmd_kill_cursors() fails with a negative number of cursors");
115
ok (mongo_sync_cmd_kill_cursors (c, 1, (gint64)1234) == FALSE,
116
"mongo_sync_cmd_kill_cursors() fails with a bogus FD");
118
mongo_sync_disconnect (c);
120
test_mongo_sync_cmd_kill_cursors_net ();
123
RUN_TEST (6, mongo_sync_cmd_kill_cursors);