Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Unified Diff: base/test/test_suite.cc

Issue 10735063: Create an AtExitManager around each test, to take care of stray singletons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/test_suite.cc
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc
index 05a6069ba22a25720da254f8188b813f51b4b482..1a123118d6501aa492da3f35defdb594e105120c 100644
--- a/base/test/test_suite.cc
+++ b/base/test/test_suite.cc
@@ -81,32 +81,66 @@ class TestWatchAtExitManager : public testing::EmptyTestEventListener {
TestWatchAtExitManager() { }
~TestWatchAtExitManager() { }
- virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE {
+ virtual void OnTestCaseStart(const testing::TestCase& /*test_case*/) {
initial_top_manager_ = AtExitManager::current();
at_exit_stack_size_ = initial_top_manager_->CallbackStackSize();
+ per_test_case_manager_.reset(new base::AtExitManager);
}
- virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
+ virtual void OnTestCaseEnd(const testing::TestCase& test_case) {
AtExitManager* new_top_manager = AtExitManager::current();
+ if (per_test_case_manager_.get() != new_top_manager) {
+ ADD_FAILURE()
+ << "The current AtExitManager has changed across the test case "
+ << test_case.name() << " most likely because one was created in "
+ << "setting up the test case without being destroyed.";
+ }
+ per_test_case_manager_.reset();
+
+ new_top_manager = AtExitManager::current();
size_t new_stack_size = new_top_manager->CallbackStackSize();
if (initial_top_manager_ != new_top_manager) {
- ADD_FAILURE() << "The current AtExitManager has changed across the "
- "test " << test_info.test_case_name() << "." << test_info.name() <<
- " most likely because one was created without being destroyed.";
+ ADD_FAILURE()
+ << "Clearing the per test case AtExitManager did not restore the "
+ << "original AtExitManager to the top of the stack, indicating that "
+ << "the testing AtExitManager stack was corrupted while running the "
+ << "test case " << test_case.name() << ".";
} else if (new_stack_size != at_exit_stack_size_) {
- // TODO(scottbyer): clean up all the errors that result from this and
- // turn this into a test failure with
- // ADD_FAILURE(). http://crbug.com/133403
- LOG(WARNING) <<
- "AtExitManager: items were added to the callback list by " <<
- test_info.test_case_name() << "." << test_info.name() <<
- ". Global state should be cleaned up before a test exits.";
+ ADD_FAILURE()
+ << "Items were added to the original AtExitManager callback list "
+ << "while running the test case " << test_case.name() << ".";
+ }
+ }
+
+ virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE {
+ per_test_manager_.reset(new base::AtExitManager);
+ }
+
+ virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
+ AtExitManager* new_top_manager = AtExitManager::current();
+ if (per_test_manager_.get() != new_top_manager) {
+ ADD_FAILURE()
+ << "The current AtExitManager has changed across the test "
+ << test_info.test_case_name() << "." << test_info.name()
+ << " most likely because one was created without being destroyed.";
+ }
+ per_test_manager_.reset();
+
+ new_top_manager = AtExitManager::current();
+ if (per_test_case_manager_.get() != new_top_manager) {
+ ADD_FAILURE()
+ << "Clearing the per test AtExitManager did not restore the test "
+ << "case AtExitManager to the top of the stack, indicating that the "
+ << "testing AtExitManager stack was corrupted while running the test "
+ << test_info.test_case_name() << "." << test_info.name() << ".";
}
}
private:
AtExitManager* initial_top_manager_;
+ scoped_ptr<base::AtExitManager> per_test_case_manager_;
+ scoped_ptr<base::AtExitManager> per_test_manager_;
size_t at_exit_stack_size_;
DISALLOW_COPY_AND_ASSIGN(TestWatchAtExitManager);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698