Skip to content

Pass a CoroutineContext, not CoroutineDispatcher, to SessionCoordinator #4950

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

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions firebase-sessions/firebase-sessions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ android {
}

dependencies {
implementation("androidx.datastore:datastore-preferences:1.0.0")
implementation("com.google.android.datatransport:transport-api:3.0.0")
implementation("com.google.firebase:firebase-common-ktx:20.3.2")
implementation("com.google.firebase:firebase-components:17.1.0")
implementation("com.google.firebase:firebase-encoders-json:18.0.1")
implementation("com.google.firebase:firebase-encoders:17.0.0")
implementation("com.google.firebase:firebase-installations-interop:17.1.0")
implementation("com.google.android.datatransport:transport-api:3.0.0")
implementation ("androidx.datastore:datastore-preferences:1.0.0")
implementation(libs.androidx.annotation)

runtimeOnly("com.google.firebase:firebase-installations:17.1.3")
Expand All @@ -60,6 +60,7 @@ dependencies {
testImplementation(libs.kotlin.coroutines.test)
testImplementation(libs.robolectric)
testImplementation(libs.truth)
testImplementation(project(":integ-testing"))

androidTestImplementation(libs.androidx.test.junit)
androidTestImplementation(libs.androidx.test.runner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.google.firebase.sessions

import android.util.Log
import com.google.firebase.installations.FirebaseInstallationsApi
import kotlinx.coroutines.CoroutineDispatcher
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
Expand All @@ -31,10 +31,10 @@ import kotlinx.coroutines.tasks.await
*/
internal class SessionCoordinator(
private val firebaseInstallations: FirebaseInstallationsApi,
backgroundDispatcher: CoroutineDispatcher,
context: CoroutineContext,
private val eventGDTLogger: EventGDTLoggerInterface,
) {
private val scope = CoroutineScope(backgroundDispatcher)
private val scope = CoroutineScope(context)

fun attemptLoggingSessionEvent(sessionEvent: SessionEvent) =
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package com.google.firebase.sessions
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.google.firebase.FirebaseApp
import com.google.firebase.concurrent.TestOnlyExecutors
import com.google.firebase.sessions.settings.SessionsSettings
import com.google.firebase.sessions.testing.FakeEventGDTLogger
import com.google.firebase.sessions.testing.FakeFirebaseApp
import com.google.firebase.sessions.testing.FakeFirebaseInstallations
import com.google.firebase.sessions.testing.FakeTimeProvider
import com.google.firebase.sessions.testing.TestSessionEventData
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.After
Expand All @@ -42,7 +43,7 @@ class SessionCoordinatorTest {
val sessionCoordinator =
SessionCoordinator(
firebaseInstallations = FakeFirebaseInstallations("FaKeFiD"),
backgroundDispatcher = StandardTestDispatcher(testScheduler),
context = TestOnlyExecutors.background().asCoroutineDispatcher() + coroutineContext,
eventGDTLogger = fakeEventGDTLogger,
)

Expand Down