Skip to content

Enable Spring preloader in cases where it is likely desired

What does this MR do and why?

This MR changes the custom behavior of bin/spring, which previously would only allow Spring to be used if the ENABLE_SPRING environment variable was explicitly set to 1.

This behavior does breaks the contract of Spring, where binstubs like bin/rspec should always run Spring unless DISABLE_SPRING is set. However, this ENABLE_SPRING opt-in behavior was added for legacy reasons which are not entirely clear.

Now, after this MR, Spring is conditionally enabled in certain cases where it is likely that the user wants to use it.

Specifically, it is always enabled when running specs under RubyMine, without requiring that the user explicitly set ENABLE_SPRING or any other environment variables (it relies on SPRING_TMP_PATH being set to enable it, which RubyMine always sets).

This MR also reverts the bin/rspec binstub to the default version which is generated by bin/spring binstub --all.

It does NOT add spring enabled binstubs for bin/rake and bin/rails, as this might cause unexpected regressions. We can try enabling those in a future MR.

More details

See the comments at the top of the bin/spring file in this MR for more detail.

Justification

This MR was created because this behavior recently became a breaking bug for RubyMine users, because RubyMine recently switched the built-in test runner from explicitly invoking spring to instead relying on the default expected behavior of a spring-enabled bin/rspec binstub (which, as noted above, should run Spring by default).

References

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

CLI default disabled behavior

  • time bin/rspec spec/lib/api/api_spec.rb
  • You should not see Running via Spring preloader, and it should take ~30 total seconds.

RubyMine enabled behavior

  • Run spec/lib/api/api_spec.rb in RubyMine with the spring preloader enabled.
  • You should see Running via Spring preloader...
  • Run it again (now that Spring server has been started, if it was not already running) via time bin/rspec spec/lib/api/api_spec.rb
  • Total execution time should be ~15 total seconds (with spring), rather than ~30 total seconds (without spring).
  • Run it again with the spring preloader disabled.
  • You should not see Running via Spring preloader, and it should take ~30 total seconds.

CLI conditionally enabled behavior

Repeat the above experiment, using the time executable to check runtime. You should see the faster runtime and Running via Spring preloader... when using any of these various methods to enable Spring:

  • time ENABLE_SPRING=1 bin/rspec spec/lib/api/api_spec.rb
  • time DISABLE_SPRING=0 bin/rspec spec/lib/api/api_spec.rb
  • time SPRING_TMP_PATH=/tmp bin/rspec spec/lib/api/api_spec.rb

Direct invocation of /bin/spring always works

  • /bin/spring status
  • This should work and print out the status of the spring servers
Edited by Chad Woolley

Merge request reports

Loading