File: bug01085-002.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 (91 lines) | stat: -rw-r--r-- 2,321 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
--TEST--
Test for PHP-1085: w=0 returns unexpected exception on failure (socketTimeoutMS via method)
--SKIPIF--
<?php $needs = "2.6.0"; $needsOp = "ge"; ?>
<?php require_once "tests/utils/standalone.inc" ?>
--FILE--
<?php

require_once "tests/utils/server.inc";

function assertFalse($value) {
    if ( ! is_bool($value)) {
        printf("Expected boolean type but received %s\n", gettype($value));
        return;
    }

    if ($value !== false) {
        echo "Expected boolean false but received boolean true\n";
    }
}

$host = MongoShellServer::getStandaloneInfo();
$mc = new MongoClient($host);

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

echo "Testing insert() with w=0\n";

for ($i = 0; $i < 10; ++$i) {
    $retval = $collection->insert(
        array('x' => $i, 'y' => str_repeat('a', 4*1024*1024)),
        array('w' => 0, 'socketTimeoutMS' => 1)
    );
    assertFalse($retval);
}

echo "Testing update() with w=0\n";

$retval = $collection->update(
    array('$where' => 'sleep(1) || true'),
    array('$set' => array('y' => 1)),
    array('w' => 0, 'socketTimeoutMS' => 1)
);
assertFalse($retval);

echo "Testing remove() with w=0\n";

$retval = $collection->remove(
    array('$where' => 'sleep(1) && false'),
    array('w' => 0, 'socketTimeoutMS' => 1)
);
assertFalse($retval);

echo "Testing update() with w=1\n";

try {
    $collection->update(
        array('$where' => 'sleep(1) || true'),
        array('$set' => array('y' => 2)),
        array('w' => 1, 'socketTimeoutMS' => 1)
    );
    echo "Expected update() with w=1 to fail but it did not!\n";
} catch (MongoCursorTimeoutException $e) {
    echo "update() with w=1 timed out as expected\n";
}

echo "Testing remove() with w=1\n";

try {
    $collection->remove(
        array('$where' => 'sleep(1) && false'),
        array('w' => 1, 'socketTimeoutMS' => 1)
    );
    echo "Expected remove() with w=1 to fail but it did not!\n";
} catch (MongoCursorTimeoutException $e) {
    echo "remove() with w=1 timed out as expected\n";
}

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
Testing insert() with w=0
Testing update() with w=0
Testing remove() with w=0
Testing update() with w=1
update() with w=1 timed out as expected
Testing remove() with w=1
remove() with w=1 timed out as expected
===DONE===