kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/2] kudu git commit: Add helper macro for tool invocations
Date Fri, 14 Sep 2018 18:03:06 GMT
Repository: kudu
Updated Branches:
  refs/heads/master f31e5cbc7 -> 72a77bfbf


Add helper macro for tool invocations

Using `ASSERT_OK` to test the results of the `kudu` tool is normal, but
it results in lousy test failure output:

../../src/kudu/tools/kudu-admin-test.cc:235: Failure
Failed
Bad status: Runtime error: /Users/wdberkeley/src/kudu/build/debug/bin/kudu: process exited
with non-zero status 1

This adds a new macro, `ASSERT_TOOL_OK`, that also logs the stdout and
stderr of a `kudu` tool invocation:

../../src/kudu/tools/kudu-admin-test.cc:235: Failure
Failed
Runtime error: /Users/wdberkeley/src/kudu/build/debug/bin/kudu: process exited with non-zero
status 1
stdout:
stderr: W0910 12:39:07.483736 2830984064 flags.cc:406] Enabled unsafe flag: --never_fsync=true
Invalid argument: Unrecognized peer type: FOOVOTER

Change-Id: I7ffd357d79982ee5c93f8d3c7cfd7cc1f0863f07
Reviewed-on: http://gerrit.cloudera.org:8080/11411
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/a643a5ce
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/a643a5ce
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/a643a5ce

Branch: refs/heads/master
Commit: a643a5ceca75d9a2d89fd937757a9d142a29c83f
Parents: f31e5cb
Author: Will Berkeley <wdberkeley@gmail.org>
Authored: Mon Sep 10 12:45:37 2018 -0700
Committer: Will Berkeley <wdberkeley@gmail.com>
Committed: Thu Sep 13 18:04:17 2018 +0000

----------------------------------------------------------------------
 src/kudu/tools/kudu-admin-test.cc | 79 ++++++++++++++++++++--------------
 1 file changed, 47 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/a643a5ce/src/kudu/tools/kudu-admin-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-admin-test.cc b/src/kudu/tools/kudu-admin-test.cc
index 05ba159..ff7e84c 100644
--- a/src/kudu/tools/kudu-admin-test.cc
+++ b/src/kudu/tools/kudu-admin-test.cc
@@ -126,6 +126,34 @@ class Schema;
 
 namespace tools {
 
+  // Helper to format info when a tool action fails.
+static string ToolRunInfo(const Status& s, const string& out, const string& err)
{
+  ostringstream str;
+  str << s.ToString() << endl;
+  str << "stdout: " << out << endl;
+  str << "stderr: " << err << endl;
+  return str.str();
+}
+
+// Helper macro for tool tests. Use as follows:
+//
+// ASSERT_TOOL_OK("cluster", "ksck", master_addrs);
+//
+// The failure Status result of RunKuduTool is usually useless, so this macro
+// also logs the stdout and stderr in case of failure, for easier diagnosis.
+// TODO(wdberkeley): Add a macro to retrieve stdout or stderr, or a macro for
+//                   when one of those should match a string.
+#define ASSERT_TOOL_OK(...) do { \
+  const vector<string>& _args{__VA_ARGS__}; \
+  string _out, _err; \
+  const Status& _s = RunKuduTool(_args, &_out, &_err); \
+  if (_s.ok()) { \
+    SUCCEED(); \
+  } else { \
+    FAIL() << ToolRunInfo(_s, _out, _err); \
+  } \
+} while (0);
+
 class AdminCliTest : public tserver::TabletServerIntegrationTestBase {
 };
 
