Skip to content

Commit e2e9d89

Browse files
committed
PHPC-225: Test Cursor::isDead() and kill on destruct
Testing for kill on destruct is based on PyMongo (see: https://jira.mongodb.org/browse/SERVER-5816?focusedCommentId=201245).
1 parent 66193e8 commit e2e9d89

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
MongoDB\Driver\Cursor destruct should kill a live cursor
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE) ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
function getNumOpenCursors(MongoDB\Driver\Manager $manager)
10+
{
11+
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(array('serverStatus' => 1)));
12+
$result = current($cursor->toArray());
13+
return $result['cursors']->totalOpen;
14+
}
15+
16+
$manager = new MongoDB\Driver\Manager(STANDALONE);
17+
18+
$manager->executeInsert(NS, array('_id' => 1));
19+
$manager->executeInsert(NS, array('_id' => 2));
20+
$manager->executeInsert(NS, array('_id' => 3));
21+
22+
$numOpenCursorsBeforeQuery = getNumOpenCursors($manager);
23+
24+
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query(array(), array('batchSize' => 2)));
25+
26+
var_dump($cursor->isDead());
27+
var_dump(getNumOpenCursors($manager) == $numOpenCursorsBeforeQuery + 1);
28+
29+
unset($cursor);
30+
31+
var_dump(getNumOpenCursors($manager) == $numOpenCursorsBeforeQuery);
32+
33+
?>
34+
===DONE===
35+
<?php exit(0); ?>
36+
--EXPECT--
37+
bool(false)
38+
bool(true)
39+
bool(true)
40+
===DONE===
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
MongoDB\Driver\Cursor::isDead()
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE) ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$manager = new MongoDB\Driver\Manager(STANDALONE);
10+
11+
$manager->executeInsert(NS, array('_id' => 1));
12+
$manager->executeInsert(NS, array('_id' => 2));
13+
$manager->executeInsert(NS, array('_id' => 3));
14+
15+
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query(array(), array('batchSize' => 2)));
16+
17+
foreach ($cursor as $_) {
18+
var_dump($cursor->isDead());
19+
}
20+
21+
?>
22+
===DONE===
23+
<?php exit(0); ?>
24+
--EXPECT--
25+
bool(false)
26+
bool(false)
27+
bool(true)
28+
===DONE===

0 commit comments

Comments
 (0)