@@ -107,6 +107,8 @@ class FirebaseMessagingTest : public FirebaseTest {
107107 bool WaitForMessage (firebase::messaging::Message* message_out,
108108 int timeout = kTimeoutSeconds );
109109
110+ const std::string* shared_token () { return shared_token_; }
111+
110112 protected:
111113 static firebase::App* shared_app_;
112114 static firebase::messaging::PollableListener* shared_listener_;
@@ -487,23 +489,31 @@ TEST_F(FirebaseMessagingTest, TestSendMessageToToken) {
487489
488490 EXPECT_TRUE (RequestPermission ());
489491 EXPECT_TRUE (WaitForToken ());
490- std::string unique_id = GetUniqueMessageId ();
491- const char kNotificationTitle [] = " Token Test" ;
492- const char kNotificationBody [] = " Token Test notification body" ;
493- SendTestMessage (shared_token_->c_str (), kNotificationTitle , kNotificationBody ,
494- {{" message" , " Hello, world!" },
495- {" unique_id" , unique_id},
496- {kNotificationLinkKey , kTestLink }});
497- LogDebug (" Waiting for message." );
498- firebase::messaging::Message message;
499- EXPECT_TRUE (WaitForMessage (&message));
500- EXPECT_EQ (message.data [" unique_id" ], unique_id);
501- EXPECT_NE (message.notification , nullptr );
502- if (message.notification ) {
503- EXPECT_EQ (message.notification ->title , kNotificationTitle );
504- EXPECT_EQ (message.notification ->body , kNotificationBody );
492+ if (!RunFlakyBlock (
493+ [](FirebaseMessagingTest* this_) {
494+ std::string unique_id = this_->GetUniqueMessageId ();
495+ const char kNotificationTitle [] = " Token Test" ;
496+ const char kNotificationBody [] = " Token Test notification body" ;
497+ this_->SendTestMessage (this_->shared_token ()->c_str (),
498+ kNotificationTitle , kNotificationBody ,
499+ {{" message" , " Hello, world!" },
500+ {" unique_id" , unique_id},
501+ {kNotificationLinkKey , kTestLink }});
502+ LogDebug (" Waiting for message." );
503+ firebase::messaging::Message message;
504+ FLAKY_EXPECT_TRUE (this_->WaitForMessage (&message));
505+ FLAKY_EXPECT_EQ (message.data [" unique_id" ], unique_id);
506+ FLAKY_EXPECT_NOTNULL (message.notification );
507+ if (message.notification ) {
508+ FLAKY_EXPECT_EQ (message.notification ->title , kNotificationTitle );
509+ FLAKY_EXPECT_EQ (message.notification ->body , kNotificationBody );
510+ }
511+ FLAKY_EXPECT_EQ (message.link , kTestLink );
512+ return true ;
513+ },
514+ this )) {
515+ FAIL () << " Test failed, check error log for details." ;
505516 }
506- EXPECT_EQ (message.link , kTestLink );
507517}
508518
509519TEST_F (FirebaseMessagingTest, TestSendMessageToTopic) {
0 commit comments