Skip to content

Commit d651df7

Browse files
committed
Restore the test for #2202 (concurrent use of the linker).
The previous test had basically been inhibited when we switched the default environment from Rhino to Node.js. Indeed, this caused `loadedJSEnv` not to use the linker itself, but rather depend on the result of `fastOptJS`. The test was therefore not testing anything anymore. We restore this test in a more explicit and robust way, with a custom task to concurrently use the linker of `fullOptJS`, and a dedicated test task to directly depend on the former + `fullOptJS`. We use `fullOptJS` instead of `fastOptJS` because it takes more time, increasing the likelihood of concurrent execution.
1 parent 9906807 commit d651df7

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

sbt-plugin-test/build.sbt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import org.scalajs.core.tools.io._
12
import org.scalajs.core.tools.jsdep.ManifestFilters
23
import org.scalajs.jsenv.nodejs.JSDOMNodeJSEnv
4+
import org.scalajs.sbtplugin.ScalaJSPluginInternal._
5+
import org.scalajs.sbtplugin.Loggers.sbtLogger2ToolsLogger
6+
7+
lazy val concurrentFakeFullOptJS = taskKey[Any]("")
8+
lazy val concurrentUseOfLinkerTest = taskKey[Any]("")
39

410
name := "Scala.js sbt test"
511

@@ -56,7 +62,32 @@ lazy val noDOM = project.settings(baseSettings: _*).
5662
/* This hopefully exposes concurrent uses of the linker. If it fails/gets
5763
* flaky, there is a bug somewhere - #2202
5864
*/
59-
settings(inConfig(Compile)(run <<= run.dependsOn(fastOptJS, loadedJSEnv)): _*)
65+
settings(inConfig(Compile)(Seq(
66+
// A fake fullOptJS that we will run concurrently with the true fullOptJS
67+
concurrentFakeFullOptJS := Def.taskDyn {
68+
val s = (streams in fullOptJS).value
69+
val log = s.log
70+
val ir = (scalaJSIR in fullOptJS).value.data
71+
val moduleInitializers = scalaJSModuleInitializers.value
72+
73+
Def.task {
74+
log.info("Fake full optimizing")
75+
val linker = (scalaJSLinker in fullOptJS).value
76+
linker.link(ir, moduleInitializers,
77+
WritableMemVirtualJSFile("fake-fastopt.js"),
78+
sbtLogger2ToolsLogger(log))
79+
}.tag((usesScalaJSLinkerTag in fullOptJS).value)
80+
}.value,
81+
82+
/* Depend on both fullOptJS and concurrentFakeFullOptJS, so that they
83+
* are hopefully executed in parallel (potentially, but they should be
84+
* blocked from actually doing so by the concurrent restrictions on
85+
* usesScalaJSLinkerTag).
86+
*/
87+
concurrentUseOfLinkerTest := {
88+
(fullOptJS.value, concurrentFakeFullOptJS.value)
89+
}
90+
)))
6091

6192
lazy val withDOM = project.settings(baseSettings: _*).
6293
enablePlugins(ScalaJSPlugin).

0 commit comments

Comments
 (0)