Skip to content

Commit

Permalink
Fix for pinpoint test failing
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanshu committed Dec 20, 2022
1 parent 26097a9 commit e76f7bb
Showing 1 changed file with 18 additions and 9 deletions.
Expand Up @@ -31,33 +31,41 @@ 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
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
fun flushEvents() {
val context = ApplicationProvider.getApplicationContext<Context>()
@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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -391,6 +399,7 @@ class PinpointAnalyticsInstrumentationTest {
Amplify.configure(context)
Sleep.milliseconds(COGNITO_CONFIGURATION_TIMEOUT)
synchronousAuth = SynchronousAuth.delegatingTo(Amplify.Auth)
synchronousAuth.signOut()
}

private fun setUniqueId() {
Expand Down

0 comments on commit e76f7bb

Please sign in to comment.