Skip to content

Commit

Permalink
upload signal as const
Browse files Browse the repository at this point in the history
  • Loading branch information
anonvt committed Aug 9, 2024
1 parent e408c4d commit a0af1a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class EventPipelineTest {

lateinit var workManager: WorkManager
private lateinit var workManager: WorkManager

@Before
fun setup() {
Expand Down Expand Up @@ -199,29 +199,24 @@ import org.junit.runner.RunWith

@Test
fun events_are_uploaded() {
val impressions1 = listOf(
getImpressionPromoted(),
getImpressionOrganic()
)
val impressions2 = listOf(
val impressions = listOf(
getImpressionPromoted(),
getImpressionOrganic()
)

val aggregated = Event(
impressions = impressions1 + impressions2,
impressions = impressions,
)

runBlocking {
EventPipeline.clear()

EventPipeline.storeImpression(ImpressionEvent(impressions1), shouldFlush = false)
EventPipeline.storeImpression(ImpressionEvent(impressions2))
EventPipeline.storeImpression(ImpressionEvent(impressions))
.join()

// Wait for the upload work to be done
while (
workManager.getWorkInfos(WorkQuery.fromUniqueWorkNames("UPLOAD"))
workManager.getWorkInfos(WorkQuery.fromUniqueWorkNames(UPLOAD_SIGNAL))
.get().first().state != WorkInfo.State.SUCCEEDED
) {
yield()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ private val KEY_IMPRESSION_EVENTS= stringPreferencesKey("KEY_IMPRESSION_EVENTS")
private val KEY_CLICK_EVENTS = stringPreferencesKey("KEY_CLICK_EVENTS")
private val KEY_PURCHASE_EVENTS = stringPreferencesKey("KEY_PURCHASE_EVENTS")

private const val UPLOAD_SIGNAL = "UPLOAD"
@VisibleForTesting
const val UPLOAD_SIGNAL = "UPLOAD"

val Context.eventDatastore: DataStore<Preferences> by preferencesDataStore(name = PREFERENCES_NAME)

Expand Down Expand Up @@ -86,7 +87,7 @@ internal object EventPipeline {

workManager!!
.enqueueUniqueWork(
"UPLOAD",
UPLOAD_SIGNAL,
ExistingWorkPolicy.REPLACE,
requestBuilder.build()
)
Expand Down

0 comments on commit a0af1a1

Please sign in to comment.