Skip to content

Commit 7b7e11e

Browse files
authored
Fix AI test timeout (#6917)
Per [b/414406390](https://b.corp.google.com/issues/414406390), This fixes the issue with long text golden files timing out the tests. This occurred because the text contents were too large for the channel's buffer- so the channel entered a suspension point until the content was read. Unfortunately, this suspension point blocked the test thread. To solve this, we do the same thing we do for `goldenStreamingFile`- we write to the channel in a separate coroutine scope. This allows Kotlin to properly recognize that the suspension point within the writer should allow for the test thread to continue.
1 parent cbd9636 commit 7b7e11e

File tree

2 files changed

+6
-4
lines changed
  • firebase-ai/src/test/java/com/google/firebase/ai/util
  • firebase-vertexai/src/test/java/com/google/firebase/vertexai/util

2 files changed

+6
-4
lines changed

firebase-ai/src/test/java/com/google/firebase/ai/util/tests.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,16 @@ internal fun goldenUnaryFile(
210210
httpStatusCode: HttpStatusCode = HttpStatusCode.OK,
211211
backend: GenerativeBackend = GenerativeBackend.vertexAI(),
212212
block: CommonTest,
213-
) =
213+
) = doBlocking {
214214
commonTest(httpStatusCode, backend = backend) {
215215
val goldenFile = loadGoldenFile(name)
216216
val message = goldenFile.readText()
217217

218-
channel.send(message.toByteArray())
218+
launch { channel.send(message.toByteArray()) }
219219

220220
block()
221221
}
222+
}
222223

223224
/**
224225
* A variant of [goldenUnaryFile] for vertexai tests Loads the *Golden File* and automatically

firebase-vertexai/src/test/java/com/google/firebase/vertexai/util/tests.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,16 @@ internal fun goldenUnaryFile(
189189
name: String,
190190
httpStatusCode: HttpStatusCode = HttpStatusCode.OK,
191191
block: CommonTest,
192-
) =
192+
) = doBlocking {
193193
commonTest(httpStatusCode) {
194194
val goldenFile = loadGoldenFile(name)
195195
val message = goldenFile.readText()
196196

197-
channel.send(message.toByteArray())
197+
launch { channel.send(message.toByteArray()) }
198198

199199
block()
200200
}
201+
}
201202

202203
/**
203204
* A variant of [goldenUnaryFile] for vertexai tests Loads the *Golden File* and automatically

0 commit comments

Comments
 (0)