|
41 | 41 | namespace firebase_testapp_automated {
|
42 | 42 |
|
43 | 43 | using app_framework::LogDebug;
|
| 44 | +using app_framework::LogError; |
44 | 45 |
|
45 | 46 | using app_framework::ProcessEvents;
|
46 | 47 | using firebase_test_framework::FirebaseTest;
|
@@ -143,34 +144,90 @@ TEST_F(FirebaseInstallationsTest, TestCanGetId) {
|
143 | 144 | }
|
144 | 145 |
|
145 | 146 | TEST_F(FirebaseInstallationsTest, TestGettingIdTwiceMatches) {
|
146 |
| - firebase::Future<std::string> id = installations_->GetId(); |
147 |
| - WaitForCompletion(id, "GetId"); |
148 |
| - EXPECT_NE(*id.result(), ""); |
149 |
| - std::string first_id = *id.result(); |
150 |
| - id = installations_->GetId(); |
151 |
| - WaitForCompletion(id, "GetId 2"); |
152 |
| - EXPECT_EQ(*id.result(), first_id); |
| 147 | + if (!RunFlakyBlock( |
| 148 | + [](firebase::installations::Installations* installations) { |
| 149 | + 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 | + } |
| 160 | + std::string first_id = *id.result(); |
| 161 | + 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 | + } |
| 174 | + return true; |
| 175 | + }, |
| 176 | + installations_)) { |
| 177 | + FAIL() << "Test failed, check error log for details."; |
| 178 | + } |
153 | 179 | }
|
154 | 180 |
|
155 | 181 | TEST_F(FirebaseInstallationsTest, TestDeleteGivesNewIdNextTime) {
|
156 |
| - firebase::Future<std::string> id = installations_->GetId(); |
157 |
| - WaitForCompletion(id, "GetId"); |
158 |
| - EXPECT_NE(*id.result(), ""); |
159 |
| - std::string first_id = *id.result(); |
160 |
| - |
161 |
| - firebase::Future<void> del = installations_->Delete(); |
162 |
| - WaitForCompletion(del, "Delete"); |
163 |
| - |
164 |
| - // Ensure that we now get a different installations id. |
165 |
| - id = installations_->GetId(); |
166 |
| - WaitForCompletion(id, "GetId 2"); |
167 |
| - EXPECT_NE(*id.result(), ""); |
| 182 | + if (!RunFlakyBlock( |
| 183 | + [](firebase::installations::Installations* installations) { |
| 184 | + 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 | + } |
| 195 | + std::string first_id = *id.result(); |
| 196 | + |
| 197 | + 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 | + } |
| 204 | + |
| 205 | + // Ensure that we now get a different installations id. |
| 206 | + 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 | + } |
168 | 217 | #if defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
|
169 |
| - // Desktop is a stub and returns the same ID, but on mobile it should |
170 |
| - // return a new ID. |
171 |
| - EXPECT_NE(*id.result(), first_id); |
| 218 | + // Desktop is a stub and returns the same ID, but on mobile it |
| 219 | + // 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 | + } |
172 | 224 | #endif // defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) &&
|
173 | 225 | // TARGET_OS_IPHONE)
|
| 226 | + return true; |
| 227 | + }, |
| 228 | + installations_)) { |
| 229 | + FAIL() << "Test failed, check error log for details."; |
| 230 | + } |
174 | 231 | }
|
175 | 232 |
|
176 | 233 | TEST_F(FirebaseInstallationsTest, TestCanGetToken) {
|
|
0 commit comments