Skip to content
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

incompatible with spring #309

Closed
Goltergaul opened this issue Apr 15, 2014 · 22 comments
Closed

incompatible with spring #309

Goltergaul opened this issue Apr 15, 2014 · 22 comments

Comments

@Goltergaul
Copy link

This gem is incompatible with https://github.com/rails/spring . The problem seems to be that the <%= ENV['TEST_ENV_NUMBER'] %> in the database.yml is not reevaluated for each test that is spinned up.

I am using the follwing two gems:
gem "spring"
gem "spring-commands-rspec"

Is there a workaround i can use?

@grosser
Copy link
Owner

grosser commented Apr 15, 2014

You could do some fancyness around reloading the db yml and reconnecting the db, but I doubt this will be the only issue you run into, since every connection needs to be redone ...

@tonidas
Copy link

tonidas commented Apr 16, 2014

That will be awesome!

@diasjorge
Copy link

maybe this could help: rails/spring#116

@sj26
Copy link
Contributor

sj26 commented Jun 4, 2014

Spring doesn't completely reconfigure activerecord, which is required if you want to do the interpolation of TEST_ENV_NUMBER into your config.

Putting into config/spring.rb worked for me:

require "active_support/core_ext/module/aliasing"
require "spring/application"

class Spring::Application
  def connect_database_with_reconfigure_database
    disconnect_database
    reconfigure_database
    connect_database_without_reconfigure_database
  end

  alias_method_chain :connect_database, :reconfigure_database

  def reconfigure_database
    if active_record_configured?
      ActiveRecord::Base.configurations =
        Rails.application.config.database_configuration
    end
  end
end

The problem is there's no nice place in the preload process to hook into, an after_fork isn't quite right because the database is already connected. Meh.

@tonidas
Copy link

tonidas commented Jun 4, 2014

@sj26 What about ActiveModel in MongoID ?

@sj26
Copy link
Contributor

sj26 commented Jun 5, 2014

@airtonsobral you'll probably need to customise your spring after_fork hook to do the same thing for mongo.

@Loremaster
Copy link

@sj26 Tried you solution and it didn't work for me, unfortunately. :( I still have errors like this one:

Failure/Error: Unable to find matching line from backtrace
     ActiveRecord::StatementInvalid:
       PG::TRDeadlockDetected: ERROR:  deadlock detected
       LINE 1: SELECT  "contact_types".* FROM "contact_types"  WHERE "conta...
                                              ^
       DETAIL:  Process 70359 waits for AccessShareLock on relation 24882218 of database 7594218; blocked by process 70358.
       Process 70358 waits for AccessExclusiveLock on relation 24888649 of database 7594218; blocked by process 70359.
       HINT:  See server log for query details.

That is sad.

UPD: After spring stop your solution started to work! Thank you!

@grosser
Copy link
Owner

grosser commented Jul 18, 2014

there is now a $250 bounty for this issue https://www.bountysource.com/issues/1669551-incompatible-with-spring :)

@dankohn
Copy link

dankohn commented Aug 18, 2014

@sj26 your solution worked for me, after running spring stop. Thanks!

@grosser
Copy link
Owner

grosser commented Aug 18, 2014

make it pretty and go grab that money then :)

@Loremaster
Copy link

@sj26 Do it, man. You should be rewarded according to your deserts!

@tetherit
Copy link

Is there a solution for mongoid?

@foobear
Copy link

foobear commented Dec 2, 2014

The solution of @sj26 did not work for me properly (also after spring stop), at least saying bin/rake parallel:create would try to create foo_development multiple times (imagine parallel:drop ;)).

In the end, we decided to simply disable Spring when running tests in parallel -- yes, it will be slightly slower as each worker has to boot; but that's not too important considering the test runtime on that project (a parallel run is still much faster).

I just disabled Spring on the bin/rake and bin/rspec binstubs by changing the way it's loaded:

running_in_parallel = ENV.has_key?('TEST_ENV_NUMBER') || ARGV.any? { |arg| arg =~ /^parallel:/ }

begin
  load File.expand_path("../spring", __FILE__) unless running_in_parallel
rescue LoadError
end

@jvenezia
Copy link

jvenezia commented Jan 8, 2015

@foobear Thank's, this is perfect for me :)

@chellberg
Copy link

@foobear worked swimmingly for me as well! thanks!

@grosser
Copy link
Owner

grosser commented Feb 6, 2015

does this look good ?
#361

@artygus
Copy link

artygus commented Apr 29, 2015

@sj26 your solution worked smoothly for me, thanks! Note for guys who are using db-charmer, set DbCharmer.connections_should_exist to false for test env

@BenMorganIO
Copy link

This worked for me:

$ spring rake parallel:spec

@layonferreira
Copy link

On top of @sj26 solution, I have to specify config.cache_store = :memory_store because spring wont reload the cache files.

@barberj
Copy link

barberj commented Aug 14, 2015

There is some info on this on the wiki https://github.com/grosser/parallel_tests/wiki

@grosser
Copy link
Owner

grosser commented Dec 2, 2015

hopefully fixed with 2.2.0

@betesh
Copy link

betesh commented Dec 4, 2015

@sj26's monkey patch has made it to the wiki: https://github.com/grosser/parallel_tests/wiki/Spring

Rferencing it here since that will most likely be the most up-to-date version going forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests