Commit e049fdf5 authored by Ben Kelly's avatar Ben Kelly Committed by Commit Bot

CacheStorage: Attempt to deflake VerifySerialScheduling unit test.

We saw a flake on fuschia where DelayedBackend.OpenEntryContinue()
failed.  The only way I can see this happening is if we get to disable
the delayed mode before the OpenEntry() is actually called.

This CL tries to avoid this condition by explicitly waiting for
OpenEntry() to be called before proceeding with the rest of the test.

Bug: 928368
Change-Id: I782fab81605524ee2bd7126fd78ebc4416825f9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1698131
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677117}
parent d5d39c65
...@@ -128,6 +128,8 @@ class DelayableBackend : public disk_cache::Backend { ...@@ -128,6 +128,8 @@ class DelayableBackend : public disk_cache::Backend {
open_entry_callback_ = base::BindOnce( open_entry_callback_ = base::BindOnce(
&DelayableBackend::OpenEntryDelayedImpl, base::Unretained(this), key, &DelayableBackend::OpenEntryDelayedImpl, base::Unretained(this), key,
base::Unretained(entry), std::move(callback)); base::Unretained(entry), std::move(callback));
if (open_entry_started_callback_)
std::move(open_entry_started_callback_).Run();
return net::ERR_IO_PENDING; return net::ERR_IO_PENDING;
} }
return backend_->OpenEntry(key, request_priority, entry, return backend_->OpenEntry(key, request_priority, entry,
...@@ -192,6 +194,11 @@ class DelayableBackend : public disk_cache::Backend { ...@@ -192,6 +194,11 @@ class DelayableBackend : public disk_cache::Backend {
void set_delay_open_entry(bool value) { delay_open_entry_ = value; } void set_delay_open_entry(bool value) { delay_open_entry_ = value; }
void set_open_entry_started_callback(
base::OnceClosure open_entry_started_callback) {
open_entry_started_callback_ = std::move(open_entry_started_callback);
}
private: private:
void OpenEntryDelayedImpl(const std::string& key, void OpenEntryDelayedImpl(const std::string& key,
disk_cache::Entry** entry, disk_cache::Entry** entry,
...@@ -206,6 +213,7 @@ class DelayableBackend : public disk_cache::Backend { ...@@ -206,6 +213,7 @@ class DelayableBackend : public disk_cache::Backend {
std::unique_ptr<disk_cache::Backend> backend_; std::unique_ptr<disk_cache::Backend> backend_;
bool delay_open_entry_; bool delay_open_entry_;
base::OnceClosure open_entry_callback_; base::OnceClosure open_entry_callback_;
base::OnceClosure open_entry_started_callback_;
}; };
class DataPipeDrainerClient : public mojo::DataPipeDrainer::Client { class DataPipeDrainerClient : public mojo::DataPipeDrainer::Client {
...@@ -2298,6 +2306,10 @@ TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) { ...@@ -2298,6 +2306,10 @@ TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) {
DelayableBackend* delayable_backend = cache_->UseDelayableBackend(); DelayableBackend* delayable_backend = cache_->UseDelayableBackend();
delayable_backend->set_delay_open_entry(true); delayable_backend->set_delay_open_entry(true);
base::RunLoop open_started_loop;
delayable_backend->set_open_entry_started_callback(
open_started_loop.QuitClosure());
int sequence_out = -1; int sequence_out = -1;
blink::mojom::BatchOperationPtr operation1 = blink::mojom::BatchOperationPtr operation1 =
...@@ -2317,8 +2329,9 @@ TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) { ...@@ -2317,8 +2329,9 @@ TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) {
close_loop1.get()), close_loop1.get()),
CacheStorageCache::BadMessageCallback()); CacheStorageCache::BadMessageCallback());
// Blocks on creating the cache entry. // Wait until the first operation attempts to open the entry and becomes
base::RunLoop().RunUntilIdle(); // delayed.
open_started_loop.Run();
blink::mojom::BatchOperationPtr operation2 = blink::mojom::BatchOperationPtr operation2 =
blink::mojom::BatchOperation::New(); blink::mojom::BatchOperation::New();
...@@ -2340,7 +2353,7 @@ TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) { ...@@ -2340,7 +2353,7 @@ TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) {
// The second put operation should wait for the first to complete. // The second put operation should wait for the first to complete.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(callback_response_); EXPECT_EQ(-1, sequence_out);
EXPECT_TRUE(delayable_backend->OpenEntryContinue()); EXPECT_TRUE(delayable_backend->OpenEntryContinue());
close_loop1->Run(); close_loop1->Run();
......
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