Skip to content

Reduce number of RewardedAd loads on iOS in CI #1180

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

Merged
merged 6 commits into from
Jan 3, 2023
Merged
Changes from 3 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
109 changes: 33 additions & 76 deletions gma/integration_test/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -778,19 +778,13 @@ TEST_F(FirebaseGmaTest, TestAdViewLoadAd) {
firebase::Future<firebase::gma::AdResult> load_ad_future;
const firebase::gma::AdResult* result_ptr = nullptr;

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

Copy link
Contributor Author

@DellaBitta DellaBitta Jan 3, 2023

Choose a reason for hiding this comment

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

The flakiness stemmed from NoFill error when the service runs out of Ads to serve. Being in a state of NoFill often takes a lot longer to recover from than our Flaky Test retry timeout, and so the flaky test block causes more problems than it solves by 1: retesting and getting the same result, and 2: pushing the service into backoff mode if too many NoFill errors are generated.

load_ad_future = ad_view->LoadAd(GetAdRequest());
WaitForCompletion(load_ad_future, "LoadAd");

result_ptr = load_ad_future.result();
ASSERT_NE(result_ptr, nullptr);
EXPECT_TRUE(result_ptr->is_successful());

FLAKY_TEST_SECTION_END();

ASSERT_NE(result_ptr, nullptr);
EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty());
EXPECT_FALSE(
Expand All @@ -811,10 +805,6 @@ TEST_F(FirebaseGmaTest, TestInterstitialAdLoad) {
SKIP_TEST_ON_DESKTOP;
SKIP_TEST_ON_SIMULATOR;

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

firebase::gma::InterstitialAd* interstitial =
new firebase::gma::InterstitialAd();

Expand All @@ -837,18 +827,12 @@ TEST_F(FirebaseGmaTest, TestInterstitialAdLoad) {

load_ad_future.Release();
delete interstitial;

FLAKY_TEST_SECTION_END();
}

TEST_F(FirebaseGmaTest, TestRewardedAdLoad) {
SKIP_TEST_ON_DESKTOP;
SKIP_TEST_ON_SIMULATOR;

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd();

WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()),
Expand All @@ -870,8 +854,6 @@ TEST_F(FirebaseGmaTest, TestRewardedAdLoad) {

load_ad_future.Release();
delete rewarded;

FLAKY_TEST_SECTION_END();
}

// Interactive test section. These have been placed up front so that the
Expand Down Expand Up @@ -1011,6 +993,9 @@ TEST_F(FirebaseGmaUITest, TestRewardedAdLoadAndShow) {
SKIP_TEST_ON_DESKTOP;
SKIP_TEST_ON_SIMULATOR;

// TODO(@drsanta): remove when GMA whitelists CI devices.
TEST_REQUIRES_USER_INTERACTION_ON_IOS;

firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd();

WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()),
Expand Down Expand Up @@ -1093,18 +1078,12 @@ TEST_F(FirebaseGmaTest, TestAdViewLoadAdEmptyAdRequest) {
firebase::Future<firebase::gma::AdResult> load_ad_future;
const firebase::gma::AdResult* result_ptr = nullptr;

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

load_ad_future = ad_view->LoadAd(request);
WaitForCompletion(load_ad_future, "LoadAd");
result_ptr = load_ad_future.result();
ASSERT_NE(result_ptr, nullptr);
EXPECT_TRUE(result_ptr->is_successful());

FLAKY_TEST_SECTION_END();

EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty());
EXPECT_FALSE(
result_ptr->response_info().mediation_adapter_class_name().empty());
Expand Down Expand Up @@ -1133,14 +1112,8 @@ TEST_F(FirebaseGmaTest, TestAdViewLoadAdAnchorAdaptiveAd) {
kBannerAdUnit, banner_ad_size),
"Initialize");

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

WaitForCompletion(ad_view->LoadAd(GetAdRequest()), "LoadAd");

FLAKY_TEST_SECTION_END();

const AdSize ad_size = ad_view->ad_size();
EXPECT_EQ(ad_size.width(), kBannerWidth);
EXPECT_NE(ad_size.height(), 0);
Expand All @@ -1163,14 +1136,8 @@ TEST_F(FirebaseGmaTest, TestAdViewLoadAdInlineAdaptiveAd) {
kBannerAdUnit, banner_ad_size),
"Initialize");

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

