- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5
 
build: Setup concurrent tests #85
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -5,13 +5,17 @@ import org.robolectric.internal.dependency.DependencyJar | |
| import org.robolectric.internal.dependency.MavenArtifactFetcher | ||
| import org.robolectric.internal.dependency.MavenDependencyResolver | ||
| import org.robolectric.internal.dependency.MavenJarArtifact | ||
| import tech.apter.junit.jupiter.robolectric.internal.extensions.createLogger | ||
| import java.io.File | ||
| 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, | ||
| 
          
            
          
           | 
    @@ -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) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| 
        
          
        
         | 
    @@ -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) | ||
| } | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log the swallowed exception. The caught  catch (e: OverlappingFileLockException) {
    // Log the exception for diagnostic purposes
    logger.warn("OverlappingFileLockException encountered: ${e.message}")
    Thread.sleep(100)
}Toolsdetekt
  | 
||
| } | ||
| runnable.run() | ||
| lock.release() | ||
| } | ||
| } | ||
| } catch (e: IOException) { | ||
| 
        
          
        
         | 
    @@ -85,6 +100,30 @@ internal class JUnit5MavenDependencyResolver private constructor( | |
| } | ||
| } | ||
| 
     | 
||
| private fun whileLocked(runnable: Runnable) { | ||
| val lockFile = createLockFile() | ||
| try { | ||
| RandomAccessFile(lockFile, "rw").use { raf -> | ||
| raf.channel.use { channel -> | ||
| var lock: FileLock? = null | ||
| while (lock == null) { | ||
| try { | ||
| lock = channel.tryLock() | ||
| } catch (e: OverlappingFileLockException) { | ||
| // Sleep for a while before retrying | ||
| Thread.sleep(100) | ||
| } | ||
                
       | 
||
| } | ||
| } | ||
| } | ||
| } catch (e: IOException) { | ||
| throw java.lang.IllegalStateException("Couldn't create lock file $lockFile", e) | ||
| } finally { | ||
| lockFile.delete() | ||
| } | ||
| } | ||
| 
     | 
||
| 
     | 
||
| private companion object { | ||
| private const val SPECIAL_CHARACTERS_IN_FILE_NAME_REGEX = """[<>:"\\/|\?\*]""" | ||
| } | ||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
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
OverlappingFileLockExceptionis swallowed without logging. Consider logging this exception to aid in diagnosing potential issues.Tools
detekt