Skip to content

Commit

Permalink
Replace Timecop with Process.clock_gettime in spec
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.

We therefore must update our test to mock the new call and also
stub the constant Process::CLOCK_MONOTONIC.

This is the same dependency on some Statsd internal behaviour, it
just _looks_ more brittle.
Timecop may support this in future: travisjeffery/timecop#220 (comment)
  • Loading branch information
Bill Franklin authored and fredericfran-gds committed Apr 29, 2021
1 parent f3e6e7c commit 929f083
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/commands/base_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def call

describe "timing" do
it "sends a command's duration to statsd" do
stub_const("Process::CLOCK_MONOTONIC", 6)
allow(Process).to receive(:clock_gettime)
allow(Process).to receive(:clock_gettime)
.with(Process::CLOCK_MONOTONIC, :nanosecond)
.and_return(1_472_243_573_027_000, 1_472_246_723_347_000)

expect(PublishingAPI.service(:statsd)).to receive(:timing) do |name, time, sample_rate|
expect(name).to eq "Commands.SlowCommand"
expect(time).to within(100).of(1000)
Expand Down

0 comments on commit 929f083

Please sign in to comment.