|
| 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