From 5a19bf45ae72c70b62c73999948ae4cb7ceb54ad Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Mon, 23 Jan 2023 11:07:53 -0800 Subject: [PATCH 1/3] Clean up integration test for GetSessionId. --- analytics/integration_test/src/integration_test.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/analytics/integration_test/src/integration_test.cc b/analytics/integration_test/src/integration_test.cc index a78ea6f08b..df8a6b5f93 100644 --- a/analytics/integration_test/src/integration_test.cc +++ b/analytics/integration_test/src/integration_test.cc @@ -128,6 +128,9 @@ TEST_F(FirebaseAnalyticsTest, TestGetSessionID) { FLAKY_TEST_SECTION_BEGIN(); #endif // TARGET_OS_IPHONE + // Give Analytics a moment to initialize and create a session. + ProcessEvents(1000); + future = firebase::analytics::GetSessionId(); WaitForCompletion(future, "GetSessionId"); From a8f01e64400c9559b2ac902080532713791cfa5e Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Mon, 23 Jan 2023 11:03:43 -0800 Subject: [PATCH 2/3] Don't output a bad session ID. --- analytics/integration_test/src/integration_test.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/analytics/integration_test/src/integration_test.cc b/analytics/integration_test/src/integration_test.cc index 787754b07f..df8a6b5f93 100644 --- a/analytics/integration_test/src/integration_test.cc +++ b/analytics/integration_test/src/integration_test.cc @@ -140,7 +140,9 @@ TEST_F(FirebaseAnalyticsTest, TestGetSessionID) { EXPECT_TRUE(future.result() != nullptr); EXPECT_NE(*future.result(), static_cast(0L)); - LogInfo("Got session ID: %" PRId64, *future.result()); + if (future.result() != nullptr) { + LogInfo("Got session ID: %" PRId64, *future.result()); + } } TEST_F(FirebaseAnalyticsTest, TestSetConsent) { From f150c33c76e3e940832c789fc3737945bb481b4d Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Mon, 23 Jan 2023 11:47:25 -0800 Subject: [PATCH 3/3] Change retry to all platforms. --- .../integration_test/src/integration_test.cc | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/analytics/integration_test/src/integration_test.cc b/analytics/integration_test/src/integration_test.cc index df8a6b5f93..f9d6ff2d24 100644 --- a/analytics/integration_test/src/integration_test.cc +++ b/analytics/integration_test/src/integration_test.cc @@ -113,30 +113,25 @@ TEST_F(FirebaseAnalyticsTest, TestGetSessionID) { #if defined(__ANDROID__) if (did_test_setconsent_) { LogInfo( - "Skipping TestGetSessionID after TestSetConsent, as it will fail until " - "the app is restarted."); + "Skipping TestGetSessionID after TestSetConsent, as GetSessionId() " + "will fail until the app is restarted."); GTEST_SKIP(); return; } #endif firebase::Future future; - // It can take Analytics a moment to initialize on iOS. - // So on iOS/tvOS, retry this test if GetSessionId returns an - // error. -#if TARGET_OS_IPHONE - FLAKY_TEST_SECTION_BEGIN(); -#endif // TARGET_OS_IPHONE - // Give Analytics a moment to initialize and create a session. ProcessEvents(1000); + // It can take Analytics even more time to initialize and create a session, so + // retry GetSessionId() if it returns an error. + FLAKY_TEST_SECTION_BEGIN(); + future = firebase::analytics::GetSessionId(); WaitForCompletion(future, "GetSessionId"); -#if TARGET_OS_IPHONE FLAKY_TEST_SECTION_END(); -#endif // TARGET_OS_IPHONE EXPECT_TRUE(future.result() != nullptr); EXPECT_NE(*future.result(), static_cast(0L));