You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jp...@apache.org on 2018/02/16 20:11:48 UTC
[2/4] mesos git commit: Adopted `TEST_AWAIT_TIMEOUT` in libprocess
tests.
Adopted `TEST_AWAIT_TIMEOUT` in libprocess tests.
Rather than hard-coding a 15sec test timeout, use the libprocess
`TEST_AWAIT_TIMEOUT` variable so that this can be globally tuned.
Added a test flag `--test_await_timeout` that can be used to set
the `TEST_AWAIT_TIMEOUT` on a test run.
Review: https://reviews.apache.org/r/65343/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cbcc903d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cbcc903d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cbcc903d
Branch: refs/heads/master
Commit: cbcc903d4edc2cb9b2a9c0a8f3205d6f1a547bea
Parents: 4261077
Author: James Peach <jp...@apache.org>
Authored: Fri Feb 16 11:37:17 2018 -0800
Committer: James Peach <jp...@apache.org>
Committed: Fri Feb 16 11:37:17 2018 -0800
----------------------------------------------------------------------
3rdparty/libprocess/src/tests/main.cpp | 48 +++++++++++++++++---
.../libprocess/src/tests/subprocess_tests.cpp | 28 +++++++-----
2 files changed, 57 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/cbcc903d/3rdparty/libprocess/src/tests/main.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/main.cpp b/3rdparty/libprocess/src/tests/main.cpp
index 4633bea..db94db6 100644
--- a/3rdparty/libprocess/src/tests/main.cpp
+++ b/3rdparty/libprocess/src/tests/main.cpp
@@ -12,6 +12,7 @@
#include <signal.h>
+#include <iostream>
#include <memory>
#include <string>
#include <vector>
@@ -27,7 +28,9 @@
#include <process/gtest.hpp>
#include <process/process.hpp>
+#include <stout/duration.hpp>
#include <stout/exit.hpp>
+#include <stout/flags.hpp>
#ifndef __WINDOWS__
#include <stout/os/signals.hpp>
@@ -35,6 +38,9 @@
#include <stout/tests/environment.hpp>
+using std::cerr;
+using std::cout;
+using std::endl;
using std::make_shared;
using std::shared_ptr;
using std::string;
@@ -46,18 +52,46 @@ using stout::internal::tests::TestFilter;
using std::shared_ptr;
using std::vector;
-// NOTE: We use RAW_LOG instead of LOG because RAW_LOG doesn't
-// allocate any memory or grab locks. And according to
-// https://code.google.com/p/google-glog/issues/detail?id=161
-// it should work in 'most' cases in signal handlers.
-inline void handler(int signal)
+namespace {
+
+class Flags : public virtual flags::FlagsBase
{
- RAW_LOG(FATAL, "Unexpected signal in signal handler: %d", signal);
-}
+public:
+ Flags()
+ {
+ add(&Flags::test_await_timeout,
+ "test_await_timeout",
+ "The default timeout for awaiting test events.",
+ process::TEST_AWAIT_TIMEOUT);
+ }
+
+ Duration test_await_timeout;
+};
+
+} // namespace {
int main(int argc, char** argv)
{
+ Flags flags;
+
+ // Load flags from environment and command line but allow unknown
+ // flags (since we might have gtest/gmock flags as well).
+ Try<flags::Warnings> load = flags.load("LIBPROCESS_", argc, argv, true);
+
+ if (flags.help) {
+ cout << flags.usage() << endl;
+ testing::InitGoogleMock(&argc, argv); // Get usage from gtest too.
+ return EXIT_SUCCESS;
+ }
+
+ if (load.isError()) {
+ cerr << flags.usage(load.error()) << endl;
+ return EXIT_FAILURE;
+ }
+
+ process::TEST_AWAIT_TIMEOUT = flags.test_await_timeout;
+
// Initialize Google Mock/Test.
testing::InitGoogleMock(&argc, argv);
http://git-wip-us.apache.org/repos/asf/mesos/blob/cbcc903d/3rdparty/libprocess/src/tests/subprocess_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/subprocess_tests.cpp b/3rdparty/libprocess/src/tests/subprocess_tests.cpp
index 8211ae6..ead5ded 100644
--- a/3rdparty/libprocess/src/tests/subprocess_tests.cpp
+++ b/3rdparty/libprocess/src/tests/subprocess_tests.cpp
@@ -619,18 +619,20 @@ TEST_F(SubprocessTest, Default)
#endif // __WINDOWS__
-struct Flags : public virtual flags::FlagsBase
+namespace {
+
+struct TestFlags : public virtual flags::FlagsBase
{
- Flags()
+ TestFlags()
{
- add(&Flags::b, "b", "bool");
- add(&Flags::i, "i", "int");
- add(&Flags::s, "s", "string");
- add(&Flags::s2, "s2", "string with single quote");
- add(&Flags::s3, "s3", "string with double quote");
- add(&Flags::d, "d", "Duration");
- add(&Flags::y, "y", "Bytes");
- add(&Flags::j, "j", "JSON::Object");
+ add(&TestFlags::b, "b", "bool");
+ add(&TestFlags::i, "i", "int");
+ add(&TestFlags::s, "s", "string");
+ add(&TestFlags::s2, "s2", "string with single quote");
+ add(&TestFlags::s3, "s3", "string with double quote");
+ add(&TestFlags::d, "d", "Duration");
+ add(&TestFlags::y, "y", "Bytes");
+ add(&TestFlags::j, "j", "JSON::Object");
}
Option<bool> b;
@@ -643,6 +645,8 @@ struct Flags : public virtual flags::FlagsBase
Option<JSON::Object> j;
};
+} // namespace {
+
// NOTE: These tests can't be run on Windows because the rely on functionality
// that does not exist on Windows. For example, `os::nonblock` will not work on
@@ -650,7 +654,7 @@ struct Flags : public virtual flags::FlagsBase
#ifndef __WINDOWS__
TEST_F(SubprocessTest, Flags)
{
- Flags flags;
+ TestFlags flags;
flags.b = true;
flags.i = 42;
flags.s = "hello";
@@ -714,7 +718,7 @@ TEST_F(SubprocessTest, Flags)
argv[i] = ::strdup(split[i - 1].c_str());
}
- Flags flags2;
+ TestFlags flags2;
Try<flags::Warnings> load = flags2.load(None(), argc, argv);
ASSERT_SOME(load);
EXPECT_TRUE(load->warnings.empty());