From 8e22adecb9879be8d8d1ce7372a9fc5440135e21 Mon Sep 17 00:00:00 2001 From: Saijad Dhuka Date: Wed, 21 Dec 2022 13:56:11 -0600 Subject: [PATCH 1/7] add retry for pinpoint tests --- .../pinpoint/PinpointAnalyticsInstrumentationTest.kt | 9 +++++++-- configuration/instrumentation-tests.gradle | 10 +--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt index 6be6288414..12e619ad61 100644 --- a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt +++ b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt @@ -282,9 +282,14 @@ class PinpointAnalyticsInstrumentationTest { .customProperties(properties) .userAttributes(userAttributes) .build() - Amplify.Analytics.identifyUser(UUID.randomUUID().toString(), pinpointUserProfile) + val uuid = UUID.randomUUID().toString() + Amplify.Analytics.identifyUser(uuid, pinpointUserProfile) Sleep.milliseconds(PINPOINT_ROUNDTRIP_TIMEOUT) - val endpointResponse = fetchEndpointResponse() + var endpointResponse = fetchEndpointResponse() + while (endpointResponse.attributes == null) { + Sleep.milliseconds(5 * 1000L) + endpointResponse = fetchEndpointResponse() + } assertCommonEndpointResponseProperties(endpointResponse) Assert.assertEquals( "User attribute value", diff --git a/configuration/instrumentation-tests.gradle b/configuration/instrumentation-tests.gradle index dd552b5e81..1477fd8059 100644 --- a/configuration/instrumentation-tests.gradle +++ b/configuration/instrumentation-tests.gradle @@ -3,15 +3,7 @@ Need to create backends for s3, pinpoint, predictions, core */ def module_backends = [ - 'aws-datastore':'DataStoreIntegTests', - 'aws-api': 'ApiInstrumentedTests', - 'aws-geo-location': 'GeoIntegTests', - 'maplibre-adapter': 'GeoIntegTests', - 'aws-storage-s3': 'NONE', - 'aws-analytics-pinpoint': 'NONE', - 'aws-predictions': 'NONE', - 'core':'NONE', - 'aws-auth-cognito': 'AuthIntegrationTests' + 'aws-analytics-pinpoint': 'NONE' ] subprojects { From 7afec430b570276382a5d26df8d02040136160dc Mon Sep 17 00:00:00 2001 From: Saijad Dhuka Date: Wed, 21 Dec 2022 14:25:07 -0600 Subject: [PATCH 2/7] add logging --- .../analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt | 1 + .../analytics/pinpoint/targeting/TargetingClient.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt index 12e619ad61..245790b39f 100644 --- a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt +++ b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt @@ -283,6 +283,7 @@ class PinpointAnalyticsInstrumentationTest { .userAttributes(userAttributes) .build() val uuid = UUID.randomUUID().toString() + Log.d("PinpointAnalyticsInstrumentationTest", "identify user with endpoint id: $uuid") Amplify.Analytics.identifyUser(uuid, pinpointUserProfile) Sleep.milliseconds(PINPOINT_ROUNDTRIP_TIMEOUT) var endpointResponse = fetchEndpointResponse() diff --git a/aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/targeting/TargetingClient.kt b/aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/targeting/TargetingClient.kt index 05b88b59ff..d56b9eca8c 100644 --- a/aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/targeting/TargetingClient.kt +++ b/aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/targeting/TargetingClient.kt @@ -155,7 +155,7 @@ internal class TargetingClient( LOG.info("Updating EndpointProfile.") // This could fail if credentials are no longer stored due to sign out before this call is processed pinpointClient.updateEndpoint(updateEndpointRequest) - LOG.info("EndpointProfile updated successfully.") + LOG.info("EndpointProfile updated successfully for ${updateEndpointRequest.toString()}.") } catch (e: Exception) { LOG.error("PinpointException occurred during endpoint update:", e) } From f94747ef6e9a8c73122ef7fa926612b645b11c65 Mon Sep 17 00:00:00 2001 From: Saijad Dhuka Date: Wed, 21 Dec 2022 14:51:04 -0600 Subject: [PATCH 3/7] add logging --- .../analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt index 245790b39f..6d50684ad1 100644 --- a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt +++ b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt @@ -287,7 +287,7 @@ class PinpointAnalyticsInstrumentationTest { Amplify.Analytics.identifyUser(uuid, pinpointUserProfile) Sleep.milliseconds(PINPOINT_ROUNDTRIP_TIMEOUT) var endpointResponse = fetchEndpointResponse() - while (endpointResponse.attributes == null) { + while (endpointResponse.attributes == null || endpointResponse.attributes?.size == 0) { Sleep.milliseconds(5 * 1000L) endpointResponse = fetchEndpointResponse() } From d5114dbd4ad6a9aac2f902bfebd224200ae60c28 Mon Sep 17 00:00:00 2001 From: Saijad Dhuka Date: Wed, 21 Dec 2022 15:39:14 -0600 Subject: [PATCH 4/7] added retry --- .../pinpoint/PinpointAnalyticsInstrumentationTest.kt | 4 +++- .../analytics/pinpoint/targeting/TargetingClient.kt | 2 +- configuration/instrumentation-tests.gradle | 10 +++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt index 6d50684ad1..45cc4dcfdb 100644 --- a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt +++ b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt @@ -287,9 +287,11 @@ class PinpointAnalyticsInstrumentationTest { Amplify.Analytics.identifyUser(uuid, pinpointUserProfile) Sleep.milliseconds(PINPOINT_ROUNDTRIP_TIMEOUT) var endpointResponse = fetchEndpointResponse() - while (endpointResponse.attributes == null || endpointResponse.attributes?.size == 0) { + var retry_count = 0 + while (retry_count < 10 && (endpointResponse.attributes == null || endpointResponse.attributes?.size == 0)) { Sleep.milliseconds(5 * 1000L) endpointResponse = fetchEndpointResponse() + retry_count++ } assertCommonEndpointResponseProperties(endpointResponse) Assert.assertEquals( diff --git a/aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/targeting/TargetingClient.kt b/aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/targeting/TargetingClient.kt index d56b9eca8c..05b88b59ff 100644 --- a/aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/targeting/TargetingClient.kt +++ b/aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/targeting/TargetingClient.kt @@ -155,7 +155,7 @@ internal class TargetingClient( LOG.info("Updating EndpointProfile.") // This could fail if credentials are no longer stored due to sign out before this call is processed pinpointClient.updateEndpoint(updateEndpointRequest) - LOG.info("EndpointProfile updated successfully for ${updateEndpointRequest.toString()}.") + LOG.info("EndpointProfile updated successfully.") } catch (e: Exception) { LOG.error("PinpointException occurred during endpoint update:", e) } diff --git a/configuration/instrumentation-tests.gradle b/configuration/instrumentation-tests.gradle index 1477fd8059..dd552b5e81 100644 --- a/configuration/instrumentation-tests.gradle +++ b/configuration/instrumentation-tests.gradle @@ -3,7 +3,15 @@ Need to create backends for s3, pinpoint, predictions, core */ def module_backends = [ - 'aws-analytics-pinpoint': 'NONE' + 'aws-datastore':'DataStoreIntegTests', + 'aws-api': 'ApiInstrumentedTests', + 'aws-geo-location': 'GeoIntegTests', + 'maplibre-adapter': 'GeoIntegTests', + 'aws-storage-s3': 'NONE', + 'aws-analytics-pinpoint': 'NONE', + 'aws-predictions': 'NONE', + 'core':'NONE', + 'aws-auth-cognito': 'AuthIntegrationTests' ] subprojects { From 275c11587deec286e53c1dc766c496434da9d362 Mon Sep 17 00:00:00 2001 From: Saijad Dhuka Date: Wed, 21 Dec 2022 15:40:35 -0600 Subject: [PATCH 5/7] just run for pinpoint --- configuration/instrumentation-tests.gradle | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/configuration/instrumentation-tests.gradle b/configuration/instrumentation-tests.gradle index dd552b5e81..1477fd8059 100644 --- a/configuration/instrumentation-tests.gradle +++ b/configuration/instrumentation-tests.gradle @@ -3,15 +3,7 @@ Need to create backends for s3, pinpoint, predictions, core */ def module_backends = [ - 'aws-datastore':'DataStoreIntegTests', - 'aws-api': 'ApiInstrumentedTests', - 'aws-geo-location': 'GeoIntegTests', - 'maplibre-adapter': 'GeoIntegTests', - 'aws-storage-s3': 'NONE', - 'aws-analytics-pinpoint': 'NONE', - 'aws-predictions': 'NONE', - 'core':'NONE', - 'aws-auth-cognito': 'AuthIntegrationTests' + 'aws-analytics-pinpoint': 'NONE' ] subprojects { From 4ea193d58310a3d1b95266b7c5755f67f597f58f Mon Sep 17 00:00:00 2001 From: Saijad Dhuka Date: Wed, 21 Dec 2022 15:58:55 -0600 Subject: [PATCH 6/7] revert instrumentation changes --- .../pinpoint/PinpointAnalyticsInstrumentationTest.kt | 3 +-- configuration/instrumentation-tests.gradle | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt index 45cc4dcfdb..c453e9ff36 100644 --- a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt +++ b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt @@ -283,7 +283,6 @@ class PinpointAnalyticsInstrumentationTest { .userAttributes(userAttributes) .build() val uuid = UUID.randomUUID().toString() - Log.d("PinpointAnalyticsInstrumentationTest", "identify user with endpoint id: $uuid") Amplify.Analytics.identifyUser(uuid, pinpointUserProfile) Sleep.milliseconds(PINPOINT_ROUNDTRIP_TIMEOUT) var endpointResponse = fetchEndpointResponse() @@ -318,7 +317,7 @@ class PinpointAnalyticsInstrumentationTest { } private fun assertCommonEndpointResponseProperties(endpointResponse: EndpointResponse) { - Log.i("DEBUG", endpointResponse.toString()) + Log.d("PinpointAnalyticsInstrumentationTest", endpointResponse.toString()) val attributes = endpointResponse.attributes!! Assert.assertEquals("user@test.com", attributes["email"]!![0]) Assert.assertEquals("test-user", attributes["name"]!![0]) diff --git a/configuration/instrumentation-tests.gradle b/configuration/instrumentation-tests.gradle index 1477fd8059..dd552b5e81 100644 --- a/configuration/instrumentation-tests.gradle +++ b/configuration/instrumentation-tests.gradle @@ -3,7 +3,15 @@ Need to create backends for s3, pinpoint, predictions, core */ def module_backends = [ - 'aws-analytics-pinpoint': 'NONE' + 'aws-datastore':'DataStoreIntegTests', + 'aws-api': 'ApiInstrumentedTests', + 'aws-geo-location': 'GeoIntegTests', + 'maplibre-adapter': 'GeoIntegTests', + 'aws-storage-s3': 'NONE', + 'aws-analytics-pinpoint': 'NONE', + 'aws-predictions': 'NONE', + 'core':'NONE', + 'aws-auth-cognito': 'AuthIntegrationTests' ] subprojects { From 515a4144016c62ebe4585dbbfa7dec476de7b824 Mon Sep 17 00:00:00 2001 From: Saijad Dhuka Date: Wed, 21 Dec 2022 16:13:24 -0600 Subject: [PATCH 7/7] address comments --- .../PinpointAnalyticsInstrumentationTest.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt index c453e9ff36..dfcedbf0fb 100644 --- a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt +++ b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt @@ -90,7 +90,7 @@ class PinpointAnalyticsInstrumentationTest { // Act: Record the event Amplify.Analytics.recordEvent(event) - Sleep.milliseconds(RECORD_INSERTION_TIMEOUT) + Sleep.milliseconds(DEFAULT_TIMEOUT) Amplify.Analytics.flushEvents() val hubEvents = hubAccumulator.await(10, TimeUnit.SECONDS) val submittedEvents = combineAndFilterEvents(hubEvents) @@ -118,7 +118,7 @@ class PinpointAnalyticsInstrumentationTest { .addProperty("DemoDoubleProperty2", 2.0) .build() Amplify.Analytics.recordEvent(event1) - Sleep.milliseconds(RECORD_INSERTION_TIMEOUT) + Sleep.milliseconds(DEFAULT_TIMEOUT) val eventName2 = "Amplify-event" + UUID.randomUUID().toString() val event2 = AnalyticsEvent.builder() .name(eventName2) @@ -126,7 +126,7 @@ class PinpointAnalyticsInstrumentationTest { .addProperty("DemoProperty2", 2.0) .build() Amplify.Analytics.recordEvent(event2) - Sleep.milliseconds(RECORD_INSERTION_TIMEOUT) + Sleep.milliseconds(DEFAULT_TIMEOUT) Amplify.Analytics.flushEvents() val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS) val hubEvent = analyticsHubEventAccumulator.awaitFirst() @@ -189,9 +189,9 @@ class PinpointAnalyticsInstrumentationTest { // Act: Record two events: the one created above and another just with a key Amplify.Analytics.recordEvent(event) - Sleep.milliseconds(RECORD_INSERTION_TIMEOUT) + Sleep.milliseconds(DEFAULT_TIMEOUT) Amplify.Analytics.recordEvent("amplify-test-event") - Sleep.milliseconds(RECORD_INSERTION_TIMEOUT) + Sleep.milliseconds(DEFAULT_TIMEOUT) Amplify.Analytics.flushEvents() val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS) val submittedEvents = combineAndFilterEvents(hubEvents) @@ -226,10 +226,10 @@ class PinpointAnalyticsInstrumentationTest { // Act: Record an event, unregister the global property, and record another event Amplify.Analytics.recordEvent("amplify-test-event-with-property") - Sleep.milliseconds(RECORD_INSERTION_TIMEOUT) + Sleep.milliseconds(DEFAULT_TIMEOUT) Amplify.Analytics.unregisterGlobalProperties("GlobalProperty") Amplify.Analytics.recordEvent("amplify-test-event-without-property") - Sleep.milliseconds(RECORD_INSERTION_TIMEOUT) + Sleep.milliseconds(DEFAULT_TIMEOUT) Amplify.Analytics.flushEvents() val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS) val submittedEvents = combineAndFilterEvents(hubEvents) @@ -287,8 +287,8 @@ class PinpointAnalyticsInstrumentationTest { Sleep.milliseconds(PINPOINT_ROUNDTRIP_TIMEOUT) var endpointResponse = fetchEndpointResponse() var retry_count = 0 - while (retry_count < 10 && (endpointResponse.attributes == null || endpointResponse.attributes?.size == 0)) { - Sleep.milliseconds(5 * 1000L) + while (retry_count < MAX_RETRIES && endpointResponse.attributes.isNullOrEmpty()) { + Sleep.milliseconds(DEFAULT_TIMEOUT) endpointResponse = fetchEndpointResponse() retry_count++ } @@ -376,7 +376,8 @@ class PinpointAnalyticsInstrumentationTest { private const val CONFIGURATION_NAME = "amplifyconfiguration" private const val COGNITO_CONFIGURATION_TIMEOUT = 10 * 1000L private const val PINPOINT_ROUNDTRIP_TIMEOUT = 10 * 1000L - private const val RECORD_INSERTION_TIMEOUT = 5 * 1000L + private const val DEFAULT_TIMEOUT = 5 * 1000L + private const val MAX_RETRIES = 10 private const val UNIQUE_ID_KEY = "UniqueId" private const val PREFERENCES_AND_FILE_MANAGER_SUFFIX = "515d6767-01b7-49e5-8273-c8d11b0f331d" private lateinit var synchronousAuth: SynchronousAuth