You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2013/10/09 20:38:04 UTC
[2/3] git commit: Fixed tests to not leak temporary directories.
Fixed tests to not leak temporary directories.
Review: https://reviews.apache.org/r/14506
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/7b973369
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/7b973369
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/7b973369
Branch: refs/heads/master
Commit: 7b973369a6a0e8baf7ad6f4f8651482583f9439b
Parents: 8077ad4
Author: Vinod Kone <vi...@twitter.com>
Authored: Fri Oct 4 16:38:22 2013 -0700
Committer: Vinod Kone <vi...@twitter.com>
Committed: Wed Oct 9 11:18:41 2013 -0700
----------------------------------------------------------------------
src/tests/environment.cpp | 31 ++++++++++++++++++-------------
src/tests/environment.hpp | 5 +++--
2 files changed, 21 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/7b973369/src/tests/environment.cpp
----------------------------------------------------------------------
diff --git a/src/tests/environment.cpp b/src/tests/environment.cpp
index bf62bcf..6edce45 100644
--- a/src/tests/environment.cpp
+++ b/src/tests/environment.cpp
@@ -192,18 +192,6 @@ Environment::Environment()
}
-Environment::~Environment()
-{
- foreach (const string& directory, directories) {
- Try<Nothing> rmdir = os::rmdir(directory);
- if (rmdir.isError()) {
- LOG(ERROR) << "Failed to remove '" << directory
- << "': " << rmdir.error();
- }
- }
-}
-
-
void Environment::SetUp()
{
// Clear any MESOS_ environment variables so they don't affect our tests.
@@ -237,6 +225,19 @@ void Environment::SetUp()
}
+void Environment::TearDown()
+{
+ foreach (const string& directory, directories) {
+ Try<Nothing> rmdir = os::rmdir(directory);
+ if (rmdir.isError()) {
+ LOG(ERROR) << "Failed to remove '" << directory
+ << "': " << rmdir.error();
+ }
+ }
+ directories.clear();
+}
+
+
Try<string> Environment::mkdtemp()
{
const ::testing::TestInfo* const testInfo =
@@ -264,7 +265,11 @@ Try<string> Environment::mkdtemp()
const string& path =
path::join("/tmp", strings::join("_", testCase, testName, "XXXXXX"));
- return os::mkdtemp(path);
+ Try<string> mkdtemp = os::mkdtemp(path);
+ if (mkdtemp.isSome()) {
+ directories.push_back(mkdtemp.get());
+ }
+ return mkdtemp;
}
} // namespace tests {
http://git-wip-us.apache.org/repos/asf/mesos/blob/7b973369/src/tests/environment.hpp
----------------------------------------------------------------------
diff --git a/src/tests/environment.hpp b/src/tests/environment.hpp
index 9acbe2f..02a897b 100644
--- a/src/tests/environment.hpp
+++ b/src/tests/environment.hpp
@@ -34,15 +34,16 @@ namespace tests {
class Environment : public ::testing::Environment {
public:
Environment();
- virtual ~Environment();
virtual void SetUp();
+ virtual void TearDown();
+
// Helper to create a temporary directory based on the current test
// case name and test name (derived from TestInfo via
// ::testing::UnitTest::GetInstance()->current_test_info()). Note
// that the directory will automagically get removed when the
- // environment instance gets destructed.
+ // environment is teared down.
Try<std::string> mkdtemp();
private: