Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit df9d467

Browse files
committed
Test to ensure cursor/query result drop kills cursor
1 parent 001832e commit df9d467

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

t/kill-cursor.t

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2018 - present MongoDB, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
use strict;
16+
use warnings;
17+
use Test::More;
18+
19+
use lib "t/lib";
20+
use MongoDBTest qw/skip_unless_mongod build_client get_test_db/;
21+
22+
skip_unless_mongod();
23+
24+
my @events;
25+
my $conn = build_client(monitoring_callback => sub {
26+
push @events, shift;
27+
});
28+
my $testdb = get_test_db($conn);
29+
my $coll = $testdb->get_collection('test_collection');
30+
31+
for my $index (0..1000) {
32+
$coll->insert_one({
33+
type => 'testval',
34+
value => $index,
35+
});
36+
}
37+
38+
my $id;
39+
@events = ();
40+
do {
41+
my $results = $coll->query({ type => 'testval' });
42+
ok defined($results->next), 'fetch one document';
43+
$id = $results->result->_cursor_id;
44+
ok defined($id), 'cursor id';
45+
undef $results;
46+
};
47+
48+
my ($event) = grep {
49+
$_->{commandName} eq 'killCursors'
50+
&&
51+
$_->{type} eq 'command_succeeded'
52+
} @events;
53+
54+
ok defined($event), 'successful killcursors event';
55+
56+
if (defined $event and defined $id) {
57+
is $event->{reply}{ok}, 1,
58+
'reply ok';
59+
is_deeply $event->{reply}{cursorsAlive}, [],
60+
'reply cursors alive';
61+
is_deeply $event->{reply}{cursorsNotFound}, [],
62+
'reply cursors not found';
63+
is_deeply $event->{reply}{cursorsUnknown}, [],
64+
'reply cursors unknown';
65+
is_deeply $event->{reply}{cursorsKilled}, [$id],
66+
'reply cursors killed';
67+
}
68+
69+
done_testing;

0 commit comments

Comments
 (0)