@@ -195,7 +223,7 @@ TEST_F(AdminCliTest, TestChangeConfig) {
 
   LOG(INFO) << "Adding replica at tserver with UUID "
             << new_node->uuid() << " as VOTER...";
-  ASSERT_OK(RunKuduTool({
+  ASSERT_TOOL_OK(
     "tablet",
     "change_config",
     "add_replica",
@@ -203,7 +231,7 @@ TEST_F(AdminCliTest, TestChangeConfig) {
     tablet_id_,
     new_node->uuid(),
     "VOTER"
-  }));
+  );
 
   InsertOrDie(&active_tablet_servers, new_node->uuid(), new_node);
   ASSERT_OK(WaitUntilCommittedConfigNumVotersIs(active_tablet_servers.size(),
@@ -233,14 +261,14 @@ TEST_F(AdminCliTest, TestChangeConfig) {
   // Now remove the server.
   LOG(INFO) << "Removing replica at tserver with UUID "
             << new_node->uuid() << " from the config...";
-  ASSERT_OK(RunKuduTool({
+  ASSERT_TOOL_OK(
     "tablet",
     "change_config",
     "remove_replica",
     cluster_->master()->bound_rpc_addr().ToString(),
     tablet_id_,
     new_node->uuid()
-  }));
+  );
 
   ASSERT_EQ(1, active_tablet_servers.erase(new_node->uuid()));
   ASSERT_OK(WaitUntilCommittedConfigNumVotersIs(active_tablet_servers.size(),
@@ -333,13 +361,14 @@ TEST_P(MoveTabletParamTest, Test) {
       add,
     };
 
-    Status s = RunKuduTool(tool_command);
+    string stdout, stderr;
+    Status s = RunKuduTool(tool_command, &stdout, &stderr);
     if (downTS == DownTS::TabletPeer) {
       ASSERT_TRUE(s.IsRuntimeError());
       workload.StopAndJoin();
       return;
     }
-    ASSERT_OK(s);
+    ASSERT_TRUE(s.ok()) << ToolRunInfo(s, stdout, stderr);
 
     active_tservers.pop_front();
     active_tservers.push_back(add);
@@ -904,7 +933,7 @@ TEST_F(AdminCliTest, TestUnsafeChangeConfigFollowerWithPendingConfig)
{
   }, nullptr, &stderr);
   bool not_currently_leader = stderr.find(
       Status::IllegalState("").CodeAsString()) != string::npos;
-  ASSERT_TRUE(s.ok() || not_currently_leader);
+  ASSERT_TRUE(s.ok() || not_currently_leader) << "stderr: " << stderr;
 
   LOG(INFO) << "Change Config Op timed out, Sending a Replace config "
             << "command when change config op is pending on the leader.";
@@ -1209,7 +1238,7 @@ TEST_F(AdminCliTest, TestLeaderStepDown) {
   }, nullptr, &stderr);
   bool not_currently_leader = stderr.find(
       Status::IllegalState("").CodeAsString()) != string::npos;
-  ASSERT_TRUE(s.ok() || not_currently_leader);
+  ASSERT_TRUE(s.ok() || not_currently_leader) << "stderr: " << stderr;
   if (s.ok()) {
     int64_t new_term;
     ASSERT_EVENTUALLY([&]() {
@@ -1261,12 +1290,12 @@ TEST_F(AdminCliTest, TestDeleteTable) {
             .add_master_server_addr(master_address)
             .Build(&client));
 
-  ASSERT_OK(RunKuduTool({
+  ASSERT_TOOL_OK(
     "table",
     "delete",
     master_address,
     kTableId
-  }));
+  );
 
   vector<string> tables;
   ASSERT_OK(client->ListTables(&tables));
@@ -1337,14 +1366,6 @@ TEST_F(AdminCliTest, TestListTablesDetail) {
   }
 }
 
-static string ToolRunInfo(const Status& s, const string& out, const string& err)
{
-  ostringstream str;
-  str << s.ToString() << endl;
-  str << "stdout: " << out << endl;
-  str << "stderr: " << err << endl;
-  return str.str();
-}
-
 TEST_F(AdminCliTest, RebalancerReportOnly) {
   static const char kReferenceOutput[] =
     R"***(Per-server replica distribution summary:
@@ -1974,14 +1995,11 @@ TEST_P(TserverGoesDownDuringRebalancingTest, TserverDown) {
   // Pre-condition: 'kudu cluster ksck' should be happy with the cluster state
   // shortly after initial setup.
   ASSERT_EVENTUALLY([&]() {
-    string out;
-    string err;
-    const auto s = RunKuduTool({
+    ASSERT_TOOL_OK(
       "cluster",
       "ksck",
-      cluster_->master()->bound_rpc_addr().ToString(),
-    }, &out, &err);
-    ASSERT_TRUE(s.ok()) << ToolRunInfo(s, out, err);
+      cluster_->master()->bound_rpc_addr().ToString()
+    )
   });
 
   Random r(SeedRandom());
@@ -2227,14 +2245,11 @@ TEST_P(RebalancingDuringElectionStormTest, RoundRobin) {
   // etc. Eventually, the system should heal itself and 'kudu cluster ksck'
   // should report no issues.
   ASSERT_EVENTUALLY([&]() {
-    string out;
-    string err;
-    const auto s = RunKuduTool({
+    ASSERT_TOOL_OK(
       "cluster",
       "ksck",
-      cluster_->master()->bound_rpc_addr().ToString(),
-    }, &out, &err);
-    ASSERT_TRUE(s.ok()) << ToolRunInfo(s, out, err);
+      cluster_->master()->bound_rpc_addr().ToString()
+    )
   });
 
   // The rebalancer should successfully rebalance the cluster after ksck
@@ -2307,7 +2322,7 @@ TEST_P(RebalancerAndSingleReplicaTablets, SingleReplicasStayOrMove)
{
               .add_hash_partitions({ "key" }, 3)
               .num_replicas(kRepFactor)
               .Create());
-    ASSERT_OK(RunKuduTool({
+    ASSERT_TOOL_OK(
       "perf",
       "loadgen",
       cluster_->master()->bound_rpc_addr().ToString(),
@@ -2315,7 +2330,7 @@ TEST_P(RebalancerAndSingleReplicaTablets, SingleReplicasStayOrMove)
{
       // Don't need much data in there.
       "--num_threads=1",
       "--num_rows_per_thread=1",
-    }));
+    );
   }
   for (auto i = kRepFactor + 1; i < kNumTservers; ++i) {
     ASSERT_OK(cluster_->tablet_server(i)->Restart());


Mime
View raw message