delete_table-test: make TestUnknownTabletsAreNotDeleted less flaky

Let's take advantage of AssertEventually.

Change-Id: I58bc405f35c9337305aa55e2431b4e1dcb821c24
Reviewed-on: http://gerrit.cloudera.org:8080/4356
Reviewed-by: Todd Lipcon <[email protected]>
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/61557b32
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/61557b32
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/61557b32

Branch: refs/heads/master
Commit: 61557b327f78f644d6ca37f2d739168937627527
Parents: 2e30b2a
Author: Adar Dembo <[email protected]>
Authored: Fri Sep 9 15:06:32 2016 -0700
Committer: Adar Dembo <[email protected]>
Committed: Sat Sep 10 00:48:50 2016 +0000

----------------------------------------------------------------------
 src/kudu/integration-tests/delete_table-test.cc | 28 +++++++++++++++-----
 1 file changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/61557b32/src/kudu/integration-tests/delete_table-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/delete_table-test.cc 
b/src/kudu/integration-tests/delete_table-test.cc
index 6bb3499..0aa3d63 100644
--- a/src/kudu/integration-tests/delete_table-test.cc
+++ b/src/kudu/integration-tests/delete_table-test.cc
@@ -62,6 +62,7 @@ using std::vector;
 using strings::Substitute;
 
 METRIC_DECLARE_entity(server);
+METRIC_DECLARE_histogram(handler_latency_kudu_master_MasterService_TSHeartbeat);
 
METRIC_DECLARE_histogram(handler_latency_kudu_tserver_TabletServerAdminService_DeleteTablet);
 
 namespace kudu {
@@ -915,8 +916,20 @@ TEST_F(DeleteTableTest, TestUnknownTabletsAreNotDeleted) {
   cluster_->master()->Shutdown();
   ASSERT_OK(env_->DeleteRecursively(cluster_->master()->data_dir()));
   ASSERT_OK(cluster_->master()->Restart());
-  SleepFor(MonoDelta::FromSeconds(2));
+
+  // Give the master a chance to finish writing the new master tablet to disk
+  // so that it can be found after the subsequent restart below.
+  ASSERT_OK(cluster_->master()->WaitForCatalogManager());
+
   int64_t num_delete_attempts;
+  AssertEventually([&]() {
+    int64_t num_heartbeats;
+    ASSERT_OK(cluster_->master()->GetInt64Metric(
+        &METRIC_ENTITY_server, "kudu.master",
+        &METRIC_handler_latency_kudu_master_MasterService_TSHeartbeat, 
"total_count",
+        &num_heartbeats));
+    ASSERT_GE(num_heartbeats, 1);
+  });
   ASSERT_OK(cluster_->tablet_server(0)->GetInt64Metric(
       &METRIC_ENTITY_server, "kudu.tabletserver",
       
&METRIC_handler_latency_kudu_tserver_TabletServerAdminService_DeleteTablet,
@@ -929,12 +942,13 @@ TEST_F(DeleteTableTest, TestUnknownTabletsAreNotDeleted) {
   cluster_->master()->mutable_flags()->push_back(
       "--catalog_manager_delete_orphaned_tablets");
   ASSERT_OK(cluster_->master()->Restart());
-  SleepFor(MonoDelta::FromSeconds(2));
-  ASSERT_OK(cluster_->tablet_server(0)->GetInt64Metric(
-      &METRIC_ENTITY_server, "kudu.tabletserver",
-      
&METRIC_handler_latency_kudu_tserver_TabletServerAdminService_DeleteTablet,
-      "total_count", &num_delete_attempts));
-  ASSERT_EQ(1, num_delete_attempts);
+  AssertEventually([&]() {
+    ASSERT_OK(cluster_->tablet_server(0)->GetInt64Metric(
+        &METRIC_ENTITY_server, "kudu.tabletserver",
+        
&METRIC_handler_latency_kudu_tserver_TabletServerAdminService_DeleteTablet,
+        "total_count", &num_delete_attempts));
+    ASSERT_EQ(1, num_delete_attempts);
+  });
 
 }
 

Reply via email to