Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timing issue with ProcessPendingContributions browser test #5498

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ class BraveRewardsBrowserTest

void WaitForMultipleTipReconcileCompleted(int32_t needed) {
multiple_tip_reconcile_needed_ = needed;

// May have reached reconcile count before this function was ever
// called, check for that here
if (multiple_tip_reconcile_count_ == multiple_tip_reconcile_needed_) {
multiple_tip_reconcile_completed_ = true;
}

if (multiple_tip_reconcile_completed_) {
return;
}
Expand Down Expand Up @@ -945,9 +952,20 @@ class BraveRewardsBrowserTest
}

void RefreshPublisherListUsingRewardsPopup() const {
rewards_service_browsertest_utils::WaitForElementThenClick(
OpenRewardsPopup(),
"[data-test-id='unverified-check-button']");
// Refresh publisher list; assume that absence of refresh button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come publisher is already verified if we didn't click refresh yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding of the code the publisher list also updates on a timer, so sometimes the manual click isn't needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting so you thing that timer is causing problems

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the timer is kicking off the update and updating the server before there's any chance to click the button (at least on my local Windows machine). Once the rewards popup opens, there's no longer a "Refresh Status" button to click on because it's already updated to a verified publisher.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this happened because we don't send any end when doing pagination, so pagination will continue for 100 pages and because of that we have this race condition

// means that we're all set (i.e., publisher is already showing as
// verified)
content::WebContents* popup_contents = OpenRewardsPopup();
const std::string selector = "[data-test-id='unverified-check-button']";
bool result = rewards_service_browsertest_utils::
WaitForElementToAppearAndReturnResult(
popup_contents,
selector);
if (result) {
rewards_service_browsertest_utils::WaitForElementThenClick(
popup_contents,
selector);
}
}

content::WebContents* OpenSiteBanner(ContributionType banner_type) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ void WaitForElementToAppear(
content::WebContents* context,
const std::string& selector,
bool should_appear) {
bool result = WaitForElementToAppearAndReturnResult(
context,
selector);

ASSERT_EQ(should_appear, result);
}

bool WaitForElementToAppearAndReturnResult(
content::WebContents* context,
const std::string& selector) {
auto script = kWaitForElementToAppearScript +
content::JsReplace(R"(
new Promise(async (resolve, reject) => {
Expand All @@ -64,7 +74,7 @@ void WaitForElementToAppear(
content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
content::ISOLATED_WORLD_ID_CONTENT_END);

ASSERT_EQ(should_appear, result);
return result.ExtractBool();
}

void WaitForElementToEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ void WaitForElementToAppear(
const std::string& selector,
bool should_appear = true);

bool WaitForElementToAppearAndReturnResult(
content::WebContents* context,
const std::string& selector);

void WaitForElementToEqual(
content::WebContents*,
const std::string& selector,
Expand Down