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 a7f89824e1..bc9b1adeb4 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 @@ -31,6 +31,7 @@ import com.amplifyframework.analytics.pinpoint.models.AWSPinpointUserProfile import com.amplifyframework.analytics.pinpoint.targeting.endpointProfile.EndpointProfile import com.amplifyframework.auth.AuthPlugin import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin +import com.amplifyframework.auth.cognito.exceptions.invalidstate.SignedInException import com.amplifyframework.core.Amplify import com.amplifyframework.hub.HubChannel import com.amplifyframework.hub.HubEvent @@ -38,14 +39,14 @@ import com.amplifyframework.testutils.HubAccumulator import com.amplifyframework.testutils.Resources import com.amplifyframework.testutils.Sleep import com.amplifyframework.testutils.sync.SynchronousAuth -import java.util.UUID -import java.util.concurrent.TimeUnit import kotlinx.coroutines.runBlocking import org.json.JSONException import org.junit.Assert import org.junit.Before import org.junit.BeforeClass import org.junit.Test +import java.util.UUID +import java.util.concurrent.TimeUnit class PinpointAnalyticsInstrumentationTest { @Before @@ -53,11 +54,18 @@ class PinpointAnalyticsInstrumentationTest { val context = ApplicationProvider.getApplicationContext() @RawRes val resourceId = Resources.getRawResourceId(context, CREDENTIALS_RESOURCE_NAME) val userAndPasswordPair = readCredentialsFromResource(context, resourceId) - synchronousAuth.signOut() - synchronousAuth.signIn( - userAndPasswordPair!!.first, - userAndPasswordPair.second - ) + try { + synchronousAuth.signIn( + userAndPasswordPair!!.first, + userAndPasswordPair.second + ) + } catch (e: Exception) { + if (e is SignedInException) { + e.printStackTrace() + } else { + throw e + } + } val hubAccumulator = HubAccumulator.create(HubChannel.ANALYTICS, AnalyticsChannelEventName.FLUSH_EVENTS, 1).start() Amplify.Analytics.flushEvents() @@ -191,7 +199,7 @@ class PinpointAnalyticsInstrumentationTest { Amplify.Analytics.recordEvent("amplify-test-event") Sleep.milliseconds(RECORD_INSERTION_TIMEOUT) Amplify.Analytics.flushEvents() - val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS) + val hubEvents = analyticsHubEventAccumulator.await(15, TimeUnit.SECONDS) val submittedEvents = combineAndFilterEvents(hubEvents) Assert.assertEquals(2, submittedEvents.size.toLong()) val event1Attributes = submittedEvents[0].properties @@ -229,7 +237,7 @@ class PinpointAnalyticsInstrumentationTest { Amplify.Analytics.recordEvent("amplify-test-event-without-property") Sleep.milliseconds(RECORD_INSERTION_TIMEOUT) Amplify.Analytics.flushEvents() - val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS) + val hubEvents = analyticsHubEventAccumulator.await(15, TimeUnit.SECONDS) val submittedEvents = combineAndFilterEvents(hubEvents) // Assert: Ensure there are two events, the first has attributes, and the second doesn't @@ -391,6 +399,7 @@ class PinpointAnalyticsInstrumentationTest { Amplify.configure(context) Sleep.milliseconds(COGNITO_CONFIGURATION_TIMEOUT) synchronousAuth = SynchronousAuth.delegatingTo(Amplify.Auth) + synchronousAuth.signOut() } private fun setUniqueId() {