Skip to content

Commit

Permalink
increase timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
restingbull committed Aug 22, 2024
1 parent e0b9571 commit 8a761e5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ genrule(
[
bazel_integration_tests(
name = "%s_test" % example,
timeout = "eternal",
additional_env_inherit = [
"ANDROID_HOME",
"ANDROID_SDK_ROOT",
Expand Down
60 changes: 47 additions & 13 deletions src/main/kotlin/io/bazel/kotlin/test/BazelIntegrationTestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package io.bazel.kotlin.test

import io.bazel.kotlin.builder.utils.BazelRunFiles
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import java.io.BufferedInputStream
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.nio.charset.StandardCharsets.UTF_8
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
import java.util.concurrent.Callable
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.zip.GZIPInputStream
import kotlin.io.path.createDirectories
Expand Down Expand Up @@ -54,6 +60,7 @@ object BazelIntegrationTestRunner {
bzlmod && workspace.hasModule() || !bzlmod && workspace.hasWorkspace()
}
.forEach { bzlmod ->
println("Starting bzlmod $bzlmod test")
bazel.run(
workspace,
"--bazelrc=$bazelrc",
Expand Down Expand Up @@ -164,22 +171,49 @@ object BazelIntegrationTestRunner {
.directory(inDirectory.toFile())
.start()
.let { process ->
if (process.waitFor(800, TimeUnit.SECONDS) && process.exitValue() == 0) {
return Result.success(process)
}
val out = process.inputStream.readAllBytes().toString(UTF_8)
val err = process.errorStream.readAllBytes().toString(UTF_8)
process.destroyForcibly()
return Result.failure(
AssertionError(
"""
println("Running ${args.joinToString(" ")}...")
val executor = Executors.newCachedThreadPool();
try {
val stdOut = executor.submit(process.inputStream.streamTo(System.out))
val stdErr = executor.submit(process.inputStream.streamTo(System.out))
if (process.waitFor(300, TimeUnit.SECONDS) && process.exitValue() == 0) {
return Result.success(process)
}
process.destroyForcibly()
return Result.failure(
AssertionError(
"""
$this ${args.joinToString(" ")} exited ${process.exitValue()}:
stdout:
$out
${stdOut.get().toString(UTF_8)}
stderr:
$err
${stdErr.get().toString(UTF_8)}
""".trimIndent(),
),
)
),
)
} finally {
executor.shutdown();
executor.awaitTermination(1, TimeUnit.SECONDS);
}
}

private fun InputStream.streamTo(out: OutputStream): Callable<ByteArray> {
return Callable {
val result = ByteArrayOutputStream();
BufferedInputStream(this).apply {
val buffer = ByteArray(4096)
var read = 0
do {
if (Thread.currentThread().isInterrupted) {
out.flush()
break
}
result.write(buffer, 0, read);
out.write(buffer, 0, read)
read = read(buffer)
} while (read != -1)
}
return@Callable result.toByteArray()
}
}
}

0 comments on commit 8a761e5

Please sign in to comment.