Skip to content

Commit 8e9b993

Browse files
authored
[ads] Fix intermittent Brave Ads integration tests hang (uplift to 1.94.x) (#39430)
Uplift of #39172 (squashed) to release
1 parent 2cd9e25 commit 8e9b993

4 files changed

Lines changed: 21 additions & 41 deletions

File tree

components/brave_ads/core/internal/account/deposits/cash_deposit_test.cc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "brave/components/brave_ads/core/internal/account/deposits/cash_deposit.h"
77

8-
#include "base/test/run_until.h"
98
#include "base/test/test_future.h"
109
#include "brave/components/brave_ads/core/internal/ad_units/test/ad_test_constants.h"
1110
#include "brave/components/brave_ads/core/internal/catalog/catalog_url_request_builder_util.h"
@@ -36,16 +35,11 @@ TEST_F(BraveAdsCashDepositIntegrationTest, GetValue) {
3635
CashDeposit deposit;
3736

3837
// Act & Assert
39-
ASSERT_TRUE(base::test::RunUntil([&] {
40-
base::test::TestFuture<bool, double> test_future;
41-
deposit.GetValue(test::kCreativeInstanceId, test_future.GetCallback());
42-
const auto [success, value] = test_future.Take();
43-
if (!success) {
44-
return false;
45-
}
46-
EXPECT_DOUBLE_EQ(test::kValue, value);
47-
return true;
48-
}));
38+
base::test::TestFuture<bool, double> test_future;
39+
deposit.GetValue(test::kCreativeInstanceId, test_future.GetCallback());
40+
const auto [success, value] = test_future.Take();
41+
EXPECT_TRUE(success);
42+
EXPECT_DOUBLE_EQ(test::kValue, value);
4943
}
5044

5145
TEST_F(BraveAdsCashDepositIntegrationTest,

components/brave_ads/core/internal/common/test/test_base.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ void TestBase::FlushImmediateTasks() {
373373
// sequence, even for fire-and-forget calls with `base::DoNothing`. Those
374374
// replies arrive with a 0ms delay and must be flushed so that callers see
375375
// only genuinely scheduled tasks.
376-
if (task_environment_.NextMainThreadPendingTaskDelay().is_zero()) {
377-
task_environment_.FastForwardBy(base::TimeDelta());
378-
}
376+
task_environment_.FastForwardBy(base::TimeDelta());
379377
}
380378

381379
} // namespace brave_ads::test

components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table_test.cc

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "brave/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table.h"
77

8-
#include "base/test/run_until.h"
98
#include "base/test/test_future.h"
109
#include "brave/components/brave_ads/core/internal/catalog/catalog_url_request_builder_util.h"
1110
#include "brave/components/brave_ads/core/internal/common/test/mock_test_util.h"
@@ -36,17 +35,12 @@ TEST_F(BraveAdsConversionsDatabaseTableIntegrationTest,
3635
const database::table::CreativeSetConversions database_table;
3736

3837
// Act & Assert
39-
ASSERT_TRUE(base::test::RunUntil([&] {
40-
base::test::TestFuture<bool, CreativeSetConversionList> test_future;
41-
database_table.GetUnexpired(
42-
test_future.GetCallback<bool, const CreativeSetConversionList&>());
43-
const auto [success, creative_set_conversions] = test_future.Take();
44-
if (!success || creative_set_conversions.empty()) {
45-
return false;
46-
}
47-
EXPECT_THAT(creative_set_conversions, ::testing::SizeIs(2));
48-
return true;
49-
}));
38+
base::test::TestFuture<bool, CreativeSetConversionList> test_future;
39+
database_table.GetUnexpired(
40+
test_future.GetCallback<bool, const CreativeSetConversionList&>());
41+
const auto [success, creative_set_conversions] = test_future.Take();
42+
EXPECT_TRUE(success);
43+
EXPECT_THAT(creative_set_conversions, ::testing::SizeIs(2));
5044
}
5145

5246
} // namespace brave_ads

components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table_test.cc

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "brave/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_table.h"
77

8-
#include "base/test/run_until.h"
98
#include "base/test/test_future.h"
109
#include "brave/components/brave_ads/core/internal/catalog/catalog_url_request_builder_util.h"
1110
#include "brave/components/brave_ads/core/internal/common/test/mock_test_util.h"
@@ -36,20 +35,15 @@ TEST_F(BraveAdsCreativeNotificationAdsDatabaseTableIntegrationTest,
3635
const database::table::CreativeNotificationAds database_table;
3736

3837
// Act & Assert
39-
ASSERT_TRUE(base::test::RunUntil([&] {
40-
base::test::TestFuture<bool, SegmentList, CreativeNotificationAdList>
41-
test_future;
42-
database_table.GetForSegments(
43-
/*segments=*/{"technology & computing"},
44-
test_future.GetCallback<bool, const SegmentList&,
45-
CreativeNotificationAdList>());
46-
const auto [success, segments, creative_ads] = test_future.Take();
47-
if (!success || creative_ads.empty()) {
48-
return false;
49-
}
50-
EXPECT_THAT(creative_ads, ::testing::SizeIs(2));
51-
return true;
52-
}));
38+
base::test::TestFuture<bool, SegmentList, CreativeNotificationAdList>
39+
test_future;
40+
database_table.GetForSegments(
41+
/*segments=*/{"technology & computing"},
42+
test_future
43+
.GetCallback<bool, const SegmentList&, CreativeNotificationAdList>());
44+
const auto [success, segments, creative_ads] = test_future.Take();
45+
EXPECT_TRUE(success);
46+
EXPECT_THAT(creative_ads, ::testing::SizeIs(2));
5347
}
5448

5549
} // namespace brave_ads

0 commit comments

Comments
 (0)