aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/naming
diff options
context:
space:
mode:
authorGravatar Alexander Polcyn <apolcyn@google.com>2017-12-28 18:09:19 -0800
committerGravatar Alexander Polcyn <apolcyn@google.com>2018-03-20 23:51:23 -0700
commitd21ee150765c73876992bbf06c716b4600ba047f (patch)
treeef97400ceb7007fc0c1498e61adf851cdc0eaa26 /test/cpp/naming
parent690dde672a877083e29ee5af0b8252697aa48fa0 (diff)
Stop relying on certain ipv6 macros. Also bazel build updates.
Fix error just made in bazel/grpc_build_system.bzl Fix merge conflict support/env -> gpr/env
Diffstat (limited to 'test/cpp/naming')
-rw-r--r--test/cpp/naming/address_sorting_test.cc112
1 files changed, 111 insertions, 1 deletions
diff --git a/test/cpp/naming/address_sorting_test.cc b/test/cpp/naming/address_sorting_test.cc
index d2c73a5674..3648364788 100644
--- a/test/cpp/naming/address_sorting_test.cc
+++ b/test/cpp/naming/address_sorting_test.cc
@@ -46,7 +46,7 @@
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
-#include "src/core/lib/support/env.h"
+#include "src/core/lib/gpr/env.h"
#include "src/core/lib/support/string.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@@ -326,6 +326,61 @@ TEST(AddressSortingTest,
}
TEST(AddressSortingTest,
+ TestUsesDestinationWithHigherPrecedenceWithV4CompatAndLocalhostAddress) {
+ bool ipv4_supported = true;
+ bool ipv6_supported = true;
+// Handle unique observed behavior of inet_ntop(v4-compatible-address) on OS X.
+#if GPR_APPLE == 1
+ const char* v4_compat_dest = "[::0.0.0.2]:443";
+ const char* v4_compat_src = "[::0.0.0.2]:0";
+#else
+ const char* v4_compat_dest = "[::2]:443";
+ const char* v4_compat_src = "[::2]:0";
+#endif
+ OverrideAddressSortingSourceAddrFactory(
+ ipv4_supported, ipv6_supported,
+ {
+ {"[::1]:443", {"[::1]:0", AF_INET6}},
+ {v4_compat_dest, {v4_compat_src, AF_INET6}},
+ });
+ grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ {v4_compat_dest, AF_INET6},
+ {"[::1]:443", AF_INET6},
+ });
+ grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ VerifyLbAddrOutputs(lb_addrs, {
+ "[::1]:443",
+ v4_compat_dest,
+ });
+}
+
+TEST(AddressSortingTest,
+ TestUsesDestinationWithHigherPrecedenceWithCatchAllAndLocalhostAddress) {
+ bool ipv4_supported = true;
+ bool ipv6_supported = true;
+ OverrideAddressSortingSourceAddrFactory(
+ ipv4_supported, ipv6_supported,
+ {
+ // 1234::2 for src and dest to make sure that prefix matching has no
+ // influence on this test.
+ {"[1234::2]:443", {"[1234::2]:0", AF_INET6}},
+ {"[::1]:443", {"[::1]:0", AF_INET6}},
+ });
+ grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ {"[1234::2]:443", AF_INET6},
+ {"[::1]:443", AF_INET6},
+ });
+ grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ VerifyLbAddrOutputs(
+ lb_addrs,
+ {
+ // ::1 should match the localhost precedence entry and be prioritized
+ "[::1]:443",
+ "[1234::2]:443",
+ });
+}
+
+TEST(AddressSortingTest,
TestUsesDestinationWithHigherPrecedenceWith2000PrefixedAddress) {
bool ipv4_supported = true;
bool ipv6_supported = true;
@@ -391,6 +446,30 @@ TEST(AddressSortingTest,
});
}
+TEST(
+ AddressSortingTest,
+ TestUsesDestinationWithHigherPrecedenceWithCatchAllAndAndV4MappedAddresses) {
+ bool ipv4_supported = true;
+ bool ipv6_supported = true;
+ OverrideAddressSortingSourceAddrFactory(
+ ipv4_supported, ipv6_supported,
+ {
+ {"[::ffff:0.0.0.2]:443", {"[::ffff:0.0.0.3]:0", AF_INET6}},
+ {"[1234::2]:443", {"[1234::3]:0", AF_INET6}},
+ });
+ grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ {"[::ffff:0.0.0.2]:443", AF_INET6},
+ {"[1234::2]:443", AF_INET6},
+ });
+ grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ VerifyLbAddrOutputs(lb_addrs, {
+ // ::ffff:0:2 should match the v4-mapped
+ // precedence entry and be deprioritized.
+ "[1234::2]:443",
+ "[::ffff:0.0.0.2]:443",
+ });
+}
+
/* Tests for rule 8 */
TEST(AddressSortingTest, TestPrefersSmallerScope) {
@@ -611,6 +690,37 @@ TEST(AddressSortingTest, TestStableSortNoSrcAddrsExistWithIpv4) {
});
}
+TEST(AddressSortingTest, TestStableSortV4CompatAndSiteLocalAddresses) {
+ bool ipv4_supported = true;
+ bool ipv6_supported = true;
+// Handle unique observed behavior of inet_ntop(v4-compatible-address) on OS X.
+#if GPR_APPLE == 1
+ const char* v4_compat_dest = "[::0.0.0.2]:443";
+ const char* v4_compat_src = "[::0.0.0.3]:0";
+#else
+ const char* v4_compat_dest = "[::2]:443";
+ const char* v4_compat_src = "[::3]:0";
+#endif
+ OverrideAddressSortingSourceAddrFactory(
+ ipv4_supported, ipv6_supported,
+ {
+ {"[fec0::2000]:443", {"[fec0::2001]:0", AF_INET6}},
+ {v4_compat_dest, {v4_compat_src, AF_INET6}},
+ });
+ grpc_lb_addresses* lb_addrs = BuildLbAddrInputs({
+ {"[fec0::2000]:443", AF_INET6},
+ {v4_compat_dest, AF_INET6},
+ });
+ grpc_cares_wrapper_address_sorting_sort(lb_addrs);
+ VerifyLbAddrOutputs(lb_addrs,
+ {
+ // The sort should be stable since
+ // v4-compatible has same precedence as site-local.
+ "[fec0::2000]:443",
+ v4_compat_dest,
+ });
+}
+
int main(int argc, char** argv) {
const char* resolver = gpr_getenv("GRPC_DNS_RESOLVER");
if (resolver == NULL || strlen(resolver) == 0) {