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

FakeTimecop #14915

Merged
merged 2 commits into from May 8, 2017
Merged

FakeTimecop #14915

merged 2 commits into from May 8, 2017

Conversation

islemaster
Copy link
Contributor

@islemaster islemaster commented May 8, 2017

Deduplicates some test helpers from #14900 as requested by post-merge review. Lets tests swap in a fake Timecop implementation if they need real time to pass.

Also cleans up some expected/actual mixup in assertions added in the last PR.

Copy link
Contributor

@ashercodeorg ashercodeorg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (see comments).

#
# Pass time in the test - using real or fake time, depending on how the
# time machine is configured.
# @param [Integer] seconds - How far to jump forward
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can (should) be a Float rather than an Integer? Note that you are passing in floats in your tests.

#
class PoliceBox
def initialize(in_real_time)
@time_circuits_on = !in_real_time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this (@time_circuits_on) be better named? Without looking, I have no idea whether this indicates we are using real time or fake time. Also, it smells that you are changing the name from in_real_time (negated) to @time_circuits_on.

Maybe just use_fake_time?

Aside, I'm not a fan of PoliceBox. The person next to you probably has no idea what this class does. Similarly for PoliceBox#in_box. Granted, I don't have better, so no change required here.

end

def pause_time
Timecop.freeze if @time_circuits_on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I'd expect this to raise if time circuits are off, except we can't if we want tests to be "ambidextrous". Probably worth documenting this (also with resume_time).

require 'helpers/null_pub_sub_api'
require 'helpers/redis_table'
require_relative './police_box'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ./ necessary? Just curious.

For use in tests that sometimes want to time-travel (like most unit test runs) and sometimes don't (when verifying a behavior against real Redis.
@islemaster islemaster changed the title PoliceBox FakeTimecop May 8, 2017
@islemaster
Copy link
Contributor Author

Completely new approach, hopefully easier to grok for those unfamiliar with Doctor Who. PTAL.

Copy link
Contributor

@ashercodeorg ashercodeorg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed the reference (being mostly unfamiliar). That said, I still much prefer this implementation. Thanks!

@islemaster islemaster merged commit bc2ef7d into staging May 8, 2017
@islemaster islemaster deleted the big-blue-box branch May 8, 2017 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants