@@ -147,30 +147,15 @@ TEST_F(FirebaseInstallationsTest, TestGettingIdTwiceMatches) {
147147 if (!RunFlakyBlock (
148148 [](firebase::installations::Installations* installations) {
149149 firebase::Future<std::string> id = installations->GetId ();
150- WaitForCompletionAnyResult (id, " GetId" );
151- if (id.error () != 0 ) {
152- LogError (" GetId returned error %d: %s" , id.error (),
153- id.error_message ());
154- return false ;
155- }
156- if (*id.result () == " " ) {
157- LogError (" GetId returned blank" );
158- return false ;
159- }
150+ FLAKY_WAIT_FOR_COMPLETION (id, " GetId" );
151+ FLAKY_EXPECT_NE (*id.result (), " " ); // ensure non-blank
160152 std::string first_id = *id.result ();
161153 id = installations->GetId ();
162- WaitForCompletionAnyResult (id, " GetId 2" );
163- if (id.error () != 0 ) {
164- LogError (" GetId 2 returned error %d: %s" , id.error (),
165- id.error_message ());
166- return false ;
167- }
168- if (*id.result () != first_id) {
169- LogError (
170- " GetId 2 returned non-matching ID: first(%s) vs second(%s)" ,
171- first_id.c_str (), id.result ()->c_str ());
172- return false ;
173- }
154+ FLAKY_WAIT_FOR_COMPLETION (id, " GetId 2" );
155+ FLAKY_EXPECT_NE (*id.result (), " " ); // ensure non-blank
156+
157+ // Ensure the second ID returned is the same as the first.
158+ FLAKY_EXPECT_EQ (*id.result (), first_id);
174159 return true ;
175160 },
176161 installations_)) {
@@ -182,47 +167,24 @@ TEST_F(FirebaseInstallationsTest, TestDeleteGivesNewIdNextTime) {
182167 if (!RunFlakyBlock (
183168 [](firebase::installations::Installations* installations) {
184169 firebase::Future<std::string> id = installations->GetId ();
185- WaitForCompletionAnyResult (id, " GetId" );
186- if (id.error () != 0 ) {
187- LogError (" GetId returned error %d: %s" , id.error (),
188- id.error_message ());
189- return false ;
190- }
191- if (*id.result () == " " ) {
192- LogError (" GetId returned blank" );
193- return false ;
194- }
170+ FLAKY_WAIT_FOR_COMPLETION (id, " GetId" );
171+ FLAKY_EXPECT_NE (*id.result (), " " ); // ensure non-blank
195172 std::string first_id = *id.result ();
196173
197174 firebase::Future<void > del = installations->Delete ();
198- WaitForCompletionAnyResult (del, " Delete" );
199- if (del.error () != 0 ) {
200- LogError (" Delete returned error %d: %s" , id.error (),
201- id.error_message ());
202- return false ;
203- }
175+ FLAKY_WAIT_FOR_COMPLETION (del, " Delete" );
204176
205177 // Ensure that we now get a different installations id.
206178 id = installations->GetId ();
207- WaitForCompletionAnyResult (id, " GetId 2" );
208- if (id.error () != 0 ) {
209- LogError (" GetId 2 returned error %d: %s" , id.error (),
210- id.error_message ());
211- return false ;
212- }
213- if (*id.result () == " " ) {
214- LogError (" GetId 2 returned blank" );
215- return false ;
216- }
179+ FLAKY_WAIT_FOR_COMPLETION (id, " GetId 2" );
180+ FLAKY_EXPECT_NE (*id.result (), " " ); // ensure non-blank
217181#if defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
218182 // Desktop is a stub and returns the same ID, but on mobile it
219183 // should return a new ID.
220- if (*id.result () == first_id) {
221- LogError (" IDs match (should be different): %s" , first_id.c_str ());
222- return false ;
223- }
184+ FLAKY_EXPECT_NE (*id.result (), first_id);
224185#endif // defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) &&
225186 // TARGET_OS_IPHONE)
187+
226188 return true ;
227189 },
228190 installations_)) {
@@ -237,34 +199,52 @@ TEST_F(FirebaseInstallationsTest, TestCanGetToken) {
237199}
238200
239201TEST_F (FirebaseInstallationsTest, TestGettingTokenTwiceMatches) {
240- firebase::Future<std::string> token = installations_->GetToken (false );
241- WaitForCompletion (token, " GetToken" );
242- EXPECT_NE (*token.result (), " " );
243- std::string first_token = *token.result ();
244- token = installations_->GetToken (false );
245- WaitForCompletion (token, " GetToken 2" );
246- EXPECT_EQ (*token.result (), first_token);
202+ if (!RunFlakyBlock (
203+ [](firebase::installations::Installations* installations) {
204+ firebase::Future<std::string> token =
205+ installations->GetToken (false );
206+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken" );
207+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
208+ std::string first_token = *token.result ();
209+ token = installations->GetToken (false );
210+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken 2" );
211+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
212+ FLAKY_EXPECT_EQ (*token.result (), first_token);
213+ return true ;
214+ },
215+ installations_)) {
216+ FAIL () << " Test failed, check error log for details." ;
217+ }
247218}
248219
249220TEST_F (FirebaseInstallationsTest, TestDeleteGivesNewTokenNextTime) {
250- firebase::Future<std::string> token = installations_->GetToken (false );
251- WaitForCompletion (token, " GetToken" );
252- EXPECT_NE (*token.result (), " " );
253- std::string first_token = *token.result ();
221+ if (!RunFlakyBlock (
222+ [](firebase::installations::Installations* installations) {
223+ firebase::Future<std::string> token =
224+ installations->GetToken (false );
225+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken" );
226+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
227+ std::string first_token = *token.result ();
254228
255- firebase::Future<void > del = installations_ ->Delete ();
256- WaitForCompletion (del, " Delete" );
229+ firebase::Future<void > del = installations ->Delete ();
230+ FLAKY_WAIT_FOR_COMPLETION (del, " Delete" );
257231
258- // Ensure that we now get a different installations token.
259- token = installations_ ->GetToken (false );
260- WaitForCompletion (token, " GetToken 2" );
261- EXPECT_NE (*token.result (), " " );
232+ // Ensure that we now get a different installations token.
233+ token = installations ->GetToken (false );
234+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken 2" );
235+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
262236#if defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
263- // Desktop is a stub and returns the same token, but on mobile it should
264- // return a new token.
265- EXPECT_NE (*token.result (), first_token);
237+ // Desktop is a stub and returns the same token, but on mobile it
238+ // should return a new token.
239+ FLAKY_EXPECT_NE (*token.result (), first_token);
266240#endif // defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) &&
267241 // TARGET_OS_IPHONE)
242+
243+ return true ;
244+ },
245+ installations_)) {
246+ FAIL () << " Test failed, check error log for details." ;
247+ }
268248}
269249
270250TEST_F (FirebaseInstallationsTest, TestCanGetIdAndTokenTogether) {
0 commit comments