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

Unified Diff: net/ssl/server_bound_cert_service_unittest.cc

Issue 22702003: Fix leak of sequenced worker pool in unit tests when service_ is replaced. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments improved Created 7 years, 4 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: net/ssl/server_bound_cert_service_unittest.cc
diff --git a/net/ssl/server_bound_cert_service_unittest.cc b/net/ssl/server_bound_cert_service_unittest.cc
index 0063f496036854c4c3a1ae2be4cbc1dea394ae66..f1d45d03e0d082abba4b9c89f6e2523b7c09cae2 100644
--- a/net/ssl/server_bound_cert_service_unittest.cc
+++ b/net/ssl/server_bound_cert_service_unittest.cc
@@ -536,7 +536,16 @@ TEST_F(ServerBoundCertServiceTest, AsyncStoreGetNoCertsInStore) {
EXPECT_FALSE(private_key_info.empty());
EXPECT_FALSE(der_cert.empty());
EXPECT_FALSE(request_handle.is_active());
-}
+
+ // Wait for any posted ServerBoundCertServiceWorkers to finish, in order to
+ // ensure that the workers are cleared by the time service_'s destructor is
+ // called. This prevents a leak of the SequencedWorkerPool, which by default
+ // continues on shutdown. (By calling
+ // CallGetServerBoundCertCallbackWithResult, callbacks are called directly,
+ // short-circuiting ServerBoundCertService's usual bookkeeping, so existing
+ // tasks must be both cleared and waited for to ensure proper memory freeing.)
+ sequenced_worker_pool_->FlushForTesting();
Ryan Sleevi 2013/08/09 00:45:10 I can't help but keep reading this comment and cod
juanlang 2013/08/09 04:48:52 Yeah, that big comment should have been a clue to
juanlang 2013/08/09 16:25:28 Yep, PostTask is the right thing here. Thanks. I d
+ base::MessageLoop::current()->RunUntilIdle(); }
TEST_F(ServerBoundCertServiceTest, AsyncStoreGetOneCertInStore) {
MockServerBoundCertStoreWithAsyncGet* mock_store =
@@ -560,7 +569,6 @@ TEST_F(ServerBoundCertServiceTest, AsyncStoreGetOneCertInStore) {
mock_store->CallGetServerBoundCertCallbackWithResult(
OK, base::Time(), "ab", "cd");
-
error = callback.WaitForResult();
EXPECT_EQ(OK, error);
EXPECT_EQ(1, service_->cert_count());
@@ -572,6 +580,16 @@ TEST_F(ServerBoundCertServiceTest, AsyncStoreGetOneCertInStore) {
EXPECT_STREQ("ab", private_key_info.c_str());
EXPECT_STREQ("cd", der_cert.c_str());
EXPECT_FALSE(request_handle.is_active());
+
+ // Wait for any posted ServerBoundCertServiceWorkers to finish, in order to
+ // ensure that the workers are cleared by the time service_'s destructor is
+ // called. This prevents a leak of the SequencedWorkerPool, which by default
+ // continues on shutdown. (By calling
+ // CallGetServerBoundCertCallbackWithResult, callbacks are called directly,
+ // short-circuiting ServerBoundCertService's usual bookkeeping, so existing
+ // tasks must be both cleared and waited for to ensure proper memory freeing.)
+ sequenced_worker_pool_->FlushForTesting();
+ base::MessageLoop::current()->RunUntilIdle(); }
}
#endif // !defined(USE_OPENSSL)
« 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