mirror of https://github.com/sbt/sbt.git
Add special hook to diagnose travis failing test.
This commit is contained in:
parent
87306524a8
commit
273024a238
|
|
@ -5,7 +5,8 @@ import java.io.File
|
|||
import java.net.URLClassLoader
|
||||
import java.util.HashMap
|
||||
|
||||
private[sbt] final class ClassLoaderCache(val commonParent: ClassLoader) {
|
||||
// Hack for testing only
|
||||
private[sbt] final class ClassLoaderCache(val commonParent: ClassLoader, errorEvicted: Boolean = false) {
|
||||
private[this] val delegate = new HashMap[List[File], Reference[CachedClassLoader]]
|
||||
|
||||
/**
|
||||
|
|
@ -25,9 +26,10 @@ private[sbt] final class ClassLoaderCache(val commonParent: ClassLoader) {
|
|||
get(files, stamps, existingRef.get)
|
||||
|
||||
private[this] def get(files: List[File], stamps: List[Long], existing: CachedClassLoader): ClassLoader =
|
||||
if (existing == null || stamps != existing.timestamps)
|
||||
if (existing == null || stamps != existing.timestamps) {
|
||||
if (existing == null && errorEvicted) sys.error(s"Evicted classloader for [${files mkString ", "}]!!!! Not allowed, Travis!")
|
||||
newEntry(files, stamps)
|
||||
else
|
||||
} else
|
||||
existing.loader
|
||||
|
||||
private[this] def newEntry(files: List[File], stamps: List[Long]): ClassLoader =
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ object ConcurrentCache extends Properties("ClassLoaderCache concurrent access")
|
|||
|
||||
property("Same class loader for same classpaths concurrently processed") = forAll { (names: List[String], concurrent: Int) =>
|
||||
withcp(names.distinct) { files =>
|
||||
val cache = new ClassLoaderCache(null)
|
||||
val cache = new ClassLoaderCache(null, errorEvicted = true)
|
||||
val loaders = (1 to concurrent).par.map(_ => cache(files)).toList
|
||||
loaders match {
|
||||
case DifferentClassloader(left, right) => false :| s"${showCp(left)} != ${showCp(right)}"
|
||||
|
|
@ -32,7 +32,7 @@ object ConcurrentCache extends Properties("ClassLoaderCache concurrent access")
|
|||
}
|
||||
|
||||
private[this] def withcp[T](names: List[String])(f: List[File] => T): T = IO.withTemporaryDirectory { tmp =>
|
||||
val files = names.map { name =>
|
||||
val files = names.sorted.map { name =>
|
||||
val file = new File(tmp, name)
|
||||
IO.touch(file)
|
||||
file
|
||||
|
|
|
|||
Loading…
Reference in New Issue