Commit 31f207b0 authored by Kev's avatar Kev Committed by Rémy Coutable

Fix RSpec/TimecopFreeze offenses (Part 2/2)

parent 3b815509
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
RSpec/TimecopFreeze: RSpec/TimecopFreeze:
Exclude: Exclude:
- ee/spec/lib/gitlab/analytics/cycle_analytics/data_collector_spec.rb - ee/spec/lib/gitlab/analytics/cycle_analytics/data_collector_spec.rb
- ee/spec/lib/gitlab/geo/git_push_http_spec.rb
- ee/spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
- ee/spec/lib/gitlab/geo/oauth/login_state_spec.rb
- ee/spec/lib/gitlab/insights/reducers/count_per_period_reducer_spec.rb - ee/spec/lib/gitlab/insights/reducers/count_per_period_reducer_spec.rb
- ee/spec/models/merge_train_spec.rb - ee/spec/models/merge_train_spec.rb
- ee/spec/support/shared_contexts/lib/gitlab/insights/reducers/reducers_shared_contexts.rb - ee/spec/support/shared_contexts/lib/gitlab/insights/reducers/reducers_shared_contexts.rb
......
...@@ -24,16 +24,14 @@ RSpec.describe Gitlab::Geo::GitPushHttp, :geo, :use_clean_rails_memory_store_cac ...@@ -24,16 +24,14 @@ RSpec.describe Gitlab::Geo::GitPushHttp, :geo, :use_clean_rails_memory_store_cac
end end
it 'stores the ID with an expiration' do it 'stores the ID with an expiration' do
Timecop.freeze do
subject.cache_referrer_node(secondary.id) subject.cache_referrer_node(secondary.id)
Timecop.travel(described_class::EXPIRES_IN + 20.seconds) do travel_to((described_class::EXPIRES_IN + 20.seconds).from_now)
value = Rails.cache.read(cache_key) value = Rails.cache.read(cache_key)
expect(value).to be_nil expect(value).to be_nil
end end
end end
end
end
context 'when geo_node_id is not an integer' do context 'when geo_node_id is not an integer' do
it 'does not cache anything' do it 'does not cache anything' do
......
...@@ -81,25 +81,22 @@ RSpec.describe Gitlab::Geo::LogCursor::Daemon, :clean_gitlab_redis_shared_state ...@@ -81,25 +81,22 @@ RSpec.describe Gitlab::Geo::LogCursor::Daemon, :clean_gitlab_redis_shared_state
is_expected.to receive(:find_and_handle_events!).and_raise('any error').twice is_expected.to receive(:find_and_handle_events!).and_raise('any error').twice
Timecop.freeze do
daemon.run_once! daemon.run_once!
Timecop.travel(described_class::MAX_ERROR_DURATION + 1.second) do travel_to((described_class::MAX_ERROR_DURATION + 1.second).from_now) do
daemon.run_once! daemon.run_once!
end end
end end
end end
end
context 'when this error is not the final straw' do context 'when this error is not the final straw' do
it 'does not call `#exit!`' do it 'does not call `#exit!`' do
is_expected.not_to receive(:exit!) is_expected.not_to receive(:exit!)
Timecop.freeze do
is_expected.to receive(:find_and_handle_events!).and_raise('any error') is_expected.to receive(:find_and_handle_events!).and_raise('any error')
daemon.run_once! daemon.run_once!
Timecop.travel(described_class::MAX_ERROR_DURATION + 1.second) do travel_to((described_class::MAX_ERROR_DURATION + 1.second).from_now) do
is_expected.to receive(:find_and_handle_events!) # successful is_expected.to receive(:find_and_handle_events!) # successful
daemon.run_once! daemon.run_once!
...@@ -110,7 +107,6 @@ RSpec.describe Gitlab::Geo::LogCursor::Daemon, :clean_gitlab_redis_shared_state ...@@ -110,7 +107,6 @@ RSpec.describe Gitlab::Geo::LogCursor::Daemon, :clean_gitlab_redis_shared_state
end end
end end
end end
end
describe '#find_and_handle_events!' do describe '#find_and_handle_events!' do
context 'with some event logs' do context 'with some event logs' do
......
...@@ -9,7 +9,11 @@ RSpec.describe Gitlab::Geo::Oauth::LoginState do ...@@ -9,7 +9,11 @@ RSpec.describe Gitlab::Geo::Oauth::LoginState do
let(:timestamp) { Time.utc(2019, 2, 10, 19, 0, 0) } let(:timestamp) { Time.utc(2019, 2, 10, 19, 0, 0) }
around do |example| around do |example|
Timecop.freeze(timestamp) { example.run } if example.metadata[:no_traveling]
example.run
else
travel_to(timestamp) { example.run }
end
end end
before do before do
...@@ -68,12 +72,14 @@ RSpec.describe Gitlab::Geo::Oauth::LoginState do ...@@ -68,12 +72,14 @@ RSpec.describe Gitlab::Geo::Oauth::LoginState do
expect(subject.valid?).to eq(false) expect(subject.valid?).to eq(false)
end end
it "returns false when token's expired" do it "returns false when token's expired", :no_traveling do
subject = described_class.new(return_to: return_to, salt: salt, token: token) subject = travel_to(timestamp) do
described_class.new(return_to: return_to, salt: salt, token: token)
end
# Needs to be at least 120 seconds, because the default expiry is # Needs to be at least 120 seconds, because the default expiry is
# 60 seconds with an additional 60 second leeway. # 60 seconds with an additional 60 second leeway.
Timecop.freeze(timestamp + 125) do travel_to(timestamp + 125) do
expect(subject.valid?).to eq(false) expect(subject.valid?).to eq(false)
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