Commit 72e58df6 authored by Toon Claes's avatar Toon Claes

Make methods private as much as possible

parent 01ce3d7d
......@@ -60,6 +60,8 @@ module Gitlab
end
end
private
def track_gaps(current_id)
log_info("Event log gap detected", previous_event_id: previous_id, current_event_id: current_id)
......@@ -78,8 +80,6 @@ module Gitlab
current_id > (previous_id + 1)
end
private
def grace_timestamp
(Time.now - GAP_GRACE_PERIOD).to_i
end
......
......@@ -43,6 +43,8 @@ module Gitlab
end
end
private
def handle_events(batch, previous_batch_last_id)
logger.info("Handling events", first_id: batch.first.id, last_id: batch.last.id)
......
......@@ -18,12 +18,12 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
it 'returns the lowest gap id' do
Timecop.travel(50.minutes.ago) do
gap_tracking.previous_id = 18
gap_tracking.track_gaps(20)
gap_tracking.send(:track_gaps, 20)
end
Timecop.travel(40.minutes.ago) do
gap_tracking.previous_id = 12
gap_tracking.track_gaps(14)
gap_tracking.send(:track_gaps, 14)
end
expect(described_class.min_gap_id).to eq(13)
......@@ -37,10 +37,10 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
it 'returns the number of gaps' do
gap_tracking.previous_id = 18
gap_tracking.track_gaps(20)
gap_tracking.send(:track_gaps, 20)
gap_tracking.previous_id = 12
gap_tracking.track_gaps(14)
gap_tracking.send(:track_gaps, 14)
expect(described_class.gap_count).to eq(2)
end
......@@ -106,12 +106,12 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
it 'logs a message' do
expect(gap_tracking).to receive(:log_info).with(/gap detected/, hash_including(previous_event_id: previous_event_id, current_event_id: event_id_with_gap))
gap_tracking.track_gaps(event_id_with_gap)
gap_tracking.send(:track_gaps, event_id_with_gap)
end
it 'saves the gap id in redis' do
Timecop.freeze do
gap_tracking.track_gaps(event_id_with_gap)
gap_tracking.send(:track_gaps, event_id_with_gap)
expect(read_gaps).to contain_exactly([gap_id.to_s, Time.now.to_i])
end
......@@ -119,7 +119,7 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
it 'saves a range of gaps id in redis' do
Timecop.freeze do
gap_tracking.track_gaps(event_id_with_gap + 3)
gap_tracking.send(:track_gaps, event_id_with_gap + 3)
expected_gaps = ((previous_event_id + 1)..(event_id_with_gap + 2)).collect { |id| [id.to_s, Time.now.to_i] }
......@@ -131,13 +131,13 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
expected_gaps = []
Timecop.freeze do
gap_tracking.track_gaps(event_id_with_gap)
gap_tracking.send(:track_gaps, event_id_with_gap)
expected_gaps << [gap_id.to_s, Time.now.to_i]
end
Timecop.travel(2.minutes) do
gap_tracking.previous_id = 17
gap_tracking.track_gaps(19)
gap_tracking.send(:track_gaps, 19)
expected_gaps << [18.to_s, Time.now.to_i]
end
......@@ -147,25 +147,25 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
describe '#gap?' do
it 'returns false when current_id is the previous +1' do
expect(gap_tracking.gap?(previous_event_id + 1)).to be_falsy
expect(gap_tracking.send(:gap?, previous_event_id + 1)).to be_falsy
end
it 'returns true when current_id is the previous +2' do
expect(gap_tracking.gap?(previous_event_id + 2)).to be_truthy
expect(gap_tracking.send(:gap?, previous_event_id + 2)).to be_truthy
end
it 'returns false when current_id is equal to the previous' do
expect(gap_tracking.gap?(previous_event_id)).to be_falsy
expect(gap_tracking.send(:gap?, previous_event_id)).to be_falsy
end
it 'returns false when current_id less than the previous' do
expect(gap_tracking.gap?(previous_event_id - 1)).to be_falsy
expect(gap_tracking.send(:gap?, previous_event_id - 1)).to be_falsy
end
it 'returns false when previous id is 0' do
gap_tracking.previous_id = 0
expect(gap_tracking.gap?(100)).to be_falsy
expect(gap_tracking.send(:gap?, 100)).to be_falsy
end
end
......
......@@ -86,7 +86,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
end
it 'calls #handle_gap_event for each gap the gap tracking finds' do
allow(daemon.gap_tracking).to receive(:fill_gaps).and_yield(1).and_yield(5)
allow(daemon.send(:gap_tracking)).to receive(:fill_gaps).and_yield(1).and_yield(5)
expect(daemon).to receive(:handle_gap_event).with(1)
expect(daemon).to receive(:handle_gap_event).with(5)
......@@ -193,20 +193,20 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
let(:batch) { create_list(:geo_event_log, 2) }
it 'passes the previous batch id on to gap tracking' do
expect(daemon.gap_tracking).to receive(:previous_id=).with(55).ordered
expect(daemon.send(:gap_tracking)).to receive(:previous_id=).with(55).ordered
batch.each do |event_log|
expect(daemon.gap_tracking).to receive(:previous_id=).with(event_log.id).ordered
expect(daemon.send(:gap_tracking)).to receive(:previous_id=).with(event_log.id).ordered
end
daemon.handle_events(batch, 55)
daemon.send(:handle_events, batch, 55)
end
it 'checks for gaps for each id in batch' do
batch.each do |event_log|
expect(daemon.gap_tracking).to receive(:check!).with(event_log.id)
expect(daemon.send(:gap_tracking)).to receive(:check!).with(event_log.id)
end
daemon.handle_events(batch, 55)
daemon.send(:handle_events, batch, 55)
end
it 'handles every single event' do
......@@ -214,7 +214,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
expect(daemon).to receive(:handle_single_event).with(event_log)
end
daemon.handle_events(batch, 55)
daemon.send(:handle_events, batch, 55)
end
end
......@@ -225,20 +225,20 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
event_log = build(:geo_event_log)
expect(daemon).not_to receive(:can_replay?)
daemon.handle_single_event(event_log)
daemon.send(:handle_single_event, event_log)
end
it 'checks if it can replay the event' do
expect(daemon).to receive(:can_replay?)
daemon.handle_single_event(event_log)
daemon.send(:handle_single_event, event_log)
end
it 'processes event when it is replayable' do
allow(daemon).to receive(:can_replay?).and_return(true)
expect(daemon).to receive(:process_event).with(event_log.event, event_log)
daemon.handle_single_event(event_log)
daemon.send(:handle_single_event, event_log)
end
end
......@@ -246,7 +246,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
gaps = []
Timecop.travel(12.minutes) do
daemon.gap_tracking.fill_gaps { |id| gaps << id }
daemon.send(:gap_tracking).send(:fill_gaps, { |id| gaps << id })
end
gaps
......
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