mirror of https://github.com/sbt/sbt.git
Use coursier.util.Task more in tests
This commit is contained in:
parent
13eda41fa2
commit
c98393838a
|
|
@ -8,6 +8,9 @@ trait Schedulable[F[_]] extends Gather[F] {
|
|||
|
||||
object Schedulable {
|
||||
|
||||
lazy val defaultThreadPool =
|
||||
fixedThreadPool(4 max Runtime.getRuntime.availableProcessors())
|
||||
|
||||
def fixedThreadPool(size: Int): ExecutorService =
|
||||
Executors.newFixedThreadPool(
|
||||
size,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package coursier.util
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.concurrent.{ExecutionContext, Future, Promise}
|
||||
|
||||
final case class Task[T](value: ExecutionContext => Future[T]) extends AnyVal {
|
||||
|
||||
|
|
@ -26,5 +26,8 @@ object Task extends PlatformTask {
|
|||
def delay[A](a: => A): Task[A] =
|
||||
Task(ec => Future(a)(ec))
|
||||
|
||||
def never[A]: Task[A] =
|
||||
Task(_ => Promise[A].future)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ object JsTests extends TestSuite {
|
|||
.map { res =>
|
||||
assert(res.isRight)
|
||||
}
|
||||
.future
|
||||
.future()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ import java.io.File
|
|||
import java.nio.file.Files
|
||||
|
||||
import coursier.cache.protocol.TestprotocolHandler
|
||||
import coursier.interop.scalaz._
|
||||
import coursier.util.Task
|
||||
import utest._
|
||||
|
||||
import scala.concurrent.{Await, ExecutionContext}
|
||||
import scala.concurrent.duration.Duration
|
||||
import scala.util.Try
|
||||
|
||||
object CacheFetchTests extends TestSuite {
|
||||
|
|
@ -30,29 +32,34 @@ object CacheFetchTests extends TestSuite {
|
|||
Console.err.println(s"Warning: unable to remove temporary directory $tmpDir")
|
||||
}
|
||||
|
||||
val res = try {
|
||||
val fetch = Fetch.from(
|
||||
Seq(
|
||||
extraRepo,
|
||||
MavenRepository("https://repo1.maven.org/maven2")
|
||||
),
|
||||
Cache.fetch(
|
||||
tmpDir
|
||||
val fetch = Fetch.from(
|
||||
Seq(
|
||||
extraRepo,
|
||||
MavenRepository("https://repo1.maven.org/maven2")
|
||||
),
|
||||
Cache.fetch[Task](
|
||||
tmpDir
|
||||
)
|
||||
)
|
||||
|
||||
val startRes = Resolution(
|
||||
Set(
|
||||
Dependency(
|
||||
Module("com.github.alexarchambault", "coursier_2.11"), "1.0.0-M9-test"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val startRes = Resolution(
|
||||
Set(
|
||||
Dependency(
|
||||
Module("com.github.alexarchambault", "coursier_2.11"), "1.0.0-M9-test"
|
||||
)
|
||||
)
|
||||
)
|
||||
val f = startRes
|
||||
.process
|
||||
.run(fetch)
|
||||
.future()(ExecutionContext.global)
|
||||
|
||||
startRes.process.run(fetch).unsafePerformSync
|
||||
} finally {
|
||||
cleanTmpDir()
|
||||
}
|
||||
val res =
|
||||
try Await.result(f, Duration.Inf)
|
||||
finally {
|
||||
cleanTmpDir()
|
||||
}
|
||||
|
||||
val errors = res.errors
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ package test
|
|||
import java.io.File
|
||||
import java.math.BigInteger
|
||||
|
||||
import coursier.interop.scalaz._
|
||||
import coursier.util.{Gather, Schedulable, Task}
|
||||
import utest._
|
||||
|
||||
import scalaz.concurrent.Strategy
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
|
||||
object ChecksumTests extends TestSuite {
|
||||
|
|
@ -83,13 +83,13 @@ object ChecksumTests extends TestSuite {
|
|||
|
||||
val cache = new File(cachePath)
|
||||
|
||||
def validate(artifact: Artifact, sumType: String) =
|
||||
Cache.validateChecksum(
|
||||
def validate(artifact: Artifact, sumType: String): Task[Either[FileError, Unit]] =
|
||||
Cache.validateChecksum[Task](
|
||||
artifact,
|
||||
sumType,
|
||||
cache,
|
||||
Strategy.DefaultExecutorService
|
||||
).run.unsafePerformSync
|
||||
Schedulable.defaultThreadPool
|
||||
).run
|
||||
|
||||
def artifact(url: String) = Artifact(
|
||||
url,
|
||||
|
|
@ -110,11 +110,14 @@ object ChecksumTests extends TestSuite {
|
|||
"http://abc.com/com/github/alexarchambault/coursier_2.11/1.0.0-M9/coursier_2.11-1.0.0-M9.pom"
|
||||
).map(artifact)
|
||||
|
||||
def validateAll(sumType: String) =
|
||||
for (artifact <- artifacts) {
|
||||
val res = validate(artifact, sumType)
|
||||
assert(res.isRight)
|
||||
}
|
||||
def validateAll(sumType: String): Future[Seq[Unit]] =
|
||||
Gather[Task].gather(
|
||||
artifacts.map { artifact =>
|
||||
validate(artifact, sumType).map { res =>
|
||||
assert(res.isRight)
|
||||
}
|
||||
}
|
||||
).future()(ExecutionContext.global)
|
||||
|
||||
'sha1 - validateAll("SHA-1")
|
||||
'sha256 - validateAll("SHA-256")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package coursier
|
|||
package test
|
||||
|
||||
import coursier.core.Repository
|
||||
import coursier.interop.scalaz._
|
||||
import coursier.maven.MavenRepository
|
||||
import utest._
|
||||
import scala.async.Async.{ async, await }
|
||||
|
|
@ -19,7 +18,7 @@ object ResolutionTests extends TestSuite {
|
|||
Resolution(deps, filter = filter, forceVersions = forceVersions)
|
||||
.process
|
||||
.run(Platform.fetch(repositories))
|
||||
.future
|
||||
.future()
|
||||
|
||||
implicit class ProjectOps(val p: Project) extends AnyVal {
|
||||
def kv: (ModuleVersion, (Artifact.Source, Project)) = p.moduleVersion -> (testRepository.source, p)
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ class Backend($: BackendScope[Unit, State]) {
|
|||
|
||||
// For reasons that are unclear to me, not delaying this when using the runNow execution context
|
||||
// somehow discards the $.modState above. (Not a major problem as queue is used by default.)
|
||||
Future(task)(scala.scalajs.concurrent.JSExecutionContext.Implicits.queue).flatMap(_.future).foreach { res: Resolution =>
|
||||
Future(task)(scala.scalajs.concurrent.JSExecutionContext.Implicits.queue).flatMap(_.future()).foreach { res: Resolution =>
|
||||
$.modState{ s =>
|
||||
updateDepGraph(res)
|
||||
updateTree(res, "#deptree", reverse = s.reverseTree)
|
||||
|
|
|
|||
Loading…
Reference in New Issue