Commit e39da6a8 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'Fix-RSpec/TimecopFreeze-offenses-(Part-2/2)' into 'master'

Fix RSpec/TimecopFreeze offenses (Part 2/2)

See merge request gitlab-org/gitlab!76032
parents 85626631 31f207b0
...@@ -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,14 +24,12 @@ RSpec.describe Gitlab::Geo::GitPushHttp, :geo, :use_clean_rails_memory_store_cac ...@@ -24,14 +24,12 @@ 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)
travel_to((described_class::EXPIRES_IN + 20.seconds).from_now)
Timecop.travel(described_class::EXPIRES_IN + 20.seconds) do
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
......
...@@ -81,12 +81,10 @@ RSpec.describe Gitlab::Geo::LogCursor::Daemon, :clean_gitlab_redis_shared_state ...@@ -81,12 +81,10 @@ 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
...@@ -95,17 +93,15 @@ RSpec.describe Gitlab::Geo::LogCursor::Daemon, :clean_gitlab_redis_shared_state ...@@ -95,17 +93,15 @@ RSpec.describe Gitlab::Geo::LogCursor::Daemon, :clean_gitlab_redis_shared_state
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!
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!
end
end end
end end
end end
......
...@@ -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