Skip to content
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

build: Setup concurrent tests #85

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
21 changes: 18 additions & 3 deletions robolectric-extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,27 @@ test {
systemProperty 'junit.jupiter.execution.parallel.enabled', 'true'
systemProperty 'junit.jupiter.execution.parallel.mode.default', 'same_thread'
systemProperty 'junit.jupiter.execution.parallel.mode.classes.default', 'same_thread'
systemProperty 'java.util.logging.config.file',
"${projectDir}/src/test/resources/logging.properties"
systemProperty 'java.util.logging.config.file', "${projectDir}/src/test/resources/logging.properties"
systemProperty 'robolectric.usePreinstrumentedJars', 'true'
}

tasks.test {
task concurrentTest(type: Test) {
testLogging {
showStandardStreams = true
showExceptions = true
showCauses = true
showStackTraces = true
}
systemProperty 'junit.jupiter.execution.parallel.enabled', 'true'
systemProperty 'junit.jupiter.execution.parallel.mode.default', 'same_thread'
systemProperty 'junit.jupiter.execution.parallel.mode.classes.default', 'concurrent'
systemProperty 'java.util.logging.config.file', "${projectDir}/src/test/resources/logging.properties"
systemProperty 'robolectric.usePreinstrumentedJars', 'true'
}

check.dependsOn(concurrentTest)

tasks.withType(Test.class).configureEach {
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(libs.versions.jvmToolchain.get().toInteger()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import java.io.IOException
import java.io.RandomAccessFile
import java.net.MalformedURLException
import java.net.URL
import java.nio.channels.FileLock
import java.nio.channels.OverlappingFileLockException
import java.util.concurrent.ExecutorService


internal class JUnit5MavenDependencyResolver private constructor(
repositoryUrl: String,
repositoryId: String,
Expand All @@ -20,6 +23,7 @@ internal class JUnit5MavenDependencyResolver private constructor(
proxyHost: String?,
proxyPort: Int,
) : MavenDependencyResolver(repositoryUrl, repositoryId, repositoryUserName, repositoryPassword, proxyHost, proxyPort) {
@Suppress("unused")
constructor() : this(
MavenRoboSettings.getMavenRepositoryUrl(),
MavenRoboSettings.getMavenRepositoryId(),
Expand All @@ -44,9 +48,12 @@ internal class JUnit5MavenDependencyResolver private constructor(
val artifacts: List<Pair<DependencyJar, MavenJarArtifact>> = dependencies.map { it to MavenJarArtifact(it) }

for ((dependencyJar, artifact) in artifacts) {
if (!File(localRepositoryDir, artifact.jarPath()).exists()) {
val artifactJarFile = File(localRepositoryDir, artifact.jarPath())
if (!artifactJarFile.exists()) {
whileLocked(dependencyJar) {
mavenArtifactFetcher.fetchArtifact(artifact)
if (!artifactJarFile.exists()) {
mavenArtifactFetcher.fetchArtifact(artifact)
}
}
}
}
Expand All @@ -73,9 +80,17 @@ internal class JUnit5MavenDependencyResolver private constructor(
try {
RandomAccessFile(lockFile, "rw").use { raf ->
raf.channel.use { channel ->
channel.lock().use {
runnable.run()
var lock: FileLock? = null
while (lock == null) {
try {
lock = channel.tryLock()
} catch (e: OverlappingFileLockException) {
// Sleep for a while before retrying
Thread.sleep(100)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log the swallowed exception.

The caught OverlappingFileLockException is swallowed without logging. Consider logging this exception to aid in diagnosing potential issues.

catch (e: OverlappingFileLockException) {
    // Log the exception for diagnostic purposes
    logger.warn("OverlappingFileLockException encountered: ${e.message}")
    Thread.sleep(100)
}
Tools
detekt

[warning] 87-87: The caught exception is swallowed. The original exception could be lost.

(detekt.exceptions.SwallowedException)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log the swallowed exception.

The caught OverlappingFileLockException is swallowed without logging. Consider logging this exception to aid in diagnosing potential issues.

catch (e: OverlappingFileLockException) {
    // Log the exception for diagnostic purposes
    logger.warn("OverlappingFileLockException encountered: ${e.message}")
    Thread.sleep(100)
}
Tools
detekt

[warning] 87-87: The caught exception is swallowed. The original exception could be lost.

(detekt.exceptions.SwallowedException)

}
runnable.run()
lock.release()
}
}
} catch (e: IOException) {
Expand Down
Loading