Commit 80e53817 authored by jkarlin's avatar jkarlin Committed by Commit bot

Flush SimpleCache worker pool between all tests.

This will prevent tests that utilize a SimpleCache from running into teardown leaks.

BUG=413688

Review URL: https://codereview.chromium.org/562203002

Cr-Commit-Position: refs/heads/master@{#296936}
parent 62f3270d
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "content/public/browser/browser_thread_delegate.h" #include "content/public/browser/browser_thread_delegate.h"
#include "net/disk_cache/simple/simple_backend_impl.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
...@@ -141,11 +142,12 @@ void BrowserThreadImpl::ShutdownThreadPool() { ...@@ -141,11 +142,12 @@ void BrowserThreadImpl::ShutdownThreadPool() {
} }
// static // static
void BrowserThreadImpl::FlushThreadPoolHelper() { void BrowserThreadImpl::FlushThreadPoolHelperForTesting() {
// We don't want to create a pool if none exists. // We don't want to create a pool if none exists.
if (g_globals == NULL) if (g_globals == NULL)
return; return;
g_globals.Get().blocking_pool->FlushForTesting(); g_globals.Get().blocking_pool->FlushForTesting();
disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
} }
void BrowserThreadImpl::Init() { void BrowserThreadImpl::Init() {
......
...@@ -61,7 +61,7 @@ class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread, ...@@ -61,7 +61,7 @@ class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread,
// For testing. // For testing.
friend class ContentTestSuiteBaseListener; friend class ContentTestSuiteBaseListener;
friend class TestBrowserThreadBundle; friend class TestBrowserThreadBundle;
static void FlushThreadPoolHelper(); static void FlushThreadPoolHelperForTesting();
// The identifier of this thread. Only one thread can exist with a given // The identifier of this thread. Only one thread can exist with a given
// identifier at a given time. // identifier at a given time.
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_context.h" #include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "net/disk_cache/simple/simple_backend_impl.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/blob/blob_storage_context.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -53,12 +52,6 @@ class ServiceWorkerCacheStorageManagerTest : public testing::Test { ...@@ -53,12 +52,6 @@ class ServiceWorkerCacheStorageManagerTest : public testing::Test {
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
base::RunLoop().RunUntilIdle();
cache_manager_.reset();
base::RunLoop().RunUntilIdle();
disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
base::RunLoop().RunUntilIdle();
} }
virtual bool MemoryOnly() { return false; } virtual bool MemoryOnly() { return false; }
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_context.h" #include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "net/disk_cache/simple/simple_backend_impl.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_job_factory_impl.h" #include "net/url_request/url_request_job_factory_impl.h"
...@@ -80,12 +79,6 @@ class ServiceWorkerCacheTest : public testing::Test { ...@@ -80,12 +79,6 @@ class ServiceWorkerCacheTest : public testing::Test {
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
base::RunLoop().RunUntilIdle();
cache_ = NULL;
base::RunLoop().RunUntilIdle();
disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
base::RunLoop().RunUntilIdle();
} }
void CreateRequests(ChromeBlobStorageContext* blob_storage_context) { void CreateRequests(ChromeBlobStorageContext* blob_storage_context) {
......
...@@ -44,7 +44,7 @@ class ContentTestSuiteBaseListener : public testing::EmptyTestEventListener { ...@@ -44,7 +44,7 @@ class ContentTestSuiteBaseListener : public testing::EmptyTestEventListener {
ContentTestSuiteBaseListener() { ContentTestSuiteBaseListener() {
} }
virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
BrowserThreadImpl::FlushThreadPoolHelper(); BrowserThreadImpl::FlushThreadPoolHelperForTesting();
} }
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentTestSuiteBaseListener); DISALLOW_COPY_AND_ASSIGN(ContentTestSuiteBaseListener);
......
...@@ -24,7 +24,7 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() { ...@@ -24,7 +24,7 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() {
// pool via PostTaskAndReply are able to reply back to the originating thread. // pool via PostTaskAndReply are able to reply back to the originating thread.
// Thus we must flush the blocking pool while the browser threads still exist. // Thus we must flush the blocking pool while the browser threads still exist.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
BrowserThreadImpl::FlushThreadPoolHelper(); BrowserThreadImpl::FlushThreadPoolHelperForTesting();
// To ensure a clean teardown, each thread's message loop must be flushed // To ensure a clean teardown, each thread's message loop must be flushed
// just before the thread is destroyed. But destroying a fake thread does not // just before the thread is destroyed. But destroying a fake thread does not
...@@ -46,7 +46,7 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() { ...@@ -46,7 +46,7 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() {
// This is the point at which we normally shut down the thread pool. So flush // This is the point at which we normally shut down the thread pool. So flush
// it again in case any shutdown tasks have been posted to the pool from the // it again in case any shutdown tasks have been posted to the pool from the
// threads above. // threads above.
BrowserThreadImpl::FlushThreadPoolHelper(); BrowserThreadImpl::FlushThreadPoolHelperForTesting();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ui_thread_.reset(); ui_thread_.reset();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment