Skip to content

Commit 658806b

Browse files
authored
Use custom dispatcher for apis calls to FTL (#77)
* Use custom dispatcher for apis calls to FTL * updating to make it configurable * removing unused var * lint fix
1 parent df4d134 commit 658806b

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

AndroidXCI/lib/src/main/kotlin/dev/androidx/ci/config/Config.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package dev.androidx.ci.config
1818

1919
import com.google.auth.Credentials
20+
import okhttp3.Dispatcher
2021
import okhttp3.logging.HttpLoggingInterceptor
2122

2223
/**
@@ -44,6 +45,7 @@ internal class Config {
4445
val gcp: Gcp,
4546
val endPoint: String = "https://testing.googleapis.com/v1/",
4647
val httpLogLevel: HttpLoggingInterceptor.Level = HttpLoggingInterceptor.Level.NONE,
48+
val dispatcher: Dispatcher = Dispatcher()
4749
)
4850
class Datastore(
4951
val gcp: Gcp,

AndroidXCI/lib/src/main/kotlin/dev/androidx/ci/firebase/FirebaseTestLabApi.kt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,26 @@ internal interface FirebaseTestLabApi {
6868
fun build(
6969
config: Config.FirebaseTestLab
7070
): FirebaseTestLabApi {
71-
val client = OkHttpClient.Builder().authenticateWith(
72-
config.gcp
73-
).addInterceptor {
74-
val newBuilder = it.request().newBuilder()
75-
newBuilder.addHeader(
76-
"Content-Type", "application/json;charset=utf-8",
77-
)
78-
newBuilder.addHeader(
79-
"Accept", "application/json"
80-
)
81-
it.proceed(
82-
newBuilder.build()
83-
)
84-
}.withLog4J(
85-
level = config.httpLogLevel,
86-
klass = FirebaseTestLabApi::class
87-
).build()
71+
val client = OkHttpClient
72+
.Builder()
73+
.dispatcher(config.dispatcher)
74+
.authenticateWith(
75+
config.gcp
76+
).addInterceptor {
77+
val newBuilder = it.request().newBuilder()
78+
newBuilder.addHeader(
79+
"Content-Type", "application/json;charset=utf-8",
80+
)
81+
newBuilder.addHeader(
82+
"Accept", "application/json"
83+
)
84+
it.proceed(
85+
newBuilder.build()
86+
)
87+
}.withLog4J(
88+
level = config.httpLogLevel,
89+
klass = FirebaseTestLabApi::class
90+
).build()
8891
val moshi = Moshi.Builder()
8992
.add(MetadataKotlinJsonAdapterFactory())
9093
.build()

AndroidXCI/lib/src/main/kotlin/dev/androidx/ci/testRunner/TestRunnerService.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import dev.androidx.ci.testRunner.vo.RemoteApk
1818
import dev.androidx.ci.testRunner.vo.UploadedApk
1919
import kotlinx.coroutines.CoroutineDispatcher
2020
import kotlinx.coroutines.Dispatchers
21+
import okhttp3.Dispatcher
2122
import okhttp3.logging.HttpLoggingInterceptor
2223
import java.io.InputStream
2324

@@ -173,7 +174,11 @@ interface TestRunnerService {
173174
* You may want to modify this if you want to use the same GCP account for isolated
174175
* test runs.
175176
*/
176-
testRunDataStoreObjectKind: String = AOSP_OBJECT_KIND
177+
testRunDataStoreObjectKind: String = AOSP_OBJECT_KIND,
178+
/**
179+
* Dispatcher for making api calls to FTL
180+
*/
181+
dispatcher: Dispatcher = Dispatcher()
177182
): TestRunnerService {
178183
val httpLogLevel = if (logHttpCalls) {
179184
HttpLoggingInterceptor.Level.BODY
@@ -211,6 +216,7 @@ interface TestRunnerService {
211216
config = Config.FirebaseTestLab(
212217
gcp = gcpConfig,
213218
httpLogLevel = httpLogLevel,
219+
dispatcher = dispatcher
214220
)
215221
),
216222
gcsResultPath = gcsResultPath

0 commit comments

Comments
 (0)