1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <mongoc.h>
#include "TestSuite.h"
#include "test-conveniences.h"
#include "test-libmongoc.h"
int skip_if_single (void)
{
return (test_framework_is_mongos () || test_framework_is_replset());
}
static void
server_selection_error_dns (const char *uri, const char *errmsg, bool assert_as)
{
mongoc_client_t *client;
mongoc_collection_t *collection;
bson_error_t error;
bson_t *command;
bson_t reply;
bool success;
client = mongoc_client_new (uri);
collection = mongoc_client_get_collection (client, "test", "test");
command = tmp_bson("{'ping': 1}");
success = mongoc_collection_command_simple (collection, command, NULL, &reply, &error);
ASSERT_OR_PRINT(success == assert_as, error);
if (!success && errmsg) {
ASSERT_CMPSTR(error.message, errmsg);
}
bson_destroy (&reply);
mongoc_collection_destroy (collection);
mongoc_client_destroy (client);
}
static void
test_server_selection_error_dns_single (void)
{
server_selection_error_dns (
"mongodb://non-existing-localhost:27017/",
"No suitable servers found (`serverselectiontryonce` set): [Failed to resolve 'non-existing-localhost']",
false
);
}
static void
test_server_selection_error_dns_multi_fail (void)
{
server_selection_error_dns (
"mongodb://non-existing-localhost:27017,other-non-existing-localhost:27017/",
"No suitable servers found (`serverselectiontryonce` set): [Failed to resolve 'non-existing-localhost'] [Failed to resolve 'other-non-existing-localhost']",
false
);
}
static void
test_server_selection_error_dns_multi_success (void *context)
{
server_selection_error_dns (
"mongodb://non-existing-localhost:27017,localhost:27017,other-non-existing-localhost:27017/",
"",
true
);
}
void
test_server_selection_errors_install (TestSuite *suite)
{
TestSuite_Add (suite, "/server_selection/errors/dns/single", test_server_selection_error_dns_single);
TestSuite_Add (suite, "/server_selection/errors/dns/multi/fail", test_server_selection_error_dns_multi_fail);
TestSuite_AddFull (suite, "/server_selection/errors/dns/multi/success", test_server_selection_error_dns_multi_success, NULL, NULL, skip_if_single);
}
|