Mark some Fledge tests as @FlakyTest

Mark some tests as flaky because we need more time to deep dive them.

Bug: 315521295
Bug: 304766178
Bug: 304764127
Change-Id: If910f1f37865306afd09e05a05795d3390084388
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionE2ETest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionE2ETest.java
index 032ef2a..cb96ee9 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionE2ETest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionE2ETest.java
@@ -962,6 +962,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304764127)
     public void testRunAdSelectionSuccess_preV3BiddingLogicWithAdCostCpcBillingEnabled()
             throws Exception {
         AdSelectionE2ETestFlags flagsWithCPCEnabled =
@@ -1233,6 +1234,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304764127)
     public void testRunAdSelectionSuccess_preV3BiddingLogicWithDataVersionHeaderFlagDisabled()
             throws Exception {
         AdSelectionE2ETestFlags flagsWithDataVersionHeaderEnabled =
@@ -1374,6 +1376,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304764127)
     public void testRunAdSelectionSuccess_preV3BiddingLogicWinnerWithoutBuyerDataVersionHeader()
             throws Exception {
         AdSelectionE2ETestFlags flagsWithDataVersionHeaderEnabled =
@@ -1496,6 +1499,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304764127)
     public void testRunAdSelectionSuccess_preV3BiddingLogicWithAdCostCpcBillingDisabled()
             throws Exception {
         AdSelectionE2ETestFlags flagsWithCPCDisabled =
@@ -3430,6 +3434,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304764127)
     public void testRunAdSelectionOnlyContextualAds_NoCAsNoNetworkCall_Success() throws Exception {
         doReturn(new AdSelectionE2ETestFlags()).when(FlagsFactory::getFlags);
         // Logger calls come after the callback is returned
@@ -3520,6 +3525,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testRunAdSelectionNoContextualAds_NoCAs_Failure() throws Exception {
         doReturn(new AdSelectionE2ETestFlags()).when(FlagsFactory::getFlags);
         // Logger calls come after the callback is returned
@@ -4013,6 +4019,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304764127)
     public void testRunAdSelectionMultipleCAsNoCachingSuccess_v3BiddingLogic() throws Exception {
         doReturn(new AdSelectionE2ETestFlags()).when(FlagsFactory::getFlags);
 
@@ -4383,6 +4390,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304764127)
     public void testRunAdSelectionSucceedsWithOverride_preV3BiddingLogic() throws Exception {
         doReturn(new AdSelectionE2ETestFlags()).when(FlagsFactory::getFlags);
         // Logger calls come after the callback is returned
@@ -4520,6 +4528,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304764127)
     public void testRunAdSelectionSucceedsWithOverride_v3BiddingLogic() throws Exception {
         doReturn(new AdSelectionE2ETestFlags()).when(FlagsFactory::getFlags);
         // Logger calls come after the callback is returned
@@ -6778,6 +6787,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testRunAdSelectionMissingScoringSignalsFailure() throws Exception {
         doReturn(new AdSelectionE2ETestFlags()).when(FlagsFactory::getFlags);
         // Logger calls come after the callback is returned
@@ -7290,6 +7300,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304764127)
     public void testRunAdSelectionThrottledSubsequentCallFailure() throws Exception {
         doReturn(FlagsFactory.getFlagsForTest()).when(FlagsFactory::getFlags);
 
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionFromOutcomesE2ETest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionFromOutcomesE2ETest.java
index 7841cb8..47e2550 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionFromOutcomesE2ETest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionFromOutcomesE2ETest.java
@@ -62,6 +62,7 @@
 
 import androidx.room.Room;
 import androidx.test.core.app.ApplicationProvider;
+import androidx.test.filters.FlakyTest;
 
 import com.android.adservices.MockWebServerRuleFactory;
 import com.android.adservices.common.SupportedByConditionRule;
@@ -441,6 +442,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testSelectAdsFromOutcomesPickHighestSuccessUnifiedTables() throws Exception {
         doReturn(new AdSelectionFromOutcomesE2ETest.TestFlags()).when(FlagsFactory::getFlags);
         MockWebServer server = mMockWebServerRule.startMockWebServer(mDispatcher);
@@ -685,6 +687,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testSelectAdsFromOutcomesWaterfallMalformedPrebuiltUriFailed() throws Exception {
         doReturn(new AdSelectionFromOutcomesE2ETest.TestFlags()).when(FlagsFactory::getFlags);
         MockWebServer server = mMockWebServerRule.startMockWebServer(mDispatcher);
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionScriptEngineTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionScriptEngineTest.java
index 795df45..5dcd38c 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionScriptEngineTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionScriptEngineTest.java
@@ -42,6 +42,7 @@
 import android.util.Log;
 
 import androidx.test.core.app.ApplicationProvider;
+import androidx.test.filters.FlakyTest;
 import androidx.test.filters.SmallTest;
 
 import com.android.adservices.LoggerFactory;
@@ -227,6 +228,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304766178)
     public void testAuctionScriptIsInvalidIfAnyRequiredFunctionDoesNotExist() throws Exception {
         assertFalse(
                 callJsValidation(
@@ -245,6 +247,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304766178)
     public void testCanCallScript() throws Exception {
         final AuctionScriptResult result =
                 callAuctionEngine(
@@ -260,6 +263,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testCanCallScriptRunWithCopier() throws Exception {
         final AuctionScriptResult result =
                 callAuctionEngine(
@@ -275,6 +279,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304766178)
     public void testThrowsJSExecutionExceptionIfTheFunctionIsNotFound() throws Exception {
         Exception exception =
                 Assert.assertThrows(
@@ -324,6 +329,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304766178)
     public void testGenerateBidSuccessfulCase() throws Exception {
         doNothing().when(mRunAdBiddingPerCAExecutionLoggerMock).startGenerateBids();
         // Logger calls come after the callback is returned
@@ -361,6 +367,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testGenerateBidWithAdCostSuccessfulCaseCpcBillingEnabled() throws Exception {
         // Reinit engine with cpc billing enabled
         mAdSelectionScriptEngine =
@@ -513,6 +520,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304766178)
     public void testGenerateBidWithCopierSuccessfulCase() throws Exception {
         mAdSelectionScriptEngine =
                 new AdSelectionScriptEngine(
@@ -656,6 +664,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testGenerateBidV3WithCopierSuccessfulCase() throws Exception {
         mAdSelectionScriptEngine =
                 new AdSelectionScriptEngine(
@@ -716,6 +725,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testGenerateBidV3WithCopierWithAdCounterKeysSuccessfulCase() throws Exception {
         mAdSelectionScriptEngine =
                 new AdSelectionScriptEngine(
@@ -804,6 +814,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304766178)
     public void testGenerateBidBackwardCompatCaseSuccess() throws Exception {
         doNothing().when(mRunAdBiddingPerCAExecutionLoggerMock).startGenerateBids();
         // Logger calls come after the callback is returned
@@ -943,6 +954,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304766178)
     public void testGenerateBidBackwardCompatCaseException() throws Exception {
         final String incompatibleVersionOfJS =
                 "function generateBids(ad, auction_signals, per_buyer_signals,"
@@ -1633,6 +1645,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304766178)
     public void testCanRunScriptWithStringInterpolationTokenInIt() throws Exception {
         final AuctionScriptResult result =
                 callAuctionEngine(
@@ -1648,6 +1661,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 304766178)
     public void testEncodeSignals()
             throws ExecutionException, InterruptedException, TimeoutException {
         List<String> seeds = List.of("SignalsA", "SignalsB");
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionServiceImplTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionServiceImplTest.java
index 05c4b06..48cd932 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionServiceImplTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdSelectionServiceImplTest.java
@@ -106,6 +106,7 @@
 
 import androidx.room.Room;
 import androidx.test.core.app.ApplicationProvider;
+import androidx.test.filters.FlakyTest;
 
 import com.android.adservices.LoggerFactory;
 import com.android.adservices.MockWebServerRuleFactory;
@@ -670,6 +671,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportImpressionSuccessfullyReportsDataVersionHeader() throws Exception {
         Assume.assumeTrue(JSScriptEngine.AvailabilityChecker.isJSSandboxAvailable());
 
@@ -808,6 +810,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportImpressionSuccessfullyReportsSellerDataVersionHeader() throws Exception {
         Assume.assumeTrue(JSScriptEngine.AvailabilityChecker.isJSSandboxAvailable());
 
@@ -933,6 +936,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportImpressionSuccessWithRegisterAdBeaconEnabled() throws Exception {
         Assume.assumeTrue(JSScriptEngine.AvailabilityChecker.isJSSandboxAvailable());
 
@@ -1613,6 +1617,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportImpressionSuccessAndDoesNotCrashAfterBuyerReportThrowsAnException()
             throws Exception {
         Assume.assumeTrue(JSScriptEngine.AvailabilityChecker.isJSSandboxAvailable());
@@ -2986,6 +2991,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void
             testReportImpressionSucceedsButDesNotRegisterUrisWithInteractionKeySizeThatExceedsMax()
                     throws Exception {
@@ -6268,6 +6274,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportImpressionSucceedsWhenAdTechPassesEnrollmentCheck() throws Exception {
         Assume.assumeTrue(JSScriptEngine.AvailabilityChecker.isJSSandboxAvailable());
 
@@ -6494,6 +6501,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportImpressionSuccessThrottledSubsequentCallFailure() throws Exception {
         Assume.assumeTrue(JSScriptEngine.AvailabilityChecker.isJSSandboxAvailable());
         Uri sellerReportingUri = mMockWebServerRule.uriForPath(mSellerReportingPath);
@@ -6626,6 +6634,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportImpressionDoestNotReportWhenUrisDoNotMatchDomain() throws Exception {
         Assume.assumeTrue(JSScriptEngine.AvailabilityChecker.isJSSandboxAvailable());
         // Instantiate a server with different domain from buyer and seller for reporting
@@ -6967,6 +6976,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportImpressionSuccessWithValidImpressionReportingSubdomains()
             throws Exception {
         Assume.assumeTrue(JSScriptEngine.AvailabilityChecker.isJSSandboxAvailable());
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/ReportImpressionScriptEngineTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/ReportImpressionScriptEngineTest.java
index cb5f9e1..9e2771e 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/ReportImpressionScriptEngineTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/ReportImpressionScriptEngineTest.java
@@ -31,6 +31,7 @@
 import android.util.Log;
 
 import androidx.test.core.app.ApplicationProvider;
+import androidx.test.filters.FlakyTest;
 import androidx.test.filters.SmallTest;
 
 import com.android.adservices.common.SupportedByConditionRule;
@@ -140,6 +141,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testCanCallScript() throws Exception {
         ImmutableList.Builder<JSScriptArgument> args = new ImmutableList.Builder<>();
         args.add(AD_DATA_ARGUMENT_UTIL.asScriptArgument("ignored", AD_DATA));
@@ -154,6 +156,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testThrowsJSExecutionExceptionIfFunctionNotFound() throws Exception {
         ImmutableList.Builder<JSScriptArgument> args = new ImmutableList.Builder<>();
         args.add(AD_DATA_ARGUMENT_UTIL.asScriptArgument("ignored", AD_DATA));
@@ -172,6 +175,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testThrowsIllegalStateExceptionIfScriptIsNotReturningJson() throws Exception {
         ImmutableList.Builder<JSScriptArgument> args = new ImmutableList.Builder<>();
         args.add(AD_DATA_ARGUMENT_UTIL.asScriptArgument("ignored", AD_DATA));
@@ -239,6 +243,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportResultSuccessfulCaseWithMoreResultsFieldsThanExpected() throws Exception {
         String jsScript =
                 "function reportResult(ad_selection_config, render_uri, bid, contextual_signals) {"
@@ -331,6 +336,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportResultFailsInvalidInteractionKeyType() throws Exception {
         String jsScript =
                 "function reportResult(ad_selection_config, render_uri, bid, contextual_signals)"
@@ -359,6 +365,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportResultFailsInvalidInteractionReportingUriType() throws Exception {
         String jsScript =
                 "function reportResult(ad_selection_config, render_uri, bid, contextual_signals)"
@@ -417,6 +424,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportResultFailsWhenRegisterAdBeaconInputNotAnObject__Null() throws Exception {
         String jsScript =
                 "function reportResult(ad_selection_config, render_uri, bid, contextual_signals)"
@@ -444,6 +452,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportResultFailsWhenRegisterAdBeaconInputNotAnObject__Int() throws Exception {
         String jsScript =
                 "function reportResult(ad_selection_config, render_uri, bid, contextual_signals)"
@@ -823,6 +832,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportWinFailsInvalidInteractionKeyType() throws Exception {
         String jsScript =
                 "function reportWin(ad_selection_signals, per_buyer_signals, signals_for_buyer ,"
@@ -851,6 +861,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportWinFailsInvalidInteractionReportingUriType() throws Exception {
         String jsScript =
                 "function reportWin(ad_selection_signals, per_buyer_signals, signals_for_buyer ,"
@@ -879,6 +890,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void testReportWinFailsWhenRegisterAdBeaconCalledMoreThanOnce() throws Exception {
         String jsScript =
                 "function reportWin(ad_selection_signals, per_buyer_signals, signals_for_buyer"
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/TrustedServerAdSelectionRunnerTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/TrustedServerAdSelectionRunnerTest.java
index bef10c0..f0cfbaa 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/TrustedServerAdSelectionRunnerTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/TrustedServerAdSelectionRunnerTest.java
@@ -40,6 +40,7 @@
 import android.os.Process;
 
 import androidx.test.core.app.ApplicationProvider;
+import androidx.test.filters.FlakyTest;
 
 import com.android.adservices.common.SupportedByConditionRule;
 import com.android.adservices.common.WebViewSupportUtil;
@@ -431,6 +432,7 @@
     }
 
     @Test
+    @FlakyTest(bugId = 315521295)
     public void verifyNoRequestCompressionWhenFlagDisabled() {
         Flags flags =
                 new Flags() {