kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [kudu] branch master updated: [clock] hybrid_clock-test to run in different environments
Date Wed, 25 Mar 2020 20:07:59 GMT
This is an automated email from the ASF dual-hosted git repository.

adar 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 2612fc7  [clock] hybrid_clock-test to run in different environments
2612fc7 is described below

commit 2612fc77bb4be1da0fba090e004217821e116a49
Author: Alexey Serbin <alexey@apache.org>
AuthorDate: Tue Mar 24 15:09:05 2020 -0700

    [clock] hybrid_clock-test to run in different environments
    
    This patch updates two scenarios of the hybrid_clock-test to make
    the suite pass if run under:
      * containerized environments where ntp_adjtime() requires
        extra privileges (e.g., Docker prior to v 18.06.0-ce)
      * environments where the local clock is not NTP-synchronized
    
    For the TimeSourceAutoSelection scenario, it's about adding
    pre-conditions for those two particular cases.  If the pre-conditions
    are not satisfied, the scenario is skipped.
    
    For the TestNtpDiagnostics scenario, it turns out it's possible to
    amend it a bit to allow for running in the environments referred
    above.
    
    Change-Id: Id5cee9f4a32c18c50fe54c01c7ed81c7e93c5fa7
    Reviewed-on: http://gerrit.cloudera.org:8080/15551
    Tested-by: Kudu Jenkins
    Reviewed-by: Grant Henke <granthenke@apache.org>
    Reviewed-by: Adar Dembo <adar@cloudera.com>
---
 src/kudu/clock/hybrid_clock-test.cc | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/kudu/clock/hybrid_clock-test.cc b/src/kudu/clock/hybrid_clock-test.cc
index 80b1d57..3a94fdd 100644
--- a/src/kudu/clock/hybrid_clock-test.cc
+++ b/src/kudu/clock/hybrid_clock-test.cc
@@ -19,6 +19,7 @@
 
 #include <algorithm>
 #include <cstdint>
+#include <ostream>
 #include <string>
 #include <thread>
 #include <vector>
@@ -465,7 +466,30 @@ TEST_F(HybridClockTest, SlowClockInitialisation) {
 TEST_F(HybridClockTest, TimeSourceAutoSelection) {
   FLAGS_time_source = "auto";
   HybridClock clock(metric_entity_);
-  ASSERT_OK(clock.Init());
+  const auto s = clock.Init();
+  bool preconditions_satisfied = true;
+  if (!s.ok()) {
+    // In a testing environment where the auto-detected time source is 'system'
+    // (the local machine clock synchronized by the kernel NTP discipline),
+    // it doesn't make much sense running the test if corresponding system calls
+    // return an error (e.g., EPERM) or the clock is not synchronized.
+    // The code below is for a few cases like that: it's a set of cases seen
+    // so far in the wild.
+    if (s.IsRuntimeError()) {
+      ASSERT_STR_CONTAINS(s.ToString(), "Operation not permitted");
+      preconditions_satisfied = false;
+    } else if (s.IsServiceUnavailable()) {
+      ASSERT_STR_CONTAINS(
+          s.ToString(), "Error reading clock. Clock considered unsynchronized");
+      preconditions_satisfied = false;
+    }
+  }
+  if (!preconditions_satisfied) {
+    LOG(WARNING) << "preconditions are not satisfied, skipping the test";
+    return;
+  }
+
+  ASSERT_OK(s);
   Timestamp timestamp[2];
   uint64_t max_error_usec[2];
   ASSERT_OK(clock.NowWithError(&timestamp[0], &max_error_usec[0]));
@@ -477,7 +501,11 @@ TEST_F(HybridClockTest, TimeSourceAutoSelection) {
 TEST_F(HybridClockTest, TestNtpDiagnostics) {
   FLAGS_time_source = "system";
   HybridClock clock(metric_entity_);
-  ASSERT_OK(clock.Init());
+
+  // Even if HybridClock's initialization failed, the point of this scenario
+  // is to verify that diagnostics run appropriate tools. By design, the set
+  // of tools run these purposes doesn't depend on the initialization status.
+  WARN_NOT_OK(clock.Init(), "clock initialization failed");
 
   vector<string> log;
   clock.time_service()->DumpDiagnostics(&log);


Mime
View raw message