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
commit 03e2ada694290cafce0bea6ebbf092709aa64a2a Author: Alexey Serbin <[email protected]> AuthorDate: Thu Oct 3 12:43:38 2019 -0700 [test] use built-in NTP by default for ExternalMiniCluster This patch switches all ExternalMiniCluster-based tests to use the built-in NTP client as the default source for HybridTime timestamps. A new environment variable is introduced to override the default when running tests: KUDU_USE_SYSTEM_NTP. Set it to true if it's desired to run the ExternalMiniCluster-based scenarios using the machine's local clock as the source for HybridTime (the clock should be synchronized by the kernel NTP discipline). Change-Id: I2a93bc3847ff5b81b40106e5074934e26136320a Reviewed-on: http://gerrit.cloudera.org:8080/14362 Tested-by: Alexey Serbin <[email protected]> Reviewed-by: Grant Henke <[email protected]> --- src/kudu/mini-cluster/external_mini_cluster.cc | 2 +- src/kudu/util/test_util.cc | 23 ++++++++++++++++++----- src/kudu/util/test_util.h | 7 +++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/kudu/mini-cluster/external_mini_cluster.cc b/src/kudu/mini-cluster/external_mini_cluster.cc index 23814be..b2f01bc 100644 --- a/src/kudu/mini-cluster/external_mini_cluster.cc +++ b/src/kudu/mini-cluster/external_mini_cluster.cc @@ -116,7 +116,7 @@ ExternalMiniClusterOptions::ExternalMiniClusterOptions() logtostderr(true), start_process_timeout(MonoDelta::FromSeconds(70)), rpc_negotiation_timeout(MonoDelta::FromSeconds(3)), - num_ntp_servers(0) { + num_ntp_servers(UseSystemNtp() ? 0 : 1) { } ExternalMiniCluster::ExternalMiniCluster() diff --git a/src/kudu/util/test_util.cc b/src/kudu/util/test_util.cc index c514d0e..c41d1d1 100644 --- a/src/kudu/util/test_util.cc +++ b/src/kudu/util/test_util.cc @@ -73,7 +73,8 @@ using strings::Substitute; namespace kudu { const char* kInvalidPath = "/dev/invalid-path-for-kudu-tests"; -static const char* const kSlowTestsEnvVariable = "KUDU_ALLOW_SLOW_TESTS"; +static const char* const kSlowTestsEnvVar = "KUDU_ALLOW_SLOW_TESTS"; +static const char* const kUseSystemNtpEnvVar = "KUDU_USE_SYSTEM_NTP"; static const uint64_t kTestBeganAtMicros = Env::Default()->NowMicros(); @@ -169,8 +170,10 @@ void KuduTest::OverrideKrb5Environment() { // Test utility functions /////////////////////////////////////////////////// -bool AllowSlowTests() { - char *e = getenv(kSlowTestsEnvVariable); +namespace { +// Get the value of an environment variable that has boolean semantics. +bool GetBooleanEnvironmentVariable(const char* env_var_name) { + const char* const e = getenv(env_var_name); if ((e == nullptr) || (strlen(e) == 0) || (strcasecmp(e, "false") == 0) || @@ -183,8 +186,18 @@ bool AllowSlowTests() { (strcasecmp(e, "yes") == 0)) { return true; } - LOG(FATAL) << "Unrecognized value for " << kSlowTestsEnvVariable << ": " << e; - return false; + LOG(FATAL) << Substitute("$0: invalid value for environment variable $0", + e, env_var_name); + return false; // unreachable +} +} // anonymous namespace + +bool AllowSlowTests() { + return GetBooleanEnvironmentVariable(kSlowTestsEnvVar); +} + +bool UseSystemNtp() { + return GetBooleanEnvironmentVariable(kUseSystemNtpEnvVar); } void OverrideFlagForSlowTests(const std::string& flag_name, diff --git a/src/kudu/util/test_util.h b/src/kudu/util/test_util.h index d320e3e..7e9764d 100644 --- a/src/kudu/util/test_util.h +++ b/src/kudu/util/test_util.h @@ -87,6 +87,13 @@ class KuduTest : public ::testing::Test { // Returns true if slow tests are runtime-enabled. bool AllowSlowTests(); +// Returns true if tests should rely on the system clock synchronized by the +// kernel NTP discipline. By default, test clusters should run their own +// test NTP server and configure Kudu masters and tablet servers to use the +// built-in NTP client as the clock source for HybridTime, where the built-in +// NTP clients are pointed to the test cluster's dedicated NTP server. +bool UseSystemNtp(); + // Override the given gflag to the new value, only in the case that // slow tests are enabled and the user hasn't otherwise overridden // it on the command line.
