Skip to content

Commit e0676c7

Browse files
authored
chore: fix inconsistency with endpointWithAttributes test (#2196)
1 parent b075845 commit e0676c7

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt

+19-11
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class PinpointAnalyticsInstrumentationTest {
9090

9191
// Act: Record the event
9292
Amplify.Analytics.recordEvent(event)
93-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
93+
Sleep.milliseconds(DEFAULT_TIMEOUT)
9494
Amplify.Analytics.flushEvents()
9595
val hubEvents = hubAccumulator.await(10, TimeUnit.SECONDS)
9696
val submittedEvents = combineAndFilterEvents(hubEvents)
@@ -118,15 +118,15 @@ class PinpointAnalyticsInstrumentationTest {
118118
.addProperty("DemoDoubleProperty2", 2.0)
119119
.build()
120120
Amplify.Analytics.recordEvent(event1)
121-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
121+
Sleep.milliseconds(DEFAULT_TIMEOUT)
122122
val eventName2 = "Amplify-event" + UUID.randomUUID().toString()
123123
val event2 = AnalyticsEvent.builder()
124124
.name(eventName2)
125125
.addProperty("DemoProperty1", "DemoValue1")
126126
.addProperty("DemoProperty2", 2.0)
127127
.build()
128128
Amplify.Analytics.recordEvent(event2)
129-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
129+
Sleep.milliseconds(DEFAULT_TIMEOUT)
130130
Amplify.Analytics.flushEvents()
131131
val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS)
132132
val hubEvent = analyticsHubEventAccumulator.awaitFirst()
@@ -189,9 +189,9 @@ class PinpointAnalyticsInstrumentationTest {
189189

190190
// Act: Record two events: the one created above and another just with a key
191191
Amplify.Analytics.recordEvent(event)
192-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
192+
Sleep.milliseconds(DEFAULT_TIMEOUT)
193193
Amplify.Analytics.recordEvent("amplify-test-event")
194-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
194+
Sleep.milliseconds(DEFAULT_TIMEOUT)
195195
Amplify.Analytics.flushEvents()
196196
val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS)
197197
val submittedEvents = combineAndFilterEvents(hubEvents)
@@ -226,10 +226,10 @@ class PinpointAnalyticsInstrumentationTest {
226226

227227
// Act: Record an event, unregister the global property, and record another event
228228
Amplify.Analytics.recordEvent("amplify-test-event-with-property")
229-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
229+
Sleep.milliseconds(DEFAULT_TIMEOUT)
230230
Amplify.Analytics.unregisterGlobalProperties("GlobalProperty")
231231
Amplify.Analytics.recordEvent("amplify-test-event-without-property")
232-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
232+
Sleep.milliseconds(DEFAULT_TIMEOUT)
233233
Amplify.Analytics.flushEvents()
234234
val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS)
235235
val submittedEvents = combineAndFilterEvents(hubEvents)
@@ -282,9 +282,16 @@ class PinpointAnalyticsInstrumentationTest {
282282
.customProperties(properties)
283283
.userAttributes(userAttributes)
284284
.build()
285-
Amplify.Analytics.identifyUser(UUID.randomUUID().toString(), pinpointUserProfile)
285+
val uuid = UUID.randomUUID().toString()
286+
Amplify.Analytics.identifyUser(uuid, pinpointUserProfile)
286287
Sleep.milliseconds(PINPOINT_ROUNDTRIP_TIMEOUT)
287-
val endpointResponse = fetchEndpointResponse()
288+
var endpointResponse = fetchEndpointResponse()
289+
var retry_count = 0
290+
while (retry_count < MAX_RETRIES && endpointResponse.attributes.isNullOrEmpty()) {
291+
Sleep.milliseconds(DEFAULT_TIMEOUT)
292+
endpointResponse = fetchEndpointResponse()
293+
retry_count++
294+
}
288295
assertCommonEndpointResponseProperties(endpointResponse)
289296
Assert.assertEquals(
290297
"User attribute value",
@@ -310,7 +317,7 @@ class PinpointAnalyticsInstrumentationTest {
310317
}
311318

312319
private fun assertCommonEndpointResponseProperties(endpointResponse: EndpointResponse) {
313-
Log.i("DEBUG", endpointResponse.toString())
320+
Log.d("PinpointAnalyticsInstrumentationTest", endpointResponse.toString())
314321
val attributes = endpointResponse.attributes!!
315322
Assert.assertEquals("[email protected]", attributes["email"]!![0])
316323
Assert.assertEquals("test-user", attributes["name"]!![0])
@@ -369,7 +376,8 @@ class PinpointAnalyticsInstrumentationTest {
369376
private const val CONFIGURATION_NAME = "amplifyconfiguration"
370377
private const val COGNITO_CONFIGURATION_TIMEOUT = 10 * 1000L
371378
private const val PINPOINT_ROUNDTRIP_TIMEOUT = 10 * 1000L
372-
private const val RECORD_INSERTION_TIMEOUT = 5 * 1000L
379+
private const val DEFAULT_TIMEOUT = 5 * 1000L
380+
private const val MAX_RETRIES = 10
373381
private const val UNIQUE_ID_KEY = "UniqueId"
374382
private const val PREFERENCES_AND_FILE_MANAGER_SUFFIX = "515d6767-01b7-49e5-8273-c8d11b0f331d"
375383
private lateinit var synchronousAuth: SynchronousAuth

0 commit comments

Comments
 (0)