You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2017/06/16 21:44:00 UTC
[2/3] kudu git commit: Make AssertEventually compatible with
--gtest_break_on_failure
Make AssertEventually compatible with --gtest_break_on_failure
ASSERT_EVENTUALLY(...) works by suppressing assertion failures for a
certain number of retries until the specified assertions eventually
succeed. With gtest_break_on_failure, the failed assertions would cause
the test to crash even though they were expected.
Tested with subprocess-test --gtest_break_on_failure
Change-Id: I8e5299c2bb200420cf5ecf6aea8e13d2e44a1e43
Reviewed-on: http://gerrit.cloudera.org:8080/7212
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <as...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/5808e6d9
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/5808e6d9
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/5808e6d9
Branch: refs/heads/master
Commit: 5808e6d9fe2ef278cef2b6bd6b87a43d8f69d82d
Parents: 722f803
Author: Todd Lipcon <to...@apache.org>
Authored: Fri Jun 16 13:53:56 2017 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Jun 16 21:27:19 2017 +0000
----------------------------------------------------------------------
src/kudu/util/test_util.cc | 53 +++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/5808e6d9/src/kudu/util/test_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/test_util.cc b/src/kudu/util/test_util.cc
index 50c80c6..af809a7 100644
--- a/src/kudu/util/test_util.cc
+++ b/src/kudu/util/test_util.cc
@@ -32,6 +32,7 @@
#include "kudu/util/env.h"
#include "kudu/util/path_util.h"
#include "kudu/util/random.h"
+#include "kudu/util/scoped_cleanup.h"
#include "kudu/util/spinlock_profiling.h"
DEFINE_string(test_leave_files, "on_failure",
@@ -224,28 +225,38 @@ string GetTestDataDirectory() {
void AssertEventually(const std::function<void(void)>& f,
const MonoDelta& timeout) {
const MonoTime deadline = MonoTime::Now() + timeout;
-
- for (int attempts = 0; MonoTime::Now() < deadline; attempts++) {
- // Capture any assertion failures within this scope (i.e. from their function)
- // into 'results'
- testing::TestPartResultArray results;
- testing::ScopedFakeTestPartResultReporter reporter(
- testing::ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
- &results);
- f();
-
- // Determine whether their function produced any new test failure results.
- bool has_failures = false;
- for (int i = 0; i < results.size(); i++) {
- has_failures |= results.GetTestPartResult(i).failed();
- }
- if (!has_failures) {
- return;
+ {
+ // Disable --gtest_break_on_failure, or else the assertion failures
+ // inside our attempts will cause the test to SEGV even though we
+ // would like to retry.
+ bool old_break_on_failure = testing::FLAGS_gtest_break_on_failure;
+ auto c = MakeScopedCleanup([old_break_on_failure]() {
+ testing::FLAGS_gtest_break_on_failure = old_break_on_failure;
+ });
+ testing::FLAGS_gtest_break_on_failure = false;
+
+ for (int attempts = 0; MonoTime::Now() < deadline; attempts++) {
+ // Capture any assertion failures within this scope (i.e. from their function)
+ // into 'results'
+ testing::TestPartResultArray results;
+ testing::ScopedFakeTestPartResultReporter reporter(
+ testing::ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
+ &results);
+ f();
+
+ // Determine whether their function produced any new test failure results.
+ bool has_failures = false;
+ for (int i = 0; i < results.size(); i++) {
+ has_failures |= results.GetTestPartResult(i).failed();
+ }
+ if (!has_failures) {
+ return;
+ }
+
+ // If they had failures, sleep and try again.
+ int sleep_ms = (attempts < 10) ? (1 << attempts) : 1000;
+ SleepFor(MonoDelta::FromMilliseconds(sleep_ms));
}
-
- // If they had failures, sleep and try again.
- int sleep_ms = (attempts < 10) ? (1 << attempts) : 1000;
- SleepFor(MonoDelta::FromMilliseconds(sleep_ms));
}
// If we ran out of time looping, run their function one more time