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 @@
RSpec/TimecopFreeze:
Exclude:
- 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/models/merge_train_spec.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
end
it 'stores the ID with an expiration' do
Timecop.freeze do
subject.cache_referrer_node(secondary.id)
Timecop.travel(described_class::EXPIRES_IN + 20.seconds) do
value = Rails.cache.read(cache_key)
expect(value).to be_nil
end
end
subject.cache_referrer_node(secondary.id)
travel_to((described_class::EXPIRES_IN + 20.seconds).from_now)
value = Rails.cache.read(cache_key)
expect(value).to be_nil
end
end
......
......@@ -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
Timecop.freeze do
daemon.run_once!
daemon.run_once!
Timecop.travel(described_class::MAX_ERROR_DURATION + 1.second) do
daemon.run_once!
end
travel_to((described_class::MAX_ERROR_DURATION + 1.second).from_now) do
daemon.run_once!
end
end
end
......@@ -95,17 +93,15 @@ RSpec.describe Gitlab::Geo::LogCursor::Daemon, :clean_gitlab_redis_shared_state
it 'does not call `#exit!`' do
is_expected.not_to receive(:exit!)
Timecop.freeze do
is_expected.to receive(:find_and_handle_events!).and_raise('any error')
daemon.run_once!
is_expected.to receive(:find_and_handle_events!).and_raise('any error')
daemon.run_once!
Timecop.travel(described_class::MAX_ERROR_DURATION + 1.second) do
is_expected.to receive(:find_and_handle_events!) # successful
daemon.run_once!
travel_to((described_class::MAX_ERROR_DURATION + 1.second).from_now) do
is_expected.to receive(:find_and_handle_events!) # successful
daemon.run_once!
is_expected.to receive(:find_and_handle_events!).and_raise('any error')
daemon.run_once!
end
is_expected.to receive(:find_and_handle_events!).and_raise('any error')
daemon.run_once!
end
end
end
......
......@@ -9,7 +9,11 @@ RSpec.describe Gitlab::Geo::Oauth::LoginState do
let(:timestamp) { Time.utc(2019, 2, 10, 19, 0, 0) }
around do |example|
Timecop.freeze(timestamp) { example.run }
if example.metadata[:no_traveling]
example.run
else
travel_to(timestamp) { example.run }
end
end
before do
......@@ -68,12 +72,14 @@ RSpec.describe Gitlab::Geo::Oauth::LoginState do
expect(subject.valid?).to eq(false)
end
it "returns false when token's expired" do
subject = described_class.new(return_to: return_to, salt: salt, token: token)
it "returns false when token's expired", :no_traveling do
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
# 60 seconds with an additional 60 second leeway.
Timecop.freeze(timestamp + 125) do
travel_to(timestamp + 125) do
expect(subject.valid?).to eq(false)
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