Commit 18da217b authored by Yue Ru Sun's avatar Yue Ru Sun Committed by Commit Bot

Fix flaky UKM browser tests

Bug: 996823
Change-Id: I74170c9ce3008e40c280d0b7ccb58ffc10793364
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1784878Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Yue Ru Sun <yrsun@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695648}
parent b8c5c6cb
...@@ -206,7 +206,12 @@ class UkmBrowserTestBase : public SyncTest { ...@@ -206,7 +206,12 @@ class UkmBrowserTestBase : public SyncTest {
void BuildAndStoreUkmLog() { void BuildAndStoreUkmLog() {
auto* service = ukm_service(); auto* service = ukm_service();
DCHECK(service); DCHECK(service);
// Wait for initialization to complete before flushing.
base::RunLoop run_loop;
service->SetInitializationCompleteCallbackForTesting(run_loop.QuitClosure());
run_loop.Run();
DCHECK(service->initialize_complete_); DCHECK(service->initialize_complete_);
service->Flush(); service->Flush();
DCHECK(service->reporting_service_.ukm_log_store()->has_unsent_logs()); DCHECK(service->reporting_service_.ukm_log_store()->has_unsent_logs());
} }
...@@ -540,13 +545,7 @@ IN_PROC_BROWSER_TEST_P(UkmBrowserTest, OpenNonSyncCheck) { ...@@ -540,13 +545,7 @@ IN_PROC_BROWSER_TEST_P(UkmBrowserTest, OpenNonSyncCheck) {
// Keep in sync with UkmTest.testMetricConsent in // Keep in sync with UkmTest.testMetricConsent in
// chrome/android/javatests/src/org/chromium/chrome/browser/sync/ // chrome/android/javatests/src/org/chromium/chrome/browser/sync/
// UkmTest.java. // UkmTest.java.
#if defined(OS_CHROMEOS) IN_PROC_BROWSER_TEST_P(UkmBrowserTest, MetricsConsentCheck) {
// TODO(https://crbug.com/996823): Re-enable this test.
#define MAYBE_MetricsConsentCheck DISABLED_MetricsConsentCheck
#else
#define MAYBE_MetricsConsentCheck MetricsConsentCheck
#endif
IN_PROC_BROWSER_TEST_P(UkmBrowserTest, MAYBE_MetricsConsentCheck) {
MetricsConsentOverride metrics_consent(true); MetricsConsentOverride metrics_consent(true);
Profile* profile = ProfileManager::GetActiveUserProfile(); Profile* profile = ProfileManager::GetActiveUserProfile();
...@@ -576,13 +575,7 @@ IN_PROC_BROWSER_TEST_P(UkmBrowserTest, MAYBE_MetricsConsentCheck) { ...@@ -576,13 +575,7 @@ IN_PROC_BROWSER_TEST_P(UkmBrowserTest, MAYBE_MetricsConsentCheck) {
CloseBrowserSynchronously(sync_browser); CloseBrowserSynchronously(sync_browser);
} }
#if defined(OS_CHROMEOS) IN_PROC_BROWSER_TEST_P(UkmBrowserTest, LogProtoData) {
// TODO(https://crbug.com/996823): Re-enable this test.
#define MAYBE_LogProtoData DISABLED_LogProtoData
#else
#define MAYBE_LogProtoData LogProtoData
#endif
IN_PROC_BROWSER_TEST_P(UkmBrowserTest, MAYBE_LogProtoData) {
MetricsConsentOverride metrics_consent(true); MetricsConsentOverride metrics_consent(true);
Profile* profile = ProfileManager::GetActiveUserProfile(); Profile* profile = ProfileManager::GetActiveUserProfile();
...@@ -622,16 +615,7 @@ IN_PROC_BROWSER_TEST_P(UkmBrowserTest, MAYBE_LogProtoData) { ...@@ -622,16 +615,7 @@ IN_PROC_BROWSER_TEST_P(UkmBrowserTest, MAYBE_LogProtoData) {
// Verifies that network provider attaches effective connection type correctly // Verifies that network provider attaches effective connection type correctly
// to the UKM report. // to the UKM report.
#if defined(OS_CHROMEOS) IN_PROC_BROWSER_TEST_P(UkmBrowserTest, NetworkProviderPopulatesSystemProfile) {
// TODO(https://crbug.com/996823): Re-enable this test.
#define MAYBE_NetworkProviderPopulatesSystemProfile \
DISABLED_NetworkProviderPopulatesSystemProfile
#else
#define MAYBE_NetworkProviderPopulatesSystemProfile \
NetworkProviderPopulatesSystemProfile
#endif
IN_PROC_BROWSER_TEST_P(UkmBrowserTest,
MAYBE_NetworkProviderPopulatesSystemProfile) {
// Override network quality to 2G. This should cause the // Override network quality to 2G. This should cause the
// |max_effective_connection_type| in the system profile to be set to 2G. // |max_effective_connection_type| in the system profile to be set to 2G.
g_browser_process->network_quality_tracker() g_browser_process->network_quality_tracker()
......
...@@ -225,6 +225,9 @@ void UkmService::FinishedInitTask() { ...@@ -225,6 +225,9 @@ void UkmService::FinishedInitTask() {
DVLOG(1) << "UkmService::FinishedInitTask"; DVLOG(1) << "UkmService::FinishedInitTask";
initialize_complete_ = true; initialize_complete_ = true;
scheduler_->InitTaskComplete(); scheduler_->InitTaskComplete();
if (initialization_complete_callback_) {
std::move(initialization_complete_callback_).Run();
}
} }
void UkmService::RotateLog() { void UkmService::RotateLog() {
...@@ -268,4 +271,13 @@ bool UkmService::ShouldRestrictToWhitelistedEntries() const { ...@@ -268,4 +271,13 @@ bool UkmService::ShouldRestrictToWhitelistedEntries() const {
return restrict_to_whitelist_entries_; return restrict_to_whitelist_entries_;
} }
void UkmService::SetInitializationCompleteCallbackForTesting(base::OnceClosure callback) {
if (initialize_complete_) {
std::move(callback).Run();
} else {
// Store the callback to be invoked when initialization is complete later.
initialization_complete_callback_ = std::move(callback);
}
}
} // namespace ukm } // namespace ukm
...@@ -121,6 +121,8 @@ class UkmService : public UkmRecorderImpl { ...@@ -121,6 +121,8 @@ class UkmService : public UkmRecorderImpl {
// ukm::UkmRecorderImpl: // ukm::UkmRecorderImpl:
bool ShouldRestrictToWhitelistedEntries() const override; bool ShouldRestrictToWhitelistedEntries() const override;
void SetInitializationCompleteCallbackForTesting(base::OnceClosure callback);
// A weak pointer to the PrefService used to read and write preferences. // A weak pointer to the PrefService used to read and write preferences.
PrefService* pref_service_; PrefService* pref_service_;
...@@ -154,6 +156,9 @@ class UkmService : public UkmRecorderImpl { ...@@ -154,6 +156,9 @@ class UkmService : public UkmRecorderImpl {
bool initialize_started_ = false; bool initialize_started_ = false;
bool initialize_complete_ = false; bool initialize_complete_ = false;
// A callback invoked when initialization of the service is complete.
base::OnceClosure initialization_complete_callback_;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
// Weak pointers factory used to post task on different threads. All weak // Weak pointers factory used to post task on different threads. All weak
......
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