spring icon indicating copy to clipboard operation
spring copied to clipboard

Spring returns error after a few tries

Open thebravoman opened this issue 10 years ago • 9 comments

I strart bin/rspec and the tests are executed correctly. Spring is started. Then I run again bin/rspec and the tests are executed correclty. At a certain point bin/rspec starts returning "unninitialized constant error" or db table does not exist.

Then I do a bin/spring stop bin/rspec my_test

and it again works correctly for a few runs and then starts returning an error. It happens almost immidiately to return an error if I stop the bin/rspec process with Crtl+C

Durring this time running just rspec my_test is successful.

I don`t know even where to start debuging this. What should I look for. What should I inspect.

thebravoman avatar Feb 13 '15 17:02 thebravoman

I'm getting this too. Rails 3.2.21.

jamonholmgren avatar Mar 06 '15 00:03 jamonholmgren

Probably related to #368.

jamonholmgren avatar Mar 06 '15 00:03 jamonholmgren

For what it's worth, this seems to happen more frequently when using Guard.

jamonholmgren avatar Mar 06 '15 00:03 jamonholmgren

this happens to me as well, even when using spring rspec and not binstubs

charlietran avatar Sep 21 '15 20:09 charlietran

database foobar could come from reusing the same db connection ... on ctrl+c it might not be properly closed ... multi test constant foobar most likely from reloading ... try to find a pattern of changed files that trigger this ... turn SPRING_LOG=log/spring.log on to see more details

if you can reproduce anything try adding failing test ... from there it should be easy to fix

grosser avatar Sep 21 '15 21:09 grosser

figured it out! these intermittent failures started happening once i enabled config.threadsafe! across all environments. i'm guessing this should be disabled with Spring because of its forking model?

charlietran avatar Sep 22 '15 14:09 charlietran

@grosser is there a way I can check if Spring is preloading / running within config/application.rb, so that I can turn off thread safety only in the case that Spring is preloading?

charlietran avatar Sep 22 '15 15:09 charlietran

defined?(Spring) should do

no idea why threadsafe would mess with spring though ... it's not using threads :D could be something weird that threadsafe triggers like more eager loading ...

grosser avatar Sep 22 '15 15:09 grosser

@grosser the config.threadsafe! command in Rails 3 breaks Spring because it forces config.cache_classes to true.

adding this line in my test.rb fixed the issue:

  if defined?(Spring::Commands::RSpec)
    config.cache_classes = false
  end

charlietran avatar Oct 02 '15 21:10 charlietran