Commit 2540a648 authored by Makoto Shimazu's avatar Makoto Shimazu Committed by Commit Bot

Deflake NetworkServiceRestartBrowserTests on slower bots

Previously ServiceWorkerObserver::WaitForState(STOPPED) starts to observe the
state when it's called, but sometimes it's too slow and restarting the worker is
already happening when starting to wait for state STOPPED. This CL fixes it by
keeping all state changes and returning from WaitForState() if the observer saw
the state previously at least once.

Bug: 889855
Change-Id: Ide180fa49c9f47f68e1482b9a368b386648a3d4e
Reviewed-on: https://chromium-review.googlesource.com/c/1337214Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608279}
parent 1f29016e
...@@ -116,8 +116,10 @@ void WaitForCondition(base::RepeatingCallback<bool()> condition) { ...@@ -116,8 +116,10 @@ void WaitForCondition(base::RepeatingCallback<bool()> condition) {
class ServiceWorkerStatusObserver : public ServiceWorkerContextCoreObserver { class ServiceWorkerStatusObserver : public ServiceWorkerContextCoreObserver {
public: public:
void WaitForState(EmbeddedWorkerStatus expected_status) { void WaitForState(EmbeddedWorkerStatus expected_status) {
if (latest_status_ == expected_status) for (const auto& status : statuses_in_past_) {
return; if (status == expected_status)
return;
}
expected_status_ = expected_status; expected_status_ = expected_status;
base::RunLoop loop; base::RunLoop loop;
...@@ -128,7 +130,7 @@ class ServiceWorkerStatusObserver : public ServiceWorkerContextCoreObserver { ...@@ -128,7 +130,7 @@ class ServiceWorkerStatusObserver : public ServiceWorkerContextCoreObserver {
private: private:
void OnRunningStateChanged(int64_t version_id, void OnRunningStateChanged(int64_t version_id,
EmbeddedWorkerStatus running_status) override { EmbeddedWorkerStatus running_status) override {
latest_status_ = running_status; statuses_in_past_.push_back(running_status);
if (expected_status_.has_value() && if (expected_status_.has_value() &&
running_status == expected_status_.value()) { running_status == expected_status_.value()) {
std::move(callback_).Run(); std::move(callback_).Run();
...@@ -136,7 +138,7 @@ class ServiceWorkerStatusObserver : public ServiceWorkerContextCoreObserver { ...@@ -136,7 +138,7 @@ class ServiceWorkerStatusObserver : public ServiceWorkerContextCoreObserver {
} }
base::Optional<EmbeddedWorkerStatus> expected_status_; base::Optional<EmbeddedWorkerStatus> expected_status_;
EmbeddedWorkerStatus latest_status_; std::vector<EmbeddedWorkerStatus> statuses_in_past_;
base::OnceClosure callback_; base::OnceClosure callback_;
}; };
...@@ -692,20 +694,10 @@ IN_PROC_BROWSER_TEST_F(NetworkServiceRestartBrowserTest, MultipleWorkerFetch) { ...@@ -692,20 +694,10 @@ IN_PROC_BROWSER_TEST_F(NetworkServiceRestartBrowserTest, MultipleWorkerFetch) {
EXPECT_EQ(last_request_relative_url(), "/title2.html"); EXPECT_EQ(last_request_relative_url(), "/title2.html");
} }
// Flaky on Linux TSan and Android ASan (https://crbug.com/889855)
#if (defined(OS_LINUX) && defined(THREAD_SANITIZER)) || \
(defined(OS_ANDROID) && defined(ADDRESS_SANITIZER))
#define MAYBE_FetchFromServiceWorkerControlledPage_NoFetchHandler \
DISABLED_FetchFromServiceWorkerControlledPage_NoFetchHandler
#else
#define MAYBE_FetchFromServiceWorkerControlledPage_NoFetchHandler \
FetchFromServiceWorkerControlledPage_NoFetchHandler
#endif
// Make sure fetch from a page controlled by a service worker which doesn't have // Make sure fetch from a page controlled by a service worker which doesn't have
// a fetch handler works after crash. // a fetch handler works after crash.
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(NetworkServiceRestartBrowserTest,
NetworkServiceRestartBrowserTest, FetchFromServiceWorkerControlledPage_NoFetchHandler) {
MAYBE_FetchFromServiceWorkerControlledPage_NoFetchHandler) {
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
BrowserContext::GetDefaultStoragePartition(browser_context())); BrowserContext::GetDefaultStoragePartition(browser_context()));
ServiceWorkerStatusObserver observer; ServiceWorkerStatusObserver observer;
...@@ -743,19 +735,10 @@ IN_PROC_BROWSER_TEST_F( ...@@ -743,19 +735,10 @@ IN_PROC_BROWSER_TEST_F(
service_worker_context->RemoveObserver(&observer); service_worker_context->RemoveObserver(&observer);
} }
// Flaky on Linux TSan and Android ASan (https://crbug.com/889855)
#if (defined(OS_LINUX) && defined(THREAD_SANITIZER)) || \
(defined(OS_ANDROID) && defined(ADDRESS_SANITIZER))
#define MAYBE_FetchFromServiceWorkerControlledPage_PassThrough \
DISABLED_FetchFromServiceWorkerControlledPage_PassThrough
#else
#define MAYBE_FetchFromServiceWorkerControlledPage_PassThrough \
FetchFromServiceWorkerControlledPage_PassThrough
#endif
// Make sure fetch from a page controlled by a service worker which has a fetch // Make sure fetch from a page controlled by a service worker which has a fetch
// handler but falls back to the network works after crash. // handler but falls back to the network works after crash.
IN_PROC_BROWSER_TEST_F(NetworkServiceRestartBrowserTest, IN_PROC_BROWSER_TEST_F(NetworkServiceRestartBrowserTest,
MAYBE_FetchFromServiceWorkerControlledPage_PassThrough) { FetchFromServiceWorkerControlledPage_PassThrough) {
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
BrowserContext::GetDefaultStoragePartition(browser_context())); BrowserContext::GetDefaultStoragePartition(browser_context()));
ServiceWorkerStatusObserver observer; ServiceWorkerStatusObserver observer;
...@@ -793,20 +776,10 @@ IN_PROC_BROWSER_TEST_F(NetworkServiceRestartBrowserTest, ...@@ -793,20 +776,10 @@ IN_PROC_BROWSER_TEST_F(NetworkServiceRestartBrowserTest,
service_worker_context->RemoveObserver(&observer); service_worker_context->RemoveObserver(&observer);
} }
// Flaky on Linux TSan and Android ASan (https://crbug.com/889855)
#if (defined(OS_LINUX) && defined(THREAD_SANITIZER)) || \
(defined(OS_ANDROID) && defined(ADDRESS_SANITIZER))
#define MAYBE_FetchFromServiceWorkerControlledPage_RespondWithFetch \
DISABLED_FetchFromServiceWorkerControlledPage_RespondWithFetch
#else
#define MAYBE_FetchFromServiceWorkerControlledPage_RespondWithFetch \
FetchFromServiceWorkerControlledPage_RespondWithFetch
#endif
// Make sure fetch from a page controlled by a service worker which has a fetch // Make sure fetch from a page controlled by a service worker which has a fetch
// handler and responds with fetch() works after crash. // handler and responds with fetch() works after crash.
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(NetworkServiceRestartBrowserTest,
NetworkServiceRestartBrowserTest, FetchFromServiceWorkerControlledPage_RespondWithFetch) {
MAYBE_FetchFromServiceWorkerControlledPage_RespondWithFetch) {
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
BrowserContext::GetDefaultStoragePartition(browser_context())); BrowserContext::GetDefaultStoragePartition(browser_context()));
ServiceWorkerStatusObserver observer; ServiceWorkerStatusObserver observer;
......
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