Skip to content

Commit a77ce75

Browse files
committed
Merge pull request #135
2 parents e4471af + 8dfe8d8 commit a77ce75

File tree

3 files changed

+122
-1
lines changed

3 files changed

+122
-1
lines changed

php_phongo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ bool phongo_stream_socket_check_closed(mongoc_stream_t *stream) /* {{{ */
916916
php_phongo_stream_socket *base_stream = (php_phongo_stream_socket *)stream;
917917
TSRMLS_FETCH_FROM_CTX(base_stream->tsrm_ls);
918918

919-
return PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(base_stream->stream, PHP_STREAM_OPTION_CHECK_LIVENESS, 0, NULL);
919+
return PHP_STREAM_OPTION_RETURN_OK != php_stream_set_option(base_stream->stream, PHP_STREAM_OPTION_CHECK_LIVENESS, 0, NULL);
920920
} /* }}} */
921921

922922
mongoc_stream_t* phongo_stream_get_base_stream(mongoc_stream_t *stream) /* {{{ */

tests/standalone/bug0487-001.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
PHPC-487: check_closed stream handler should not report open socket as closed
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; SLOW(); ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$m = new MongoDB\Driver\Manager(STANDALONE);
10+
11+
$bulk = new MongoDB\Driver\BulkWrite;
12+
$bulk->insert(['x' => 1]);
13+
$wr = $m->executeBulkWrite(NS, $bulk);
14+
var_dump($wr->getInsertedCount());
15+
16+
sleep(1);
17+
18+
$bulk = new MongoDB\Driver\BulkWrite;
19+
$bulk->insert(['x' => 1]);
20+
$wr = $m->executeBulkWrite(NS, $bulk);
21+
var_dump($wr->getInsertedCount());
22+
23+
?>
24+
===DONE===
25+
<?php exit(0); ?>
26+
--EXPECT--
27+
int(1)
28+
int(1)
29+
===DONE===

tests/standalone/bug0487-002.phpt

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
--TEST--
2+
PHPC-487: check_closed stream handler should report closed socket as closed
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; SLOW(); ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
function mo_delete($id) {
10+
$url = getMOUri() . $id;
11+
12+
$opts = array("http" =>
13+
array(
14+
"method" => "DELETE",
15+
"timeout" => 60,
16+
"header" => "Accept: application/json\r\n" .
17+
"Content-type: application/x-www-form-urlencoded",
18+
"ignore_errors" => true,
19+
),
20+
);
21+
22+
$context = stream_context_create($opts);
23+
$out = file_get_contents($url, false, $context);
24+
}
25+
26+
function mo_post($url, $body) {
27+
global $KILLLIST;
28+
29+
$url = getMOUri() . $url;
30+
31+
$opts = array("http" =>
32+
array(
33+
"method" => "POST",
34+
"timeout" => 60,
35+
"header" => "Accept: application/json\r\n" .
36+
"Content-type: application/x-www-form-urlencoded",
37+
"content" => json_encode($body),
38+
"ignore_errors" => true,
39+
),
40+
);
41+
42+
$context = stream_context_create($opts);
43+
$out = file_get_contents($url, false, $context);
44+
$array = json_decode($out, true);
45+
if ($array && !empty($array["mongodb_uri"])) {
46+
$KILLLIST[] = $array["id"];
47+
return $array["mongodb_uri"];
48+
}
49+
}
50+
$KILLLIST = array();
51+
52+
$dsn = mo_post("/servers", [
53+
'id' => 'serverA',
54+
'name' => 'mongod',
55+
]);
56+
57+
$m = new MongoDB\Driver\Manager($dsn);
58+
59+
$bulk = new MongoDB\Driver\BulkWrite;
60+
$bulk->insert(['x' => 1]);
61+
$wr = $m->executeBulkWrite(NS, $bulk);
62+
var_dump($wr->getInsertedCount());
63+
64+
mo_post("/servers/serverA", ['action' => 'stop']);
65+
66+
echo throws(function() use ($m) {
67+
$bulk = new MongoDB\Driver\BulkWrite;
68+
$bulk->insert(['x' => 1]);
69+
$wr = $m->executeBulkWrite(NS, $bulk);
70+
var_dump($wr->getInsertedCount());
71+
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
72+
73+
mo_post("/servers/serverA", ['action' => 'restart']);
74+
75+
$bulk = new MongoDB\Driver\BulkWrite;
76+
$bulk->insert(['x' => 1]);
77+
$wr = $m->executeBulkWrite(NS, $bulk);
78+
var_dump($wr->getInsertedCount());
79+
80+
foreach($KILLLIST as $id) {
81+
mo_delete("/servers/$id");
82+
}
83+
84+
?>
85+
===DONE===
86+
<?php exit(0); ?>
87+
--EXPECTF--
88+
int(1)
89+
OK: Got MongoDB\Driver\Exception\RuntimeException
90+
Failed to read 4 bytes from socket within 300000 milliseconds.
91+
int(1)
92+
===DONE===

0 commit comments

Comments
 (0)