WaitForCompletion(ad_view->LoadAd(GetAdRequest()), "LoadAd");

FLAKY_TEST_SECTION_END();

const AdSize ad_size = ad_view->ad_size();
EXPECT_EQ(ad_size.width(), kBannerWidth);
EXPECT_NE(ad_size.height(), 0);
Expand All @@ -1192,14 +1159,8 @@ TEST_F(FirebaseGmaTest, TestAdViewLoadAdGetInlineAdaptiveBannerMaxHeight) {
kBannerAdUnit, banner_ad_size),
"Initialize");

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

WaitForCompletion(ad_view->LoadAd(GetAdRequest()), "LoadAd");

FLAKY_TEST_SECTION_END();

const AdSize ad_size = ad_view->ad_size();
EXPECT_EQ(ad_size.width(), kBannerWidth);
EXPECT_NE(ad_size.height(), 0);
Expand All @@ -1219,15 +1180,7 @@ TEST_F(FirebaseGmaTest, TestAdViewLoadAdDestroyNotCalled) {
WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(),
kBannerAdUnit, banner_ad_size),
"Initialize");

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

WaitForCompletion(ad_view->LoadAd(GetAdRequest()), "LoadAd");

FLAKY_TEST_SECTION_END();

delete ad_view;
}

Expand Down Expand Up @@ -1305,10 +1258,6 @@ TEST_F(FirebaseGmaTest, TestAdView) {
SKIP_TEST_ON_DESKTOP;
SKIP_TEST_ON_SIMULATOR;

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

const firebase::gma::AdSize banner_ad_size(kBannerWidth, kBannerHeight);
firebase::gma::AdView* ad_view = new firebase::gma::AdView();
WaitForCompletion(ad_view->Initialize(app_framework::GetWindowContext(),
Expand Down Expand Up @@ -1504,8 +1453,6 @@ TEST_F(FirebaseGmaTest, TestAdView) {
bounding_box_listener.bounding_box_changes_.back().height == -1);
#endif // defined(ANDROID) || TARGET_OS_IPHONE
}

FLAKY_TEST_SECTION_END();
}

TEST_F(FirebaseGmaTest, TestAdViewErrorNotInitialized) {
Expand Down Expand Up @@ -1674,10 +1621,6 @@ TEST_F(FirebaseGmaTest, TestInterstitialAdLoadEmptyRequest) {
SKIP_TEST_ON_DESKTOP;
SKIP_TEST_ON_SIMULATOR;

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();

firebase::gma::InterstitialAd* interstitial =
new firebase::gma::InterstitialAd();

Expand All @@ -1701,8 +1644,6 @@ TEST_F(FirebaseGmaTest, TestInterstitialAdLoadEmptyRequest) {
EXPECT_FALSE(result_ptr->response_info().ToString().empty());

delete interstitial;

FLAKY_TEST_SECTION_END();
}

TEST_F(FirebaseGmaTest, TestInterstitialAdErrorNotInitialized) {
Expand Down Expand Up @@ -1851,9 +1792,8 @@ TEST_F(FirebaseGmaTest, TestRewardedAdLoadEmptyRequest) {
SKIP_TEST_ON_DESKTOP;
SKIP_TEST_ON_SIMULATOR;

// Loading Ads has been deemed flaky as the AdMob Service has a chance to
// return NoFill for valid ad requests if there aren't any ads to serve.
FLAKY_TEST_SECTION_BEGIN();
// TODO(@drsanta): remove when GMA whitelists CI devices.
TEST_REQUIRES_USER_INTERACTION_ON_IOS;

// Note: while showing an ad requires user interaction in another test,
// this test is mean as a baseline loadAd functionality test.
Expand All @@ -1878,8 +1818,6 @@ TEST_F(FirebaseGmaTest, TestRewardedAdLoadEmptyRequest) {
EXPECT_FALSE(result_ptr->response_info().ToString().empty());

delete rewarded;

FLAKY_TEST_SECTION_END();
}

TEST_F(FirebaseGmaTest, TestRewardedAdErrorNotInitialized) {
Expand Down Expand Up @@ -1938,6 +1876,9 @@ TEST_F(FirebaseGmaTest, TesRewardedAdErrorAlreadyInitialized) {
TEST_F(FirebaseGmaTest, TestRewardedAdErrorLoadInProgress) {
SKIP_TEST_ON_DESKTOP;

// TODO(@drsanta): remove when GMA whitelists CI devices.
TEST_REQUIRES_USER_INTERACTION_ON_IOS;

firebase::gma::RewardedAd* rewarded = new firebase::gma::RewardedAd();
WaitForCompletion(rewarded->Initialize(app_framework::GetWindowContext()),
"Initialize");
Expand Down Expand Up @@ -2029,10 +1970,16 @@ TEST_F(FirebaseGmaTest, TestAdViewStress) {

// Load the AdView ad.
firebase::gma::AdRequest request = GetAdRequest();
WaitForCompletion(ad_view->LoadAd(request), "TestAdViewStress LoadAd");
EXPECT_EQ(ad_view->ad_size().width(), kBannerWidth);
EXPECT_EQ(ad_view->ad_size().height(), kBannerHeight);

firebase::Future<firebase::gma::AdResult> future = ad_view->LoadAd(request);
WaitForCompletionAnyResult(future, "TestAdViewStress LoadAd");
// Stress tests may exhaust the ad pool. If so, loadAd will return
// kAdErrorCodeNoFill.
EXPECT_TRUE(future.error() == firebase::gma::kAdErrorCodeNone ||
future.error() == firebase::gma::kAdErrorCodeNoFill);
if (future.error() == firebase::gma::kAdErrorCodeNone) {
EXPECT_EQ(ad_view->ad_size().width(), kBannerWidth);
EXPECT_EQ(ad_view->ad_size().height(), kBannerHeight);
}
WaitForCompletion(ad_view->Destroy(), "Destroy the AdView");
delete ad_view;
}
Expand All @@ -2055,8 +2002,13 @@ TEST_F(FirebaseGmaTest, TestInterstitialAdStress) {

// When the InterstitialAd is initialized, load an ad.
firebase::gma::AdRequest request = GetAdRequest();
WaitForCompletion(interstitial->LoadAd(kInterstitialAdUnit, request),
"TestInterstitialAdStress LoadAd");
firebase::Future<firebase::gma::AdResult> future =
interstitial->LoadAd(kInterstitialAdUnit, request);
WaitForCompletionAnyResult(future, "TestInterstitialAdStress LoadAd");
// Stress tests may exhaust the ad pool. If so, loadAd will return
// kAdErrorCodeNoFill.
EXPECT_TRUE(future.error() == firebase::gma::kAdErrorCodeNone ||
future.error() == firebase::gma::kAdErrorCodeNoFill);
delete interstitial;
}
}
Expand All @@ -2065,7 +2017,7 @@ TEST_F(FirebaseGmaTest, TestRewardedAdStress) {
SKIP_TEST_ON_DESKTOP;
SKIP_TEST_ON_EMULATOR;

// TODO(@drsanta): remove when GMA whitelists CI devices
// TODO(@drsanta): remove when GMA whitelists CI devices.
TEST_REQUIRES_USER_INTERACTION_ON_IOS;

for (int i = 0; i < 10; ++i) {
Expand All @@ -2076,8 +2028,13 @@ TEST_F(FirebaseGmaTest, TestRewardedAdStress) {

// When the RewardedAd is initialized, load an ad.
firebase::gma::AdRequest request = GetAdRequest();
WaitForCompletion(rewarded->LoadAd(kRewardedAdUnit, request),
"TestRewardedAdStress LoadAd");
firebase::Future<firebase::gma::AdResult> future =
rewarded->LoadAd(kRewardedAdUnit, request);
WaitForCompletionAnyResult(future, "TestRewardedAdStress LoadAd");
// Stress tests may exhaust the ad pool. If so, loadAd will return
// kAdErrorCodeNoFill.
EXPECT_TRUE(future.error() == firebase::gma::kAdErrorCodeNone ||
future.error() == firebase::gma::kAdErrorCodeNoFill);
delete rewarded;
}
}
Expand Down