Skip to content

PHPC-581: Use ConnectionTimeoutException for server selection failures #231

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
Feb 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ zend_class_entry* phongo_exception_from_mongoc_domain(uint32_t /* mongoc_error_d
case 50: /* ExceededTimeLimit */
return php_phongo_executiontimeoutexception_ce;
case MONGOC_ERROR_STREAM_SOCKET:
case MONGOC_ERROR_SERVER_SELECTION_FAILURE:
return php_phongo_connectiontimeoutexception_ce;
case MONGOC_ERROR_CLIENT_AUTHENTICATE:
return php_phongo_authenticationexception_ce;
Expand Down
8 changes: 4 additions & 4 deletions tests/manager/manager-executeBulkWrite_error-007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ $manager = new MongoDB\Driver\Manager('mongodb://invalid.host:27017', ['serverSe

echo throws(function() use ($manager, $bulk) {
$manager->executeBulkWrite(NS, $bulk);
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";

// Valid host refuses connection
$manager = new MongoDB\Driver\Manager('mongodb://localhost:54321', ['serverSelectionTimeoutMS' => 1]);

echo throws(function() use ($manager, $bulk) {
$manager->executeBulkWrite(NS, $bulk);
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
OK: Got MongoDB\Driver\Exception\RuntimeException
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
No suitable servers found (`serverselectiontryonce` set): %s
OK: Got MongoDB\Driver\Exception\RuntimeException
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
No suitable servers found (`serverselectiontryonce` set): %s
===DONE===
8 changes: 4 additions & 4 deletions tests/manager/manager-executeCommand_error-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ $manager = new MongoDB\Driver\Manager('mongodb://invalid.host:27017', ['serverSe

echo throws(function() use ($manager, $command) {
$manager->executeCommand(DATABASE_NAME, $command);
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";

// Valid host refuses connection
$manager = new MongoDB\Driver\Manager('mongodb://localhost:54321', ['serverSelectionTimeoutMS' => 1]);

echo throws(function() use ($manager, $command) {
$manager->executeCommand(DATABASE_NAME, $command);
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
OK: Got MongoDB\Driver\Exception\RuntimeException
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
No suitable servers found (`serverselectiontryonce` set): %s
OK: Got MongoDB\Driver\Exception\RuntimeException
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
No suitable servers found (`serverselectiontryonce` set): %s
===DONE===
8 changes: 4 additions & 4 deletions tests/manager/manager-executeQuery_error-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ $manager = new MongoDB\Driver\Manager('mongodb://invalid.host:27017', ['serverSe

echo throws(function() use ($manager, $query) {
$manager->executeQuery(NS, $query);
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";

// Valid host refuses connection
$manager = new MongoDB\Driver\Manager('mongodb://localhost:54321', ['serverSelectionTimeoutMS' => 1]);

echo throws(function() use ($manager, $query) {
$manager->executeQuery(NS, $query);
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
OK: Got MongoDB\Driver\Exception\RuntimeException
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
No suitable servers found (`serverselectiontryonce` set): %s
OK: Got MongoDB\Driver\Exception\RuntimeException
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
No suitable servers found (`serverselectiontryonce` set): %s
===DONE===
8 changes: 4 additions & 4 deletions tests/manager/manager-selectserver_error-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ $manager = new MongoDB\Driver\Manager('mongodb://invalid.host:27017', ['serverSe

echo throws(function() use ($manager, $rp) {
$manager->selectServer($rp);
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";

// Valid host refuses connection
$manager = new MongoDB\Driver\Manager('mongodb://localhost:54321', ['serverSelectionTimeoutMS' => 1]);

echo throws(function() use ($manager, $rp) {
$manager->selectServer($rp);
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
}, 'MongoDB\Driver\Exception\ConnectionTimeoutException'), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
OK: Got MongoDB\Driver\Exception\RuntimeException
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
No suitable servers found (`serverselectiontryonce` set): %s
OK: Got MongoDB\Driver\Exception\RuntimeException
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
No suitable servers found (`serverselectiontryonce` set): %s
===DONE===