Skip to content

Commit

Permalink
Fix metrics rollup floating point precision error
Browse files Browse the repository at this point in the history
```
Failure/Error: expect(perfs[2].cpu_usage_rate_average).to eq(12.0)

expected: 12.0
got: 12.000000000000002

(compared using ==)
```
  • Loading branch information
agrare committed Jun 2, 2020
1 parent 1d937fe commit 9e591b5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions spec/models/metric/ci_mixin/rollup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@
expect(perfs[0].sys_uptime_absolute_latest).to eq(3.0) # pulled from Host realtime
expect(perfs[0].derived_cpu_available).to eq(19_152)

expect(perfs[2].cpu_usage_rate_average).to eq(12.0) # pulled from Host realtime
expect(perfs[2].cpu_usagemhz_rate_average).to eq(24.0) # pulled from Host realtime
expect(perfs[2].sys_uptime_absolute_latest).to eq(16.0) # pulled from Host realtime
expect(perfs[2].cpu_usage_rate_average).to be_within(0.001).of(12.0) # pulled from Host realtime
expect(perfs[2].cpu_usagemhz_rate_average).to be_within(0.001).of(24.0) # pulled from Host realtime
expect(perfs[2].sys_uptime_absolute_latest).to be_within(0.001).of(16.0) # pulled from Host realtime
expect(perfs[2].derived_cpu_available).to eq(19_152)

expect(perfs[3].cpu_usage_rate_average).to eq(24.0) # pulled from Host realtime
expect(perfs[3].cpu_usagemhz_rate_average).to eq(48.0) # pulled from Host realtime
expect(perfs[3].sys_uptime_absolute_latest).to eq(32.0) # pulled from Host realtime
expect(perfs[3].cpu_usage_rate_average).to be_within(0.001).of(24.0) # pulled from Host realtime
expect(perfs[3].cpu_usagemhz_rate_average).to be_within(0.001).of(48.0) # pulled from Host realtime
expect(perfs[3].sys_uptime_absolute_latest).to be_within(0.001).of(32.0) # pulled from Host realtime
expect(perfs[3].derived_cpu_available).to eq(19_152)
end
end
Expand Down

0 comments on commit 9e591b5

Please sign in to comment.