File: bug01065.phpt

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (58 lines) | stat: -rw-r--r-- 1,527 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--TEST--
Test for PHP-1065: Mongo driver is crashing during getmore
--SKIPIF--
<?php $needs = "2.6.0"; $needsOp = "ge"; ?>
<?php require_once "tests/utils/standalone.inc" ?>
<?php if (!MONGO_STREAMS) { echo "skip This test requires streams support"; } ?>
--FILE--
<?php

function log_getmore($server, $cursor_options)
{
    printf("%s\n", __METHOD__);
}

$ctx = stream_context_create(array(
    "mongodb" => array("log_getmore" => "log_getmore")
));

require_once "tests/utils/server.inc";

$host = MongoShellServer::getStandaloneInfo();
$mc = new MongoClient($host, array(), array("context" => $ctx));

$collection = $mc->selectCollection(dbname(), collname(__FILE__));
$collection->drop();

for ($i = 0; $i < 10; ++$i) {
    $collection->insert(array("x" => $i), array("w" => 0));
}

$cursor = $collection->find(array('$where' => 'sleep(1) || true'));
$cursor->batchSize(2);
$cursor->timeout(-1);

$document = $cursor->getNext();
printf("First document: x = %d\n", $document['x']);

$document = $cursor->getNext();
printf("Second document: x = %d\n", $document['x']);

$cursor->timeout(1);

try {
    $document = $cursor->getNext();
    // getmore should time out within 1ms, so this should never be reached
    echo "Expected getmore to time out but it did not!\n";
} catch(MongoCursorTimeoutException $e) {
    echo $e->getMessage(), "\n";
}
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
First document: x = 0
Second document: x = 1
log_getmore
%s:%d: Read timed out after reading 0 bytes, waited for 0.%d seconds
===DONE===