pantsbuild / intellij-pants-plugin

IntelliJ Plug-in for Pants Build
Apache License 2.0
74 stars 55 forks source link

"Rerun failed tests" for Scala crashes #588

Closed odisseus closed 4 years ago

odisseus commented 4 years ago

Steps to reproduce

  1. Check out the repository with tests from https://github.com/VirtusLab/intellij-pants-plugin-tests/tree/scala-pants-bad.
  2. Open it as a SBT project in IntelliJ Idea (version 2020.2.2 is recommended).
  3. Start an SBT shell. Make sure SBT debugging is enabled.
  4. Alternatively, start SBT in an independent terminal, and connect to it using a remote debug configuration.
  5. Place a breakpoint in the file RunTestsTest.scala at line 32.
  6. In the SBT shell, enter the following command:
    pantsTests/testOnly com.twitter.intellij.pants.RunTestsTest
  7. The test should start executing. Another IntelliJ window will open, which will load and import a Pants project.
  8. After the breakpoint is activated, find a class called ExampleTests and run it using the Scalatest runner. It is important to use the right runner, not JUnit or Pants.
  9. Some of the test cases will fail. This is expected.
  10. Click the button called "Rerun failed tests".
  11. Click the exclamation mark in the bottom right corner of the window to check the error log.
  12. The SBT process may be terminated at this point, as its further execution is irrelevant.

Expected behaviour: the failed tests are run again (and fail, of course) Actual behaviour: nothing happens; a stack trace is written to IntelliJ logs.

Underlying cause

The root cause is probably the big change in the interfaces related to re-running failed tests, which was made by commit 2c9c7007f522a4de77f376a24c565ae0bcb532aa. The Pants plugin is not aware of that change and attempts to cast new objects to old interfaces. This produces the stack trace:

java.lang.ClassCastException: class org.jetbrains.plugins.scala.testingSupport.test.actions.ScalaRerunFailedTestsAction$MyScalaRunProfile cannot be cast to class org.jetbrains.plugins.scala.testingSupport.test.AbstractTestRunConfiguration (org.jetbrains.plugins.scala.testingSupport.test.actions.ScalaRerunFailedTestsAction$MyScalaRunProfile and org.jetbrains.plugins.scala.testingSupport.test.AbstractTestRunConfiguration are in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @503f83ff)
    at com.twitter.intellij.pants.execution.PantsMakeBeforeRun.getTargetAddressesToCompile(PantsMakeBeforeRun.java:367)
    at com.twitter.intellij.pants.execution.PantsMakeBeforeRun.executeTask(PantsMakeBeforeRun.java:167)
    at com.twitter.intellij.pants.execution.PantsMakeBeforeRun.executeTask(PantsMakeBeforeRun.java:74)
    at com.intellij.execution.impl.ExecutionManagerImpl$compileAndRun$1.run(ExecutionManagerImpl.kt:370)
    at com.intellij.util.RunnableCallable.call(RunnableCallable.java:20)
    at com.intellij.util.RunnableCallable.call(RunnableCallable.java:11)
    at com.intellij.openapi.application.impl.ApplicationImpl$1.call(ApplicationImpl.java:268)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
    at java.base/java.lang.Thread.run(Thread.java:834)

(Line numbers may be slightly different depending on the exact version of the Pants plugin)

Additional information

Unfortunately, I could not create a fully automated test which would run without the breakpoints, manual steps and an additional IntelliJ instance. This is caused by bugs in our testing tools. I'm going to create a proper test as soon as we fix those tools.

The bug occurs with the Scala plugin of version 2020.2.102 or newer. I could not find the last version without the bug. Presumably it was not present in the Scala plugin for IntelliJ 2020.1.x.