Commit 5c3ca746 authored by Toon Claes's avatar Toon Claes

More the specs more robust

By actually checking if it deletes the correct Geo Event Log events.
parent f56731fc
...@@ -31,7 +31,7 @@ module Geo ...@@ -31,7 +31,7 @@ module Geo
end end
log_info('Delete Geo Event Log entries up to id', geo_event_log_id: cursor_last_event_ids.min) log_info('Delete Geo Event Log entries up to id', geo_event_log_id: cursor_last_event_ids.min)
Geo::EventLog.delete_all(['id < ?', cursor_last_event_ids.min]) Geo::EventLog.where('id < ?', cursor_last_event_ids.min).delete_all
end end
end end
end end
......
...@@ -43,10 +43,11 @@ describe Geo::PruneEventLogWorker, :geo do ...@@ -43,10 +43,11 @@ describe Geo::PruneEventLogWorker, :geo do
end end
it 'deletes everything from the Geo event log' do it 'deletes everything from the Geo event log' do
create_list(:geo_event_log, 2)
expect(worker).to receive(:log_info).with('No secondary nodes, delete all Geo Event Log entries') expect(worker).to receive(:log_info).with('No secondary nodes, delete all Geo Event Log entries')
expect(Geo::EventLog).to receive(:delete_all)
worker.perform expect { worker.perform }.to change { Geo::EventLog.count }.by(-2)
end end
end end
...@@ -64,28 +65,29 @@ describe Geo::PruneEventLogWorker, :geo do ...@@ -64,28 +65,29 @@ describe Geo::PruneEventLogWorker, :geo do
it 'contacts all secondary nodes for their status' do it 'contacts all secondary nodes for their status' do
expect(node_status_service).to receive(:call).twice { healthy_status } expect(node_status_service).to receive(:call).twice { healthy_status }
expect(worker).to receive(:log_info).with('Delete Geo Event Log entries up to id', anything) expect(worker).to receive(:log_info).with('Delete Geo Event Log entries up to id', anything)
expect(Geo::EventLog).to receive(:delete_all)
worker.perform worker.perform
end end
it 'aborts when there are unhealthy nodes' do it 'aborts when there are unhealthy nodes' do
create_list(:geo_event_log, 2)
expect(node_status_service).to receive(:call).twice.and_return(healthy_status, unhealthy_status) expect(node_status_service).to receive(:call).twice.and_return(healthy_status, unhealthy_status)
expect(worker).to receive(:log_info).with('Could not get status of all nodes, not deleting any entries from Geo Event Log', unhealthy_node_count: 1) expect(worker).to receive(:log_info).with('Could not get status of all nodes, not deleting any entries from Geo Event Log', unhealthy_node_count: 1)
expect(Geo::EventLog).not_to receive(:delete_all)
worker.perform expect { worker.perform }.not_to change { Geo::EventLog.count }
end end
it 'takes the integer-minimum value of all nodes' do it 'takes the integer-minimum value of all cursor_last_event_ids' do
events = create_list(:geo_event_log, 12)
allow(node_status_service).to receive(:call).twice.and_return( allow(node_status_service).to receive(:call).twice.and_return(
build(:geo_node_status, :healthy, cursor_last_event_id: 3), build(:geo_node_status, :healthy, cursor_last_event_id: events[3]),
build(:geo_node_status, :healthy, cursor_last_event_id: 10) build(:geo_node_status, :healthy, cursor_last_event_id: events.last)
) )
expect(worker).to receive(:log_info).with('Delete Geo Event Log entries up to id', geo_event_log_id: 3) expect(worker).to receive(:log_info).with('Delete Geo Event Log entries up to id', geo_event_log_id: events[3])
expect(Geo::EventLog).to receive(:delete_all).with(['id < ?', 3])
worker.perform expect { worker.perform }.to change { Geo::EventLog.count }.by(-3)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment