GithubHelp home page GithubHelp logo

Tell spork to reload about spork HOT 9 CLOSED

sporkrb avatar sporkrb commented on June 23, 2024
Tell spork to reload

from spork.

Comments (9)

bmabey avatar bmabey commented on June 23, 2024

Actually.. in addition to having all of spork reload what would be very cool is if we could send arbitrary code (via DRb) to the parent spork process that would be evaluated. That way, we could tell it only to reload certain parts that we know need to be reloaded. Just an idea.. reloading all of it is probably easier to do at this point.

from spork.

timcharper avatar timcharper commented on June 23, 2024

This sounds very cool. In order to achieve the "reload specific portions of the app part" we would have to create a few layers of forked processes, similar to how passenger does it. I think having a full restart occur would be a great start and may suffice.

from spork.

stepheneb avatar stepheneb commented on June 23, 2024

I just sent a pull request to both of you with a rough initial reload implementation to take a look at.

This gist: http://gist.github.com/216680 shows how to use the kicker gem to send Drb spec_sever.reload requests when code files change in rails.

from spork.

stepheneb avatar stepheneb commented on June 23, 2024

Hmm ... I just found a much simpler work-around for at least one part of this problem.

Here's a simple description of what I'd like to do:

  • Have a rails model and the spec test for that model open in textmate
  • command-R in the spec test to see the results
  • change code in the model
  • command-R again in the spec test to see new results

We are using Factory girl and normally when we run this command to see what is loaded in prefork:

spork -d | grep -A25 models

I see FactoryGirl load all the model classes we are using factories for -- of course by doing that in prefork it means that any model changes I make after spork startup don't appear after the fork.

We added this file: config/initializers/spork.rb

if defined?(Spork)
  Spork.trap_class_method(Factory, :find_definitions)
end

reference, Tim's suggestion in this thread: http://groups.google.com/group/sporkgem/browse_thread/thread/24e6342e6629d371#

This delays FactoryGirls loading of the model classes it needs to introspect until after the fork.

My simple test above now works.

My test environment is setup to cache classes (config/environments./test.rb)

config.cache_classes = true

My vendored rails is 2.3.4.

I had thought the model classes would be eagerly loaded in this case but appears not to be the case.

Thinking about how to get the most performance using spork in testing -- obviously the first step is to use more mocks and less factories/fixtures ... but after that a useful generalization is:

  • load as many app classes and generate app/state in prefork as possible AND is necessary for your tests
  • don't load classes in prefork that you are working on (or app state that might be affected by the change in these classes)

It might be helpful if after Spork started I could add or subtract classes from prefork app state. My method above which reloads the whole prefork is just brute force. If I had kicker watching for fsevents and in the case above removed just the model class I was working on from the prefork -- that might help. I don't know how unloading the class would affect the app state if it already had instances using the earlier versions of the model ...?

from spork.

thibaudgg avatar thibaudgg commented on June 23, 2024

FYI, RSpactor (0.6.x) handle Spork reload like that: http://github.com/thibaudgg/rspactor/blob/v0.6/lib/rspactor/spork.rb

from spork.

timcharper avatar timcharper commented on June 23, 2024

This looks rocking! I will have to investigate. Thanks for pointing it out!

from spork.

thibaudgg avatar thibaudgg commented on June 23, 2024

I'll certainly refactorize this spork.rb implementation for the 0.7.x version of RSpactor (using IO.popen), but for that I'm waiting for the Rails 3/RSpec 2 compatibility ;-)

from spork.

timcharper avatar timcharper commented on June 23, 2024

sigh... it's been a long road. I spent several hours last week just refactoring to make all the tests run with bundler (which is totally awesome and will make it easy for anyone to run the tests). But, it's getting closer :) Closer as in if you're traveling from Spain to New York, you'd be in Portugal right now.

from spork.

thibaudgg avatar thibaudgg commented on June 23, 2024

Yeah, continue this great works! RSpactor 0.7 with RSpec 2 & Spork support will be super awesome!

from spork.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.