Skip to content

Commit 2f004c9

Browse files
committed
fix: use UTC for Time dependent functions
1 parent acd3c2b commit 2f004c9

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

spec/slowlog_check_spec.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
)
1616
}
17+
let(:frozen_time) { Time.utc(2020,4,20,4,20,45) }
18+
let(:ddog_time) { Time.utc(2020,4,20,4,16).to_i * 1000.0 }
1719

1820
before(:example) do
1921
##
@@ -23,7 +25,7 @@
2325
[
2426
[
2527
1,
26-
Time.new(2020,04,20,04,19,45).to_i,
28+
Time.utc(2020,04,20,04,19,45).to_i,
2729
100000,
2830
[
2931
"eval",
@@ -35,7 +37,7 @@
3537
],
3638
[
3739
0,
38-
Time.new(2020,04,20,04,19,15).to_i,
40+
Time.utc(2020,04,20,04,19,15).to_i,
3941
200000,
4042
[
4143
"eval",
@@ -73,7 +75,7 @@
7375
"query_index"=>0,
7476
"aggr"=>nil,
7577
"scope"=>"replication_group:replicationgroup",
76-
"pointlist"=>[[1587381405000.0, 99994.0], [1587381404000.0, 99378.0]],
78+
"pointlist"=>[[ddog_time, 99994.0], [ddog_time - 5000, 99378.0]],
7779
"expression"=>"rspec.redis.slowlog.micros.95percentile{replication_group:infraeng-dev-redis}",
7880
"unit"=>nil,
7981
"display_name"=>"rspec.redis.slowlog.micros.95percentile"
@@ -88,11 +90,10 @@
8890
}
8991

9092
# Freeze time
91-
Timecop.freeze(2020, 04, 20, 04, 20, 45)
93+
Timecop.freeze(frozen_time)
9294

9395
# Shhh...
9496
allow_any_instance_of(Logger).to receive(:info) {}
95-
9697
end
9798

9899

@@ -135,18 +136,18 @@
135136
context 'first time' do
136137
it 'returns time an hour ago' do
137138
allow(ddog).to receive(:get_points) { ["", {"status" => "ok", "series" => [] }] }
138-
expect(subject).to eq(Time.new(2020,4,20,3,20))
139+
expect(subject).to eq(Time.utc(2020,4,20,3,20))
139140
end
140141
end
141142

142143
context 'nth time' do
143-
it { is_expected.to eq(Time.new(2020,4,20,4,16)) }
144+
it { is_expected.to eq(Time.utc(2020,4,20,4,16)) }
144145
end
145146
end
146147

147148
describe '#minute_precision' do
148149
subject { slowlog_check.minute_precision(Time.now) }
149-
it { is_expected.to eq(Time.new(2020,4,20,4,20,0)) }
150+
it { is_expected.to eq(Time.utc(2020,4,20,4,20,0)) }
150151
end
151152

152153
describe '#reporting_interval' do
@@ -217,10 +218,10 @@
217218
}
218219
it { is_expected.to eq(
219220
{
220-
Time.new(2020,04,20,04,17) => nil,
221-
Time.new(2020,04,20,04,18) => nil,
222-
Time.new(2020,04,20,04,19) => bucket,
223-
Time.new(2020,04,20,04,20) => nil
221+
Time.utc(2020,04,20,04,17) => nil,
222+
Time.utc(2020,04,20,04,18) => nil,
223+
Time.utc(2020,04,20,04,19) => bucket,
224+
Time.utc(2020,04,20,04,20) => nil
224225
}
225226
)
226227
}
@@ -249,7 +250,7 @@
249250

250251
expect(ddog).to have_received(:emit_points).with(
251252
"rspec.redis.slowlog.micros.avg",
252-
[[Time.new(2020,04,20,04,19), 150000]],
253+
[[Time.utc(2020,04,20,04,19), 150000]],
253254
{
254255
:host=>"replicationgroup",
255256
:interval=>60,

0 commit comments

Comments
 (0)