Commit 7a492861 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Fix flake in some CloudPolicyTest tests after SimpleURLLoader conversion in r571184.

There was a race condition when the policy fetch request that's initiated in CloudPolicyTest::SetUpOnMainThread is cancelled becauase the test bodies start their own request (through RefreshPolicies). The first request seems to get the python test server in a bad state and it stops responding to requests afterwards.

The fix is to skip issuing the first request by temporarily unregistering CloudPolicyRefreshScheduler.

TBR=pmarko

Bug: 858883
Change-Id: I8c158ab3dffc2f38a7712a6806f9b8d28efbcfdb
Reviewed-on: https://chromium-review.googlesource.com/1119628
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571402}
parent a22f3171
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "components/policy/core/browser/browser_policy_connector.h" #include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/cloud/cloud_policy_client.h" #include "components/policy/core/common/cloud/cloud_policy_client.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h" #include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_client.h" #include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "components/policy/core/common/external_data_fetcher.h" #include "components/policy/core/common/external_data_fetcher.h"
#include "components/policy/core/common/policy_map.h" #include "components/policy/core/common/policy_map.h"
...@@ -235,6 +236,19 @@ class CloudPolicyTest : public InProcessBrowserTest, ...@@ -235,6 +236,19 @@ class CloudPolicyTest : public InProcessBrowserTest,
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
ASSERT_TRUE(policy_manager->core()->client()); ASSERT_TRUE(policy_manager->core()->client());
// The registration below will trigger a policy refresh (see
// CloudPolicyRefreshScheduler::OnRegistrationStateChanged). When the tests
// below call RefreshPolicies(), the first policy request will be cancelled
// (see CloudPolicyClient::FetchPolicy which will reset
// |policy_fetch_request_job_|). When the URLLoader implementation sees the
// SimpleURLLoader going away, it'll cancel it's request as well. This race
// sometimes causes errors in the Python policy server (|test_server_|).
// Work around this by removing the refresh scheduler as an observer
// temporarily.
policy_manager->core()->client()->RemoveObserver(
policy_manager->core()->refresh_scheduler());
base::RunLoop run_loop; base::RunLoop run_loop;
MockCloudPolicyClientObserver observer; MockCloudPolicyClientObserver observer;
EXPECT_CALL(observer, OnRegistrationStateChanged(_)).WillOnce( EXPECT_CALL(observer, OnRegistrationStateChanged(_)).WillOnce(
...@@ -260,6 +274,11 @@ class CloudPolicyTest : public InProcessBrowserTest, ...@@ -260,6 +274,11 @@ class CloudPolicyTest : public InProcessBrowserTest,
policy_manager->core()->client()->RemoveObserver(&observer); policy_manager->core()->client()->RemoveObserver(&observer);
EXPECT_TRUE(policy_manager->core()->client()->is_registered()); EXPECT_TRUE(policy_manager->core()->client()->is_registered());
// Readd the refresh scheduler as an observer now that the first policy
// fetch finished.
policy_manager->core()->client()->AddObserver(
policy_manager->core()->refresh_scheduler());
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Get the path to the user policy key file. // Get the path to the user policy key file.
base::FilePath user_policy_key_dir; base::FilePath user_policy_key_dir;
......
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