Skip to content

Commit ceaff59

Browse files
committed
Implement "clientHosts" phase for mo-tests
1 parent f072a53 commit ceaff59

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

scripts/convert-mo-tests.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -174,6 +177,54 @@ function MOOperation($phase, &$output) {
174177
}
175178
}
176179

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+
177228
function clientOperation($phase, &$output) {
178229
switch($phase["operation"]) {
179230
case "insertOne":

0 commit comments

Comments
 (0)