Skip to content

Commit

Permalink
Replace Timecop with 1 second sleep
Browse files Browse the repository at this point in the history
This test mocks the internals of Statsd (time sending a message to timing)

Statsd no longer uses Time.now to determine the time, instead
using Process.clock_gettime in order to compute monotonic time.
More details: reinh/statsd#70.

I initially updated our test to mock the new call and also
stub the constant Process::CLOCK_MONOTONIC.
But, this is the same dependency on some Statsd internal behaviour, it
just _looked_ more brittle.
Timecop may support this in future: travisjeffery/timecop#220 (comment)

Instead, sleeping for 1 second doesn't also test rely on testing the
internals of the Statsd gem.
  • Loading branch information
Bill Franklin committed Jan 7, 2021
1 parent 714b03f commit 698a505
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spec/commands/base_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def call

class Commands::SlowCommand < Commands::BaseCommand
def call
Timecop.travel Time.zone.now + 1
sleep 1
:foo
end
end
Expand Down Expand Up @@ -54,7 +54,7 @@ def call
it "sends a command's duration to statsd" do
expect(PublishingAPI.service(:statsd)).to receive(:timing) do |name, time, sample_rate|
expect(name).to eq "Commands.SlowCommand"
expect(time).to be_within(10).of(1000)
expect(time).to within(100).of(1000)
expect(sample_rate).to eq 1
end

Expand Down

0 comments on commit 698a505

Please sign in to comment.