-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3463 from evanrolfe/refactor/active_job6
[api] StatusHistoryRescaler now uses ActiveJob
- Loading branch information
Showing
4 changed files
with
38 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe StatusHistoryRescalerJob, type: :job do | ||
include ActiveJob::TestHelper | ||
|
||
describe '#rescale' do | ||
before do | ||
Timecop.freeze(2010, 7, 12) | ||
|
||
now = Time.now.to_i - 2.days | ||
StatusHistory.transaction do | ||
1000.times do |i| | ||
StatusHistory.create time: now + i, key: 'idle_x86_64', value: i | ||
end | ||
end | ||
|
||
StatusHistory.create time: Time.now.to_i, key: 'busy_x86_64', value: 100 | ||
end | ||
|
||
after do | ||
Timecop.return | ||
end | ||
|
||
subject! { StatusHistoryRescalerJob.new.perform } | ||
|
||
it { expect(StatusHistory.count).to eq(2) } | ||
|
||
it 'keeps the StatusHistory with key = idle_x86_64' do | ||
status_histories = StatusHistory.where(key: 'idle_x86_64') | ||
expect(status_histories.count).to eq(1) | ||
expect(status_histories.first.value).to eq(499.5) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters