Merge pull request #20701 from markdroth/xds_bootstrap_test_fix

Change xds_end2end_test to write out its own bootstrap files.
reviewable/pr20544/r4^2
Mark D. Roth 5 years ago committed by GitHub
commit 334c826e8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      test/cpp/end2end/BUILD
  2. 22
      test/cpp/end2end/xds_bootstrap.json
  3. 12
      test/cpp/end2end/xds_bootstrap_bad.json
  4. 59
      test/cpp/end2end/xds_end2end_test.cc

@ -508,10 +508,6 @@ grpc_cc_test(
"//test/core/util:grpc_test_util",
"//test/cpp/util:test_util",
],
data = [
"xds_bootstrap.json",
"xds_bootstrap_bad.json",
],
tags = ["no_windows"], # TODO(jtattermusch): fix test on windows
)

@ -1,22 +0,0 @@
{
"xds_server": {
"server_uri": "fake:///lb",
"channel_creds": [
{
"type": "fake"
}
]
},
"node": {
"id": "xds_end2end_test",
"cluster": "test",
"metadata": {
"foo": "bar"
},
"locality": {
"region": "corp",
"zone": "svl",
"subzone": "mp3"
}
}
}

@ -1,12 +0,0 @@
{
"xds_server": {
"server_uri": "fake:///wrong_lb",
"channel_creds": [
{
"type": "fake"
}
]
},
"node": {
}
}

@ -39,6 +39,7 @@
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/map.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h"
@ -102,6 +103,59 @@ constexpr char kThrottleDropType[] = "throttle";
constexpr int kDefaultLocalityWeight = 3;
constexpr int kDefaultLocalityPriority = 0;
constexpr char kBootstrapFile[] =
"{\n"
" \"xds_server\": {\n"
" \"server_uri\": \"fake:///lb\",\n"
" \"channel_creds\": [\n"
" {\n"
" \"type\": \"fake\"\n"
" }\n"
" ]\n"
" },\n"
" \"node\": {\n"
" \"id\": \"xds_end2end_test\",\n"
" \"cluster\": \"test\",\n"
" \"metadata\": {\n"
" \"foo\": \"bar\"\n"
" },\n"
" \"locality\": {\n"
" \"region\": \"corp\",\n"
" \"zone\": \"svl\",\n"
" \"subzone\": \"mp3\"\n"
" }\n"
" }\n"
"}\n";
constexpr char kBootstrapFileBad[] =
"{\n"
" \"xds_server\": {\n"
" \"server_uri\": \"fake:///wrong_lb\",\n"
" \"channel_creds\": [\n"
" {\n"
" \"type\": \"fake\"\n"
" }\n"
" ]\n"
" },\n"
" \"node\": {\n"
" }\n"
"}\n";
char* g_bootstrap_file;
char* g_bootstrap_file_bad;
void WriteBootstrapFiles() {
char* bootstrap_file;
FILE* out = gpr_tmpfile("xds_bootstrap", &bootstrap_file);
fputs(kBootstrapFile, out);
fclose(out);
g_bootstrap_file = bootstrap_file;
out = gpr_tmpfile("xds_bootstrap_bad", &bootstrap_file);
fputs(kBootstrapFileBad, out);
fclose(out);
g_bootstrap_file_bad = bootstrap_file;
}
template <typename ServiceType>
class CountedService : public ServiceType {
public:
@ -565,7 +619,7 @@ class XdsEnd2endTest : public ::testing::TestWithParam<TestType> {
static void TearDownTestCase() { grpc_shutdown(); }
void SetUp() override {
gpr_setenv("GRPC_XDS_BOOTSTRAP", "test/cpp/end2end/xds_bootstrap.json");
gpr_setenv("GRPC_XDS_BOOTSTRAP", g_bootstrap_file);
response_generator_ =
grpc_core::MakeRefCounted<grpc_core::FakeResolverResponseGenerator>();
lb_channel_response_generator_ =
@ -1159,7 +1213,7 @@ TEST_P(SecureNamingTest, TargetNameIsExpected) {
// Tests that secure naming check fails if target name is unexpected.
TEST_P(SecureNamingTest, TargetNameIsUnexpected) {
gpr_setenv("GRPC_XDS_BOOTSTRAP", "test/cpp/end2end/xds_bootstrap_bad.json");
gpr_setenv("GRPC_XDS_BOOTSTRAP", g_bootstrap_file_bad);
::testing::FLAGS_gtest_death_test_style = "threadsafe";
// Make sure that we blow up (via abort() from the security connector) when
// the name from the balancer doesn't match expectations.
@ -2418,6 +2472,7 @@ INSTANTIATE_TEST_SUITE_P(XdsTest, ClientLoadReportingWithDropTest,
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(argc, argv);
::testing::InitGoogleTest(&argc, argv);
grpc::testing::WriteBootstrapFiles();
const auto result = RUN_ALL_TESTS();
return result;
}

Loading…
Cancel
Save