-
Notifications
You must be signed in to change notification settings - Fork 897
/
Copy pathpurging_spec.rb
88 lines (78 loc) · 3.1 KB
/
purging_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# this is basically copied from miq_report_result/purging.rb
RSpec.describe DriftState do
context "::Purging" do
before do
@vmdb_config = {
:drift_states => {
:history => {
:keep_drift_states => "6.months",
:purge_window_size => 100
}
}
}
stub_settings(@vmdb_config)
@rr1 = [
FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 1, :timestamp => (6.months + 1.day).to_i.seconds.ago.utc),
FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 1, :timestamp => (6.months - 1.day).to_i.seconds.ago.utc)
]
@rr2 = [
FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 2, :timestamp => (6.months + 2.days).to_i.seconds.ago.utc),
FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 2, :timestamp => (6.months + 1.day).to_i.seconds.ago.utc),
FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 2, :timestamp => (6.months - 1.day).to_i.seconds.ago.utc)
]
@rr_orphaned = [
FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => nil, :timestamp => (6.months - 1.day).to_i.seconds.ago.utc)
]
end
it "#purge_timer" do
EvmSpecHelper.local_miq_server
Timecop.freeze(Time.now) do
described_class.purge_timer
q = MiqQueue.all
expect(q.length).to eq(1)
expect(q.first).to have_attributes(
:class_name => described_class.name,
:method_name => "purge_by_date"
)
expect(q.first.args[0]).to be_within(0.1).of 6.months.to_i.seconds.ago.utc
end
end
context "#purge_queue" do
before do
EvmSpecHelper.local_miq_server
described_class.purge_queue(:remaining, 1)
end
it "with nothing in the queue" do
q = MiqQueue.all
expect(q.length).to eq(1)
expect(q.first).to have_attributes(
:class_name => described_class.name,
:method_name => "purge_by_remaining",
:args => [1]
)
end
end
context "#purge_count" do
it "by remaining" do
expect(described_class.purge_count(:remaining, 1)).to eq(3)
end
it "by date" do
expect(described_class.purge_count(:date, 6.months.to_i.seconds.ago.utc)).to eq(3)
end
end
context "#purge" do
it "by remaining" do
described_class.purge(:remaining, 1)
expect(described_class.where(:resource_id => 1)).to eq([@rr1.last])
expect(described_class.where(:resource_id => 2)).to eq([@rr2.last])
expect(described_class.where(:resource_id => nil)).to eq(@rr_orphaned)
end
it "by date" do
described_class.purge(:date, 6.months.to_i.seconds.ago.utc)
expect(described_class.where(:resource_id => 1)).to eq([@rr1.last])
expect(described_class.where(:resource_id => 2)).to eq([@rr2.last])
expect(described_class.where(:resource_id => nil)).to eq(@rr_orphaned)
end
end
end
end