Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coroutines: add event flow #91

Merged
merged 19 commits into from
Nov 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'coroutines' into coroutines-queue-manager
wzieba committed Nov 8, 2023
commit e14615f0ec5f4a53c16e0a42cdde9e2aee90e49f
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import java.nio.file.Path
import java.util.concurrent.TimeUnit
import kotlin.io.path.Path
import kotlin.time.Duration
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.runBlocking
@@ -116,6 +117,43 @@ class FunctionalTests {
}
}

/**
* In this scenario, the consumer application:
* 1. Goes to the background
* 2. Is re-launched
* This pattern occurs twice, which allows us to confirm the following assertions:
* 1. The event request is triggered when the consumer application is moved to the background
* 2. If the consumer application is sent to the background again within a short interval,
* the request is not duplicated.
*/
@Test
fun appSendsEventsWhenMovedToBackgroundAndDoesntSendDuplicatedRequestWhenItsMovedToBackgroundAgainQuickly() {
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
ActivityScenario.launch(SampleActivity::class.java).use { scenario ->
scenario.onActivity { activity: Activity ->
beforeEach(activity)
server.enqueue(MockResponse().setResponseCode(200))
server.enqueue(MockResponse().setResponseCode(200))
parselyTracker = initializeTracker(activity, flushInterval = 1.hours)

repeat(20) {
parselyTracker.trackPageview("url", null, null, null)
}
}

device.pressHome()
device.pressRecentApps()
device.findObject(UiSelector().descriptionContains("com.parsely")).click()
device.pressHome()

val firstRequest = server.takeRequest(10000, TimeUnit.MILLISECONDS)?.toMap()
val secondRequest = server.takeRequest(10000, TimeUnit.MILLISECONDS)?.toMap()

assertThat(firstRequest!!["events"]).hasSize(20)
assertThat(secondRequest).isNull()
}
}

/**
* In this scenario we "stress test" the concurrency model to see if we have any conflict during
*
You are viewing a condensed version of this merge commit. You can view the full changes here.