Skip to content

Commit 490403a

Browse files
committed
Merge pull request #83
2 parents 300300d + 69bff6b commit 490403a

17 files changed

+92
-42
lines changed

scripts/convert-mo-tests.php

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function mo_delete($id) {
1414
$opts = array("http" =>
1515
array(
1616
"method" => "DELETE",
17-
"timeout" => 30,
17+
"timeout" => 60,
1818
"header" => "Accept: application/json\r\n" .
1919
"Content-type: application/x-www-form-urlencoded",
2020
"ignore_errors" => true,
@@ -32,7 +32,7 @@ function mo_post($url, $body) {
3232
$opts = array("http" =>
3333
array(
3434
"method" => "POST",
35-
"timeout" => 30,
35+
"timeout" => 60,
3636
"header" => "Accept: application/json\r\n" .
3737
"Content-type: application/x-www-form-urlencoded",
3838
"content" => json_encode($body),
@@ -151,6 +151,9 @@ function phase($phase, &$output) {
151151
if (isset($phase["MOOperation"])) {
152152
return MOOperation($phase["MOOperation"], $output);
153153
}
154+
if (isset($phase["clientHosts"])) {
155+
return clientHosts($phase["clientHosts"], $output);
156+
}
154157
if (isset($phase["clientOperation"])) {
155158
return clientOperation($phase["clientOperation"], $output);
156159
}
@@ -166,11 +169,62 @@ function MOOperation($phase, &$output) {
166169
case "post":
167170
return 'mo_post("' . $phase["uri"] . '", ' . var_export($phase["payload"], true) . ');';
168171

172+
case "delete":
173+
return 'mo_delete("' . $phase["uri"] . '");';
174+
169175
default:
170-
throw UnexpectedValueException("Don't know the method $method");
176+
throw new UnexpectedValueException("Don't know the method $method");
171177
}
172178
}
173179

180+
function clientHosts($hosts, &$output) {
181+
$output = array();
182+
183+
$retval = <<< CODE
184+
\$clientHosts = array();
185+
186+
CODE;
187+
188+
if (!empty($hosts['primary'])) {
189+
$primary = var_export($hosts['primary'], true);
190+
191+
$retval .= <<< CODE
192+
\$found = array_filter(\$manager->getServers(), function(\$server) {
193+
return \$server->getHost() == $primary && \$server->getType() == MongoDB\\Driver\\SERVERTYPE_RS_PRIMARY;
194+
});
195+
if (count(\$found) == 1) {
196+
\$clientHosts['primary'] = $primary;
197+
}
198+
199+
CODE;
200+
$output['primary'] = $hosts['primary'];
201+
}
202+
203+
if (!empty($hosts['secondaries'])) {
204+
foreach ($hosts['secondaries'] as $secondaryHost) {
205+
$secondary = var_export($secondaryHost, true);
206+
207+
$retval .= <<< CODE
208+
209+
\$found = array_filter(\$manager->getServers(), function(\$server) {
210+
return \$server->getHost() == $secondary && \$server->getType() == MongoDB\\Driver\\SERVERTYPE_RS_SECONDARY;
211+
});
212+
if (count(\$found) == 1) {
213+
\$clientHosts['secondaries'][] = $secondary;
214+
}
215+
216+
CODE;
217+
$output['secondaries'][] = $secondaryHost;
218+
}
219+
}
220+
221+
$retval .= <<< CODE
222+
var_dump(\$clientHosts);
223+
CODE;
224+
225+
return $retval;
226+
}
227+
174228
function clientOperation($phase, &$output) {
175229
switch($phase["operation"]) {
176230
case "insertOne":
@@ -201,7 +255,7 @@ function clientOperation($phase, &$output) {
201255
return $retval;
202256
break;
203257

204-
case "findOne":
258+
case "find":
205259
$output = $phase["outcome"];
206260
if (!$output["ok"]) {
207261
$output["errmsg"] = "%s";
@@ -210,11 +264,7 @@ function clientOperation($phase, &$output) {
210264
try {
211265
\$query = new MongoDB\\Driver\\Query(array());
212266
\$result = \$manager->executeQuery("databaseName.collectionName", \$query)->toArray();
213-
if (\$result) {
214-
var_dump(array("ok" => 1));
215-
} else {
216-
var_dump(array("ok" => 0, "errmsg" => "Empty result"));
217-
}
267+
var_dump(array("ok" => 1));
218268
} catch(Exception \$e) {
219269
var_dump(array("ok" => 0, "errmsg" => get_class(\$e) . ": " . \$e->getMessage()));
220270
}

tests/cluster/rs/connection/read/primary-available.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function mo_delete($id) {
1111
$opts = array("http" =>
1212
array(
1313
"method" => "DELETE",
14-
"timeout" => 30,
14+
"timeout" => 60,
1515
"header" => "Accept: application/json\r\n" .
1616
"Content-type: application/x-www-form-urlencoded",
1717
"ignore_errors" => true,
@@ -29,7 +29,7 @@ function mo_post($url, $body) {
2929
$opts = array("http" =>
3030
array(
3131
"method" => "POST",
32-
"timeout" => 30,
32+
"timeout" => 60,
3333
"header" => "Accept: application/json\r\n" .
3434
"Content-type: application/x-www-form-urlencoded",
3535
"content" => json_encode($body),

tests/cluster/rs/connection/read/primary-not-available.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function mo_delete($id) {
1111
$opts = array("http" =>
1212
array(
1313
"method" => "DELETE",
14-
"timeout" => 30,
14+
"timeout" => 60,
1515
"header" => "Accept: application/json\r\n" .
1616
"Content-type: application/x-www-form-urlencoded",
1717
"ignore_errors" => true,
@@ -29,7 +29,7 @@ function mo_post($url, $body) {
2929
$opts = array("http" =>
3030
array(
3131
"method" => "POST",
32-
"timeout" => 30,
32+
"timeout" => 60,
3333
"header" => "Accept: application/json\r\n" .
3434
"Content-type: application/x-www-form-urlencoded",
3535
"content" => json_encode($body),

tests/cluster/rs/connection/write/primary-available.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function mo_delete($id) {
1111
$opts = array("http" =>
1212
array(
1313
"method" => "DELETE",
14-
"timeout" => 30,
14+
"timeout" => 60,
1515
"header" => "Accept: application/json\r\n" .
1616
"Content-type: application/x-www-form-urlencoded",
1717
"ignore_errors" => true,
@@ -29,7 +29,7 @@ function mo_post($url, $body) {
2929
$opts = array("http" =>
3030
array(
3131
"method" => "POST",
32-
"timeout" => 30,
32+
"timeout" => 60,
3333
"header" => "Accept: application/json\r\n" .
3434
"Content-type: application/x-www-form-urlencoded",
3535
"content" => json_encode($body),

tests/cluster/rs/connection/write/primary-not-available.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function mo_delete($id) {
1111
$opts = array("http" =>
1212
array(
1313
"method" => "DELETE",
14-
"timeout" => 30,
14+
"timeout" => 60,
1515
"header" => "Accept: application/json\r\n" .
1616
"Content-type: application/x-www-form-urlencoded",
1717
"ignore_errors" => true,
@@ -29,7 +29,7 @@ function mo_post($url, $body) {
2929
$opts = array("http" =>
3030
array(
3131
"method" => "POST",
32-
"timeout" => 30,
32+
"timeout" => 60,
3333
"header" => "Accept: application/json\r\n" .
3434
"Content-type: application/x-www-form-urlencoded",
3535
"content" => json_encode($body),

tests/cluster/rs/connection/write/primary-restarted.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function mo_delete($id) {
1111
$opts = array("http" =>
1212
array(
1313
"method" => "DELETE",
14-
"timeout" => 30,
14+
"timeout" => 60,
1515
"header" => "Accept: application/json\r\n" .
1616
"Content-type: application/x-www-form-urlencoded",
1717
"ignore_errors" => true,
@@ -29,7 +29,7 @@ function mo_post($url, $body) {
2929
$opts = array("http" =>
3030
array(
3131
"method" => "POST",
32-
"timeout" => 30,
32+
"timeout" => 60,
3333
"header" => "Accept: application/json\r\n" .
3434
"Content-type: application/x-www-form-urlencoded",
3535
"content" => json_encode($body),

tests/cluster/rs/discovery/remove-all-add-members.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function mo_delete($id) {
1111
$opts = array("http" =>
1212
array(
1313
"method" => "DELETE",
14-
"timeout" => 30,
14+
"timeout" => 60,
1515
"header" => "Accept: application/json\r\n" .
1616
"Content-type: application/x-www-form-urlencoded",
1717
"ignore_errors" => true,
@@ -29,7 +29,7 @@ function mo_post($url, $body) {
2929
$opts = array("http" =>
3030
array(
3131
"method" => "POST",
32-
"timeout" => 30,
32+
"timeout" => 60,
3333
"header" => "Accept: application/json\r\n" .
3434
"Content-type: application/x-www-form-urlencoded",
3535
"content" => json_encode($body),

tests/cluster/rs/discovery/stepped-down-primary-triggers-refresh.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function mo_delete($id) {
1111
$opts = array("http" =>
1212
array(
1313
"method" => "DELETE",
14-
"timeout" => 30,
14+
"timeout" => 60,
1515
"header" => "Accept: application/json\r\n" .
1616
"Content-type: application/x-www-form-urlencoded",
1717
"ignore_errors" => true,
@@ -29,7 +29,7 @@ function mo_post($url, $body) {
2929
$opts = array("http" =>
3030
array(
3131
"method" => "POST",
32-
"timeout" => 30,
32+
"timeout" => 60,
3333
"header" => "Accept: application/json\r\n" .
3434
"Content-type: application/x-www-form-urlencoded",
3535
"content" => json_encode($body),

tests/cluster/sharded/connection/all-mongos-available.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function mo_delete($id) {
1111
$opts = array("http" =>
1212
array(
1313
"method" => "DELETE",
14-
"timeout" => 30,
14+
"timeout" => 60,
1515
"header" => "Accept: application/json\r\n" .
1616
"Content-type: application/x-www-form-urlencoded",
1717
"ignore_errors" => true,
@@ -29,7 +29,7 @@ function mo_post($url, $body) {
2929
$opts = array("http" =>
3030
array(
3131
"method" => "POST",
32-
"timeout" => 30,
32+
"timeout" => 60,
3333
"header" => "Accept: application/json\r\n" .
3434
"Content-type: application/x-www-form-urlencoded",
3535
"content" => json_encode($body),

tests/cluster/sharded/connection/no-mongos-available.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function mo_delete($id) {
1111
$opts = array("http" =>
1212
array(
1313
"method" => "DELETE",
14-
"timeout" => 30,
14+
"timeout" => 60,
1515
"header" => "Accept: application/json\r\n" .
1616
"Content-type: application/x-www-form-urlencoded",
1717
"ignore_errors" => true,
@@ -29,7 +29,7 @@ function mo_post($url, $body) {
2929
$opts = array("http" =>
3030
array(
3131
"method" => "POST",
32-
"timeout" => 30,
32+
"timeout" => 60,
3333
"header" => "Accept: application/json\r\n" .
3434
"Content-type: application/x-www-form-urlencoded",
3535
"content" => json_encode($body),

0 commit comments

Comments
 (0)