This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push: new 236a58914 [tests] make the startup page tests more robust 236a58914 is described below commit 236a589140f46b7a0138c2b26620f596139f2777 Author: Alexey Serbin <ale...@apache.org> AuthorDate: Thu Jun 9 18:17:48 2022 -0700 [tests] make the startup page tests more robust I noticed that the startup page tests reliably fail on my test machine. It turned out that there was KUDU_HOME variable set in the environment, so the embedded webserver rendered the pages according to the Mustache mappings found under $KUDU_HOME/www, while the test scenarios expect all pages to be pre-rendered. This patch updates corresponding test scenarios to reliably work even if the KUDU_HOME environment is set and points to the directory with the Mustache mapping files. Change-Id: I2e56cd49eb2e00c5666e4214c7ca4246386e8b9e Reviewed-on: http://gerrit.cloudera.org:8080/18606 Tested-by: Kudu Jenkins Reviewed-by: Abhishek Chennaka <achenn...@cloudera.com> Reviewed-by: Attila Bukor <abu...@apache.org> --- src/kudu/master/master-test.cc | 118 ++++++++++++++++++++------------- src/kudu/tserver/tablet_server-test.cc | 28 +++++--- 2 files changed, 93 insertions(+), 53 deletions(-) diff --git a/src/kudu/master/master-test.cc b/src/kudu/master/master-test.cc index 5e13ed68c..d69003f56 100644 --- a/src/kudu/master/master-test.cc +++ b/src/kudu/master/master-test.cc @@ -141,6 +141,7 @@ DECLARE_int64(live_row_count_for_testing); DECLARE_int64(on_disk_size_for_testing); DECLARE_string(location_mapping_cmd); DECLARE_string(log_filename); +DECLARE_string(webserver_doc_root); METRIC_DECLARE_histogram(handler_latency_kudu_master_MasterService_GetTableSchema); @@ -392,50 +393,6 @@ TEST_F(MasterTest, TestResetBlockCacheMetricsInSameProcess) { }); } -TEST_F(MasterTest, TestStartupWebPage) { - EasyCurl c; - faststring buf; - string addr = mini_master_->bound_http_addr().ToString(); - mini_master_->Shutdown(); - std::atomic<bool> run_status_reader = false; - thread read_startup_page([&] { - EasyCurl thread_c; - faststring thread_buf; - while (!run_status_reader) { - SleepFor(MonoDelta::FromMilliseconds(10)); - if (!(thread_c.FetchURL(strings::Substitute("http://$0/startup", addr), &thread_buf)).ok()) { - continue; - } - ASSERT_STR_MATCHES(thread_buf.ToString(), "\"init_status\":(100|0)( |,)"); - ASSERT_STR_MATCHES(thread_buf.ToString(), "\"read_filesystem_status\":(100|0)( |,)"); - ASSERT_STR_MATCHES(thread_buf.ToString(), "\"read_instance_metadatafiles_status\"" - ":(100|0)( |,)"); - ASSERT_STR_MATCHES(thread_buf.ToString(), "\"read_data_directories_status\":" - "([0-9]|[1-9][0-9]|100)( |,)"); - ASSERT_STR_MATCHES(thread_buf.ToString(), "\"initialize_master_catalog_status\":" - "([0-9]|[1-9][0-9]|100)( |,)"); - ASSERT_STR_MATCHES(thread_buf.ToString(), "\"start_rpc_server_status\":(100|0)( |,)"); - } - }); - SCOPED_CLEANUP({ - run_status_reader = true; - read_startup_page.join(); - }); - - ASSERT_OK(mini_master_->Restart()); - ASSERT_OK(mini_master_->WaitForCatalogManagerInit()); - run_status_reader = true; - - // After all the steps have been completed, ensure every startup step has 100 percent status - ASSERT_OK(c.FetchURL(strings::Substitute("http://$0/startup", addr), &buf)); - ASSERT_STR_CONTAINS(buf.ToString(), "\"init_status\":100"); - ASSERT_STR_CONTAINS(buf.ToString(), "\"read_filesystem_status\":100"); - ASSERT_STR_CONTAINS(buf.ToString(), "\"read_instance_metadatafiles_status\":100"); - ASSERT_STR_CONTAINS(buf.ToString(), "\"read_data_directories_status\":100"); - ASSERT_STR_CONTAINS(buf.ToString(), "\"initialize_master_catalog_status\":100"); - ASSERT_STR_CONTAINS(buf.ToString(), "\"start_rpc_server_status\":100"); -} - TEST_F(MasterTest, TestRegisterAndHeartbeat) { const char* const kTsUUID = "my-ts-uuid"; @@ -2819,8 +2776,79 @@ TEST_P(AuthzTokenMasterTest, TestGenerateAuthzTokens) { ASSERT_EQ(supports_authz, resp.has_authz_token()); } } - INSTANTIATE_TEST_SUITE_P(SupportsAuthzTokens, AuthzTokenMasterTest, ::testing::Bool()); +class MasterStartupTest : public KuduTest { + protected: + void SetUp() override { + KuduTest::SetUp(); + + // The embedded webserver renders the contents of the generated pages + // according to mustache's mappings found under the directory pointed to by + // the --webserver_doc_root flag, which is set to $KUDU_HOME/www by default. + // Since this test assumes to fetch the pre-rendered output for the startup + // page, it would fail if the KUDU_HOME environment variable were set and + // pointed to the location where 'www' subdirectory contained the required + // mustache mappings. Let's explicitly point the document root to nowhere, + // so no mustache-based rendering is done. + FLAGS_webserver_doc_root = ""; + + mini_master_.reset(new MiniMaster(GetTestPath("Master"), HostPort("127.0.0.1", 0))); + ASSERT_OK(mini_master_->Start()); + } + + void TearDown() override { + mini_master_->Shutdown(); + KuduTest::TearDown(); + } + + unique_ptr<MiniMaster> mini_master_; +}; + +TEST_F(MasterStartupTest, StartupWebPage) { + const string addr = mini_master_->bound_http_addr().ToString(); + mini_master_->Shutdown(); + + std::atomic<bool> run_status_reader = true; + thread status_reader([&] { + EasyCurl c; + faststring buf; + while (run_status_reader) { + SleepFor(MonoDelta::FromMilliseconds(10)); + if (!c.FetchURL(strings::Substitute("http://$0/startup", addr), &buf).ok()) { + continue; + } + ASSERT_STR_MATCHES(buf.ToString(), "\"init_status\":(100|0)( |,)"); + ASSERT_STR_MATCHES(buf.ToString(), "\"read_filesystem_status\":(100|0)( |,)"); + ASSERT_STR_MATCHES(buf.ToString(), "\"read_instance_metadatafiles_status\"" + ":(100|0)( |,)"); + ASSERT_STR_MATCHES(buf.ToString(), "\"read_data_directories_status\":" + "([0-9]|[1-9][0-9]|100)( |,)"); + ASSERT_STR_MATCHES(buf.ToString(), "\"initialize_master_catalog_status\":" + "([0-9]|[1-9][0-9]|100)( |,)"); + ASSERT_STR_MATCHES(buf.ToString(), "\"start_rpc_server_status\":(100|0)( |,)"); + } + }); + SCOPED_CLEANUP({ + run_status_reader = false; + status_reader.join(); + }); + + ASSERT_OK(mini_master_->Restart()); + ASSERT_OK(mini_master_->WaitForCatalogManagerInit()); + run_status_reader = false; + + // After all the steps have been completed, ensure every startup step has 100 percent status + EasyCurl c; + faststring buf; + ASSERT_OK(c.FetchURL(strings::Substitute("http://$0/startup", addr), &buf)); + ASSERT_STR_CONTAINS(buf.ToString(), "\"init_status\":100"); + ASSERT_STR_CONTAINS(buf.ToString(), "\"read_filesystem_status\":100"); + ASSERT_STR_CONTAINS(buf.ToString(), "\"read_instance_metadatafiles_status\":100"); + ASSERT_STR_CONTAINS(buf.ToString(), "\"read_data_directories_status\":100"); + ASSERT_STR_CONTAINS(buf.ToString(), "\"initialize_master_catalog_status\":100"); + ASSERT_STR_CONTAINS(buf.ToString(), "\"start_rpc_server_status\":100"); +} + } // namespace master } // namespace kudu diff --git a/src/kudu/tserver/tablet_server-test.cc b/src/kudu/tserver/tablet_server-test.cc index ce7fb6178..68fde5aad 100644 --- a/src/kudu/tserver/tablet_server-test.cc +++ b/src/kudu/tserver/tablet_server-test.cc @@ -206,6 +206,7 @@ DECLARE_int32(workload_stats_metric_collection_interval_ms); DECLARE_string(block_manager); DECLARE_string(env_inject_eio_globs); DECLARE_string(env_inject_full_globs); +DECLARE_string(webserver_doc_root); DECLARE_uint32(tablet_apply_pool_overload_threshold_ms); // Declare these metrics prototypes for simpler unit testing of their behavior. @@ -771,6 +772,16 @@ enum class ErrorType { class TabletServerStartupWebPageTest : public TabletServerTestBase { public: void SetUp() override { + // The embedded webserver renders the contents of the generated pages + // according to mustache's mappings found under the directory pointed to by + // the --webserver_doc_root flag, which is set to $KUDU_HOME/www by default. + // Since this test assumes to fetch the pre-rendered output for the startup + // page, it would fail if the KUDU_HOME environment variable were set and + // pointed to the location where 'www' subdirectory contained the required + // mustache mappings. Let's explicitly point the document root to nowhere, + // so no mustache-based rendering is done. + FLAGS_webserver_doc_root = ""; + NO_FATALS(TabletServerTestBase::SetUp()); NO_FATALS(StartTabletServer(kNumDirs)); // Create a bunch of tablets with a bunch of rowsets. @@ -824,12 +835,13 @@ class TabletServerStartupWebPageTest : public TabletServerTestBase { }; TEST_F(TabletServerStartupWebPageTest, TestStartupWebPage) { - EasyCurl c; - faststring buf; const string url = Substitute("http://$0/startup", mini_server_->bound_http_addr().ToString()); // Verify if the startup status is complete. mini_server_->WaitStarted(); + + EasyCurl c; + faststring buf; ASSERT_OK(c.FetchURL(url, &buf)); NO_FATALS(IsStatusComplete(buf.ToString())); @@ -841,13 +853,13 @@ TEST_F(TabletServerStartupWebPageTest, TestStartupWebPage) { // Restart the tablet server and monitor the startup page contents. tablet_replica_.reset(); mini_server_->Shutdown(); - std::atomic<bool> run_status_reader = false; + std::atomic<bool> run_status_reader = true; // Hammer the webpage and validate the status percentages. - thread read_startup_page([&] { + thread status_reader([&] { EasyCurl thread_c; faststring thread_buf; - while (!run_status_reader) { + while (run_status_reader) { if (!thread_c.FetchURL(url, &thread_buf).ok()) { continue; } @@ -855,13 +867,13 @@ TEST_F(TabletServerStartupWebPageTest, TestStartupWebPage) { } }); SCOPED_CLEANUP({ - run_status_reader = true; - read_startup_page.join(); + run_status_reader = false; + status_reader.join(); }); mini_server_->Start(); mini_server_->WaitStarted(); - run_status_reader = true; + run_status_reader = false; // After the server has startup up, ensure every startup step has 100 percent status. ASSERT_OK(c.FetchURL(url, &buf));