Skip to content

PHPC-355: Add test for ConnectionTimeoutException #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2018

Conversation

kvwalker
Copy link
Contributor

@kvwalker kvwalker requested review from derickr and jmikola February 28, 2018 19:42
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not using any of the mongo-orchestration constants, so this can be require_once __DIR__ . '/../utils/tools.php'; instead.

--TEST--
MongoDB\Driver\Manager - no connection (command)
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This --SKIPIF-- shouldn't be needed, as we don't depend on mongo-orchestration.

$command = new MongoDB\Driver\Command(['drop' => 'test']);

throws(function() use($manager, $command) {
$retval = $manager->executeCommand(NS, $command);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably doesn't need to assign the return value to anything.


$command = new MongoDB\Driver\Command(['drop' => 'test']);

throws(function() use($manager, $command) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use echo throws(...), "\n"; and add the exception message to the expected output? That may require some pattern matching for dynamic values in the string, which will warrant using EXPECTF instead of EXPECT. For reference on pattern matching, see https://qa.php.net/phpt_details.php#expectf_section.

<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
===DONE===
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's easy to configure Vim to do so: newlines at the end of the file 👌


$manager = new MongoDB\Driver\Manager("mongodb://localhost:44444/?serverselectiontimeoutms=10");

$command = new MongoDB\Driver\Command(['drop' => 'test']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it makes no difference in execution, but ['ping' => 1] would be more appropriate. Also considering we're using executeCommand() below instead of executeWriteCommand(), that sets a better example for any users that might see this.

@@ -0,0 +1,22 @@
--TEST--
MongoDB\Driver\Manager - no connection (command)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest naming the file manager-executeCommand_error-003.phpt (there is a gap between 002 and 004, so we can fill it. And then "MongoDB\Driver\Manager::executeCommand() connection error" as a test name.

Down the line, we can make copies of this test for other execute methods on Manager and Server. The naming convention becomes much more practical in that case.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@kvwalker kvwalker merged commit a646b4e into mongodb:master Mar 1, 2018
kvwalker added a commit that referenced this pull request Mar 1, 2018
@kvwalker kvwalker deleted the PHPC-355 branch March 1, 2018 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants