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

Add Timecop#lens where time can go FASTER #42

Merged
merged 1 commit into from Sep 21, 2012
Merged

Add Timecop#lens where time can go FASTER #42

merged 1 commit into from Sep 21, 2012

Conversation

ghost
Copy link

@ghost ghost commented Sep 20, 2012

This pull request could also be named the "Scalosian" request (http://en.wikipedia.org/wiki/Wink_of_an_Eye).

Create a new mock_type, lens which will let time continue, like travel, but the first argument is a scaling factor which will make time move at an accelerated pace.

e.g.

Timecop.lens(3600) do
  while true do
    sleep 5
    puts "Seconds will seem like hours #{Time.now.to_s}"
  end
end

David Holcomb, david.holcomb@hp.com
Ken Mayer, ken@pivotallabs.com

@travisjeffery
Copy link
Owner

Any PR referencing TOS is good by me. Why call it Timecop#lens vs. something like Timecop#scale? I'm also interested in your use case for this?

@ghost
Copy link
Author

ghost commented Sep 21, 2012

lens only because of http://en.wikipedia.org/wiki/Gravitational_lens and http://www.technologyreview.com/view/424682/first-demonstration-of-time-cloaking/, really, so scale would be probably be a better name. I just liked the name.

Would you like me to refactor the method name and resubmit the pull request?

The use case: The QA team wants to run a simulation of 3 complete (30-day) billing cycles in a day. While they are happy with unit testing, they want some kind of "live" integration testing where days will pass in hours so they can see billing invoices and reports while simulating "real" activitiy. They want to stand up a "complete" production environment, but not have to wait 3 months. Thus Timecop#scale was born.

It works better than expected! We have several rails apps communicating via HTTP/JSON apis and Resque. Anything that depends on a Rails environment can be very simply configured to use the same time scale and presto!

...development.rb...

  if ENV['TIME_SCALE']
    time_scale = ENV['TIME_SCALE'].to_f
    config.after_initialize do
      Timecop.lens(time_scale)
    end

    # the slow query logger things *every* query is slow!
    config.active_record.auto_explain_threshold_in_seconds = 0.5 * time_scale

    $stderr.puts "TIME_SCALE: #{time_scale} @ #{Time.now.to_s}"
  end

Besides, it's just so cool :-)

Ken Mayer
ken@pivotallabs.com

travisjeffery pushed a commit that referenced this pull request Sep 21, 2012
travisjeffery pushed a commit that referenced this pull request Sep 21, 2012
@travisjeffery travisjeffery merged commit 6942d0e into travisjeffery:master Sep 21, 2012
travisjeffery pushed a commit that referenced this pull request Sep 21, 2012
@travisjeffery
Copy link
Owner

Alright awesome. No problem I did the refactoring myself, as much I like the name and its history too, I think scale is a more straight-forward and obvious API. I wish every pull request I got had such sweet references.

Sometime I should make it out to one of your guy's offices, I maintain another project called jasmine-jquery that you guys were obviously quite influential in too. :D

@ghost
Copy link
Author

ghost commented Oct 11, 2012

You're welcome any time. Come over for breakfast or one of our Tuesday tech talks and we'll serve you lunch, too.

travisjeffery pushed a commit that referenced this pull request Aug 4, 2013
* Paulche/patch-1:
  Hreffy reference to #42

Conflicts:
	README.markdown
aprescott added a commit to aprescott/timecop that referenced this pull request Mar 20, 2014
@softwarenacho
Copy link

Hi, I'm having problems with my database while using scale, I keep getting:

Out-of-sync worker list, no 22351 worker
[22263] ! Terminating timed out worker: 22417

how can I solve this?

This pull request was closed.
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

Successfully merging this pull request may close these issues.

2 participants