-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Run scripted tests on sbt 1.4.x + refactoring #10655
Conversation
fac3d59
to
f1961cf
Compare
98b75b1
to
2013eb0
Compare
|
4801f43
to
7acb9b2
Compare
Backport #10723 |
Now that #10711 got merged, I restarted the tests for this PR, let's see if all the tests pass when running against sbt 1.4 |
Challenge accepted |
To make |
b67a3eb
to
f85e4a5
Compare
// anymore before adding it to "allProblems", the field that eventually gets used by the Incomplete. (The transformation still takes place to show | ||
// the mapped source file in the logs) Play however needs to know the mapped source file to display it in it's error pages for a nice dev experience. | ||
// So the solution is that Play itself will try to transform the source file to the mapped file by running it "through" sourcePositionMappers: | ||
Project |
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.
I think the comment says it all... So since sbt/zinc#931 (which made it into sbt 1.4.1) the left Incomplete
of following compileResult
playframework/dev-mode/sbt-plugin/src/main/scala/play/sbt/run/PlayReload.scala
Lines 63 to 67 in 47f277b
val compileResult: Either[Incomplete, CompileSuccess] = for { | |
analysis <- reloadCompile().toEither.right | |
classpath <- classpath().toEither.right | |
} yield CompileSuccess(sourceMap(analysis), classpath.files) | |
compileResult.left.map(inc => CompileFailure(taskFailureHandler(inc, streams()))).merge |
https://github.com/sbt/zinc/blob/v1.4.1/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/LoggedReporter.scala#L131-L139
So since 1.4.1 sbt only transforms the position for log outputs... which is a problem for Play, so we have to make the Positions run through the sourcepositionmappers ourselves to show users the correct original soure of a problem in the error pages...
I also added two new tests for this new code here, which is relevant for sbt 1.4.1, see below.
Also I had to remove one scripted test which will always fail in sbt 1.4.1+, see routes-compiler-source-mapping/build.sbt
below (I think you have to click "Load diff" in the GitHub UI to see the comment I left there). However the two new tests I added compensate the deleted one.
val (status, body) = ScriptedTools.callUrl(path) | ||
println(s"Resource at $path returned HTTP $status") | ||
IO.write(destination, body) | ||
} |
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.
No need to wrap this in a Future
for these tests here... This was a mistake from beginning when I just copy/pasted the makeRequestAndRecordResponseBody
task from the shutdown-happy-path
scripted test where that Future is actually needed because it is a different test case.
As a result, in the test, we can also remove the 2 and 5 seconds sleep
s after calling the command because now its blocking.
dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/dev-mode-compile-and-config-error-source/test
Show resolved
Hide resolved
> makeRequestAndRecordResponseBody / appconf-fail.txt | ||
# First request takes a bit longer, therefore 5 seconds | ||
$ sleep 5000 |
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.
Like mentioned makeRequestAndRecordResponseBody
is blocking now, no need anymore for that sleep
.
dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/dev-mode-compile-and-config-error-source/test
Show resolved
Hide resolved
@@ -64,7 +64,28 @@ TaskKey[Unit]("checkPlayCompileEverything") := { | |||
base / "playmodule" / "app" / "PlayModule.scala", | |||
base / "transitive" / "app" / "Transitive.scala" | |||
) | |||
val allSources = analyses.flatMap(_.relations.allSources).map(_.toPath).sorted.map(_.toFile) | |||
val allSources = analyses.flatMap(_.relations.allSources).map(_ match { |
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.
allSources
returns VirtualFile
s in sbt 1.4 (which has no toPath
method) but a Java File
in sbt <= 1.3... Therefore I had to apply the same workaround in this test we used in PR 10648: https://github.com/playframework/playframework/pull/10648/files#diff-e1d77acde8f8aee39e58b112462d82fdcbc8c2920092be5af01ed5b3a92ca64b
EDIT:
Actually I had the error log still open in an editor so this is what failed when running with sbt 1.4:
[error] /tmp/sbt_3797ffa5/build.sbt:67: error: value toPath is not a member of xsbti.VirtualFileRef
[error] val allSources = analyses.flatMap(_.relations.allSources).map(_.toPath).sorted.map(_.toFile)
[error] ^
@@ -5,6 +5,7 @@ lazy val root = (project in file(".")) | |||
.enablePlugins(PlayJava) | |||
|
|||
libraryDependencies ++= Seq(guice, specs2 % Test) | |||
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.3.2" // can be removed when dropping Scala 2.12 |
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.
This an all changes below make the scripted tests behave on Scala 2.13 (until now they were just run with Scala 2.12...)
val source = base / args(0) | ||
val line = Integer.parseInt(args(1)) | ||
val errors = Incomplete | ||
.allExceptions(assertLeft(assertSome(Project.runTask(compile in Compile, state.value))._2.toEither)) |
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.
I removed that test because it will never succeed anymore in sbt 1.4.1+ because Positions returned by the incomplete will not be transformed anymore by the sourcepositionmappers, see comment above.
@@ -376,7 +376,6 @@ object BuildSettings { | |||
"-XX:MaxMetaspaceSize=300m", | |||
"-XX:HeapDumpPath=/tmp/", | |||
"-XX:+HeapDumpOnOutOfMemoryError", | |||
s"-Dscala.version=$scala212", |
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.
This gets set by script/test-scripted
now.
@@ -12,7 +12,7 @@ rm -rf $HOME/.ivy2/local | |||
end clean "CLEANED IVY LOCAL REPO" | |||
|
|||
start publish-local "CROSS-PUBLISHING PLAY LOCALLY FOR SBT SCRIPTED TESTS" | |||
runSbt +publishLocal | |||
runSbt ";crossScalaVersions;crossSbtVersions;+publishLocal" |
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.
Just adding some output for debugging...
@ignasi35 @octonato This pull request is finally ready to review! As an example how a cron build will look like (except without sbt 1.2) you can have a look at |
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.
This is great work! Thanks @mkurz
I only have a concern re the cost of running so many scripted tests in the CRON jobs. I'll merge as is but we should keep an eye on the weekend cron jobs to get a better idea of how much cost/benefit this brings.
- test-sbt-1.3.x | ||
- cron-test-sbt-1.3.x | ||
- cron-test-sbt-1.4.x |
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.
- test-sbt-1.3.x | |
- cron-test-sbt-1.3.x | |
- cron-test-sbt-1.4.x | |
- test-sbt-1.3.x-2.12 | |
- cron-test-sbt-1.3.x-2.13 | |
- cron-test-sbt-1.4.x |
Indicating the difference (scala version) to make it clearer what's the version tested on every PR.
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.
Not a blocker. Let's solve this elsewhere.
# Test against sbt 1.4.x, but only for cron builds | ||
- stage: cron-test-sbt-1.4.x | ||
name: "Run tests for 1.4.x and Scala 2.12.x" | ||
script: scripts/test-scripted $SCRIPTED_SBT_1_4 $TEST_SCALA_2_12 | ||
if: type = cron | ||
workspaces: | ||
use: published-local | ||
- name: "Run tests for 1.4.x and Scala 2.13.x" | ||
script: scripts/test-scripted $SCRIPTED_SBT_1_4 $TEST_SCALA_2_13 |
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.
This is rather expensive and I'm not 100% sure we should extend the support matrix in all possible axis (JDK8/11, sbt1.3/1.4, scala2.12/2.13).
I think running only 1.4.x for 2.13 could be enough. I think users of sbt 1.4 may be more likely to be early adopters in general and, therefore, users of 2.13 already.
Again, not sure whether we should keep both jobs or not...
dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/dev-mode-compile-and-config-error-source/test
Show resolved
Hide resolved
@@ -30,96 +30,152 @@ $ delete build.sbt.1 | |||
################ | |||
$ copy-file conf/application.conf application.conf.good | |||
$ copy-file application.conf.bad conf/application.conf | |||
# Give CI/docker/Java thread enough time to detect file change | |||
$ sleep 1200 | |||
> makeRequestAndRecordResponseBody / appconf-fail.txt | |||
# First request takes a bit longer, therefore 5 seconds |
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.
This comment is obsolete (the sleep is gone)
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.
I was referring to # First request takes a bit longer, therefore 5 seconds
dev-mode/sbt-plugin/src/sbt-test/play-sbt-plugin/dev-mode-compile-and-config-error-source/test
Show resolved
Hide resolved
############################################################################################################################################# | ||
# Invalid twirl template (parsing index.scala.html file is OK, but compiling target/scala-*/twirl/main/views/html/index.template.scala fails) | ||
# Actually this tests if the sourcePositionMappers set up by sbt-twirl is called and works correctly | ||
############################################################################################################################################# |
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.
These comments are great. Help the maintenance of the tests as they explain the expectation and use case very clearly. 👏🏼
@ignasi35 thanks a lot for the review! I removed the obsolete comment.
Like you said, lets merge and observe, we can always change/remove jobs from the matrix. |
As suggested once by Dale I now folded
scripts/test-scripted-13x
intoscripts/test-scripted
. I also can not see why we should have different scripts for different sbt versions... Also because this pull request now adds another sbt version,1.4.9, meaning the scripted tests will now be run against1.2.x,1.3.x and 1.4.x.I also defined fixed sbt versions in
.travis.yml
. Before that the job(s) that "Run scripted tests (a/b/c) for sbt 1.x" would just use the sbt version set by interplay (See Line -> Line -> Line). IMHO setting the versions hardcoded in .travis.yml is more readable (took me a while to figure out the default comes from interplay), safer (what if interplay upgrades to 1.3.x or newer, but nobody updates the.travis.yml
description, when looking at the tests someone may still thinks that the tests are running for 1.2.x) and also easier to maintain (we can quickly test new sbt versions by just updating .travis.yml instead of releasing and upgrading interplay).