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

Unified Diff: net/base/file_stream_unittest.cc

Issue 250783002: net: Make sure the FileStream file is closed on the worker thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use an explicit worker pool Created 6 years, 8 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 | « net/base/file_stream_context.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/file_stream_unittest.cc
diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc
index 75379e81ddb7d9c917f18850dd62ca157f1dc1cf..ecf9ea3b5957af6281fd6b15fa943f3a21f28190 100644
--- a/net/base/file_stream_unittest.cc
+++ b/net/base/file_stream_unittest.cc
@@ -14,6 +14,8 @@
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/test_timeouts.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "base/threading/thread_restrictions.h"
#include "net/base/capturing_net_log.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -757,8 +759,11 @@ TEST_F(FileStreamTest, AsyncWriteClose) {
}
TEST_F(FileStreamTest, AsyncOpenAndDelete) {
- scoped_ptr<FileStream> stream(
- new FileStream(base::MessageLoopProxy::current()));
+ scoped_refptr<base::SequencedWorkerPool> pool(
+ new base::SequencedWorkerPool(1, "StreamTest"));
+
+ bool prev = base::ThreadRestrictions::SetIOAllowed(false);
+ scoped_ptr<FileStream> stream(new FileStream(pool.get()));
int flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE |
base::File::FLAG_ASYNC;
TestCompletionCallback open_callback;
@@ -768,9 +773,20 @@ TEST_F(FileStreamTest, AsyncOpenAndDelete) {
// Delete the stream without waiting for the open operation to be
// complete. Should be safe.
stream.reset();
+
+ // Force an operation through the pool.
+ scoped_ptr<FileStream> stream2(new FileStream(pool.get()));
+ TestCompletionCallback open_callback2;
+ rv = stream2->Open(temp_file_path(), flags, open_callback2.callback());
+ EXPECT_EQ(OK, open_callback2.GetResult(rv));
+ stream2.reset();
+
+ pool->Shutdown();
+
// open_callback won't be called.
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(open_callback.have_result());
+ base::ThreadRestrictions::SetIOAllowed(prev);
}
// Verify that async Write() errors are mapped correctly.
« no previous file with comments | « net/base/file_stream_context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698