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

Commit 73babe4

Browse files
phaylonxdg
authored andcommitted
PERL-833 Test QueryResult destructor kills cursor
1 parent c10809c commit 73babe4

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

t/kill-cursor.t

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 server_version/;
21+
22+
skip_unless_mongod();
23+
24+
my @events;
25+
my $conn = build_client(monitoring_callback => sub {
26+
push @events, shift;
27+
});
28+
my $server_version = server_version($conn);
29+
my $testdb = get_test_db($conn);
30+
my $coll = $testdb->get_collection('test_collection');
31+
32+
for my $index (0..1000) {
33+
$coll->insert_one({
34+
type => 'testval',
35+
value => $index,
36+
});
37+
}
38+
39+
my $id;
40+
@events = ();
41+
do {
42+
my $results = $coll->query({ type => 'testval' });
43+
ok defined($results->next), 'fetch one document';
44+
$id = $results->result->_cursor_id;
45+
ok defined($id), 'cursor id';
46+
undef $results;
47+
};
48+
49+
my ($event) = grep {
50+
$_->{commandName} eq 'killCursors'
51+
&&
52+
$_->{type} eq 'command_succeeded'
53+
} @events;
54+
55+
ok defined($event), 'successful killcursors event';
56+
57+
if (defined $event and defined $id) {
58+
is $event->{reply}{ok}, 1,
59+
'reply ok';
60+
if ( $server_version >= v3.2.0 ) {
61+
ok( !grep { $_ eq $id } @{$event->{reply}{cursorsAlive}}, "cursor id not in alive list" );
62+
is_deeply( $event->{reply}{cursorsKilled}, [$id], 'cursor id in killed list' );
63+
}
64+
}
65+
66+
done_testing;

0 commit comments

Comments
 (0)