Commit f7112776 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ee-32004-use-timecop-safe-mode' into 'master'

[EE] Enable Timecop safe mode

See merge request !2664
parents 0a365bda f9aaeee6
...@@ -13,8 +13,11 @@ describe 'Issue Boards', :js do ...@@ -13,8 +13,11 @@ describe 'Issue Boards', :js do
let!(:list) { create(:list, board: board, label: development, position: 0) } let!(:list) { create(:list, board: board, label: development, position: 0) }
let(:card) { find('.board:nth-child(2)').first('.card') } let(:card) { find('.board:nth-child(2)').first('.card') }
around do |example|
Timecop.freeze { example.run }
end
before do before do
Timecop.freeze
stub_licensed_features(multiple_issue_assignees: true) stub_licensed_features(multiple_issue_assignees: true)
project.team << [user, :master] project.team << [user, :master]
...@@ -26,10 +29,6 @@ describe 'Issue Boards', :js do ...@@ -26,10 +29,6 @@ describe 'Issue Boards', :js do
wait_for_requests wait_for_requests
end end
after do
Timecop.return
end
context 'assignee' do context 'assignee' do
it 'updates the issues assignee' do it 'updates the issues assignee' do
click_card(card) click_card(card)
......
...@@ -15,11 +15,13 @@ describe 'Issue Boards', js: true do ...@@ -15,11 +15,13 @@ describe 'Issue Boards', js: true do
let!(:list) { create(:list, board: board, label: development, position: 0) } let!(:list) { create(:list, board: board, label: development, position: 0) }
let(:card) { find('.board:nth-child(2)').first('.card') } let(:card) { find('.board:nth-child(2)').first('.card') }
around do |example|
Timecop.freeze { example.run }
end
before do before do
Timecop.freeze
stub_licensed_features(multiple_issue_assignees: false) stub_licensed_features(multiple_issue_assignees: false)
project.add_master(user)
project.team << [user, :master]
sign_in(user) sign_in(user)
...@@ -27,10 +29,6 @@ describe 'Issue Boards', js: true do ...@@ -27,10 +29,6 @@ describe 'Issue Boards', js: true do
wait_for_requests wait_for_requests
end end
after do
Timecop.return
end
it 'shows sidebar when clicking issue' do it 'shows sidebar when clicking issue' do
click_card(card) click_card(card)
......
...@@ -5,14 +5,12 @@ feature 'Group milestones', :js do ...@@ -5,14 +5,12 @@ feature 'Group milestones', :js do
let!(:project) { create(:project_empty_repo, group: group) } let!(:project) { create(:project_empty_repo, group: group) }
let(:user) { create(:group_member, :master, user: create(:user), group: group ).user } let(:user) { create(:group_member, :master, user: create(:user), group: group ).user }
before do around do |example|
Timecop.freeze Timecop.freeze { example.run }
sign_in(user)
end end
after do before do
Timecop.return sign_in(user)
end end
context 'create a milestone' do context 'create a milestone' do
......
...@@ -8,16 +8,12 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do ...@@ -8,16 +8,12 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do
subject { background_migration.perform(cutoff_datetime) } subject { background_migration.perform(cutoff_datetime) }
context 'when an SSH key was created after the cutoff datetime' do around do |example|
before do Timecop.travel(1.day.from_now) { example.run }
Timecop.freeze
end
after do
Timecop.return
end end
context 'when an SSH key was created after the cutoff datetime' do
before do before do
Timecop.travel 1.day.from_now
@key = create(:key) @key = create(:key)
end end
...@@ -38,16 +34,12 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do ...@@ -38,16 +34,12 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do
subject { background_migration.add_keys_since(cutoff_datetime) } subject { background_migration.add_keys_since(cutoff_datetime) }
before do around do |example|
Timecop.freeze Timecop.travel(1.day.from_now) { example.run }
end
after do
Timecop.return
end end
context 'when an SSH key was created after the cutoff datetime' do context 'when an SSH key was created after the cutoff datetime' do
before do before do
Timecop.travel 1.day.from_now
@key = create(:key) @key = create(:key)
create(:key) # other key create(:key) # other key
end end
......
...@@ -175,11 +175,7 @@ describe Gitlab::Git::Storage::CircuitBreaker, clean_gitlab_redis_shared_state: ...@@ -175,11 +175,7 @@ describe Gitlab::Git::Storage::CircuitBreaker, clean_gitlab_redis_shared_state:
describe '#track_storage_inaccessible' do describe '#track_storage_inaccessible' do
around do |example| around do |example|
Timecop.freeze Timecop.freeze { example.run }
example.run
Timecop.return
end end
it 'records the failure time in redis' do it 'records the failure time in redis' do
......
...@@ -4,10 +4,6 @@ describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -4,10 +4,6 @@ describe Gitlab::Metrics::RequestsRackMiddleware do
let(:app) { double('app') } let(:app) { double('app') }
subject { described_class.new(app) } subject { described_class.new(app) }
around do |example|
Timecop.freeze { example.run }
end
describe '#call' do describe '#call' do
let(:status) { 100 } let(:status) { 100 }
let(:env) { { 'REQUEST_METHOD' => 'GET' } } let(:env) { { 'REQUEST_METHOD' => 'GET' } }
...@@ -28,16 +24,14 @@ describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -28,16 +24,14 @@ describe Gitlab::Metrics::RequestsRackMiddleware do
subject.call(env) subject.call(env)
end end
it 'measures execution time' do RSpec::Matchers.define :a_positive_execution_time do
execution_time = 10 match { |actual| actual > 0 }
allow(app).to receive(:call) do |*args|
Timecop.freeze(execution_time.seconds)
[200, nil, nil]
end end
expect(described_class).to receive_message_chain(:http_request_duration_seconds, :observe).with({ status: 200, method: 'get' }, execution_time) it 'measures execution time' do
expect(described_class).to receive_message_chain(:http_request_duration_seconds, :observe).with({ status: 200, method: 'get' }, a_positive_execution_time)
subject.call(env) Timecop.scale(3600) { subject.call(env) }
end end
end end
......
...@@ -21,21 +21,17 @@ describe UpdateAuthorizedKeysFile, :migration do ...@@ -21,21 +21,17 @@ describe UpdateAuthorizedKeysFile, :migration do
end end
context 'there are keys created before and after the cutoff datetime' do context 'there are keys created before and after the cutoff datetime' do
before do
Timecop.freeze
end
after do
Timecop.return
end
before do before do
@cutoff_datetime = UpdateAuthorizedKeysFile::DATETIME_9_3_0_RELEASED @cutoff_datetime = UpdateAuthorizedKeysFile::DATETIME_9_3_0_RELEASED
@keys = [] @keys = []
Timecop.travel(@cutoff_datetime - 1.day) Timecop.travel(@cutoff_datetime - 1.day) do
2.times { @keys << create(:key) } # 2 keys before cutoff 2.times { @keys << create(:key) } # 2 keys before cutoff
Timecop.travel(@cutoff_datetime + 1.day) end
Timecop.travel(@cutoff_datetime + 1.day) do
2.times { @keys << create(:key) } # 2 keys after cutoff 2.times { @keys << create(:key) } # 2 keys after cutoff
end end
end
it 'adds the keys created after the cutoff datetime to the authorized_keys file' do it 'adds the keys created after the cutoff datetime to the authorized_keys file' do
Gitlab::Shell.new.remove_all_keys Gitlab::Shell.new.remove_all_keys
......
...@@ -18,15 +18,17 @@ describe Burndown do ...@@ -18,15 +18,17 @@ describe Burndown do
} }
end end
around do |example|
Timecop.travel(due_date) do
example.run
end
end
before do before do
project.add_master(user) project.add_master(user)
build_sample build_sample
end end
after do
Timecop.return
end
subject { described_class.new(milestone).to_json } subject { described_class.new(milestone).to_json }
it "generates an array with date, issue count and weight" do it "generates an array with date, issue count and weight" do
...@@ -52,10 +54,10 @@ describe Burndown do ...@@ -52,10 +54,10 @@ describe Burndown do
end end
it "it counts until today if milestone due date > Date.today" do it "it counts until today if milestone due date > Date.today" do
Timecop.travel(milestone.due_date - 1.day) Timecop.travel(milestone.due_date - 1.day) do
expect(JSON.parse(subject).last[0]).to eq(Time.now.strftime("%Y-%m-%d")) expect(JSON.parse(subject).last[0]).to eq(Time.now.strftime("%Y-%m-%d"))
end end
end
it "sets attribute accurate to true" do it "sets attribute accurate to true" do
burndown = described_class.new(milestone) burndown = described_class.new(milestone)
...@@ -104,8 +106,7 @@ describe Burndown do ...@@ -104,8 +106,7 @@ describe Burndown do
next if day.even? next if day.even?
count = day * 4 count = day * 4
Timecop.travel(date) Timecop.travel(date) do
# Create issues # Create issues
issues = create_list(:issue, count, issue_params) issues = create_list(:issue, count, issue_params)
...@@ -116,7 +117,6 @@ describe Burndown do ...@@ -116,7 +117,6 @@ describe Burndown do
# Reopen issues # Reopen issues
closed.slice(0..count / 4).each(&:reopen) closed.slice(0..count / 4).each(&:reopen)
end end
end
Timecop.travel(due_date)
end end
end end
...@@ -57,18 +57,14 @@ describe Issue do ...@@ -57,18 +57,14 @@ describe Issue do
end end
describe '#closed_at' do describe '#closed_at' do
after do
Timecop.return
end
let!(:now) { Timecop.freeze(Time.now) }
it 'sets closed_at to Time.now when issue is closed' do it 'sets closed_at to Time.now when issue is closed' do
issue = create(:issue, state: 'opened') issue = create(:issue, state: 'opened')
expect(issue.closed_at).to be_nil
issue.close issue.close
expect(issue.closed_at).to eq(now) expect(issue.closed_at).to be_present
end end
end end
......
...@@ -88,12 +88,8 @@ describe RemoteMirror do ...@@ -88,12 +88,8 @@ describe RemoteMirror do
context '#sync' do context '#sync' do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first } let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
before do around do |example|
Timecop.freeze(Time.now) Timecop.freeze { example.run }
end
after do
Timecop.return
end end
context 'repository mirrors not licensed' do context 'repository mirrors not licensed' do
...@@ -145,13 +141,12 @@ describe RemoteMirror do ...@@ -145,13 +141,12 @@ describe RemoteMirror do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first } let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
let(:timestamp) { Time.now - 5.minutes } let(:timestamp) { Time.now - 5.minutes }
before do around do |example|
Timecop.freeze(Time.now) Timecop.freeze { example.run }
remote_mirror.update_attributes(last_update_started_at: Time.now)
end end
after do before do
Timecop.return remote_mirror.update_attributes(last_update_started_at: Time.now)
end end
context 'when remote mirror does not have status failed' do context 'when remote mirror does not have status failed' do
......
...@@ -229,13 +229,12 @@ describe API::Internal do ...@@ -229,13 +229,12 @@ describe API::Internal do
describe "POST /internal/allowed", :clean_gitlab_redis_shared_state do describe "POST /internal/allowed", :clean_gitlab_redis_shared_state do
context "access granted" do context "access granted" do
before do around do |example|
project.team << [user, :developer] Timecop.freeze { example.run }
Timecop.freeze
end end
after do before do
Timecop.return project.team << [user, :developer]
end end
context 'with env passed as a JSON' do context 'with env passed as a JSON' do
......
...@@ -13,12 +13,8 @@ describe AnalyticsBuildEntity do ...@@ -13,12 +13,8 @@ describe AnalyticsBuildEntity do
subject { entity.as_json } subject { entity.as_json }
before do around do |example|
Timecop.freeze Timecop.freeze { example.run }
end
after do
Timecop.return
end end
it 'contains the URL' do it 'contains the URL' do
......
...@@ -83,6 +83,7 @@ RSpec.configure do |config| ...@@ -83,6 +83,7 @@ RSpec.configure do |config|
end end
config.before(:suite) do config.before(:suite) do
Timecop.safe_mode = true
TestEnv.init TestEnv.init
end end
......
...@@ -6,12 +6,8 @@ describe RepositoryUpdateRemoteMirrorWorker do ...@@ -6,12 +6,8 @@ describe RepositoryUpdateRemoteMirrorWorker do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first } let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
let(:scheduled_time) { Time.now - 5.minutes } let(:scheduled_time) { Time.now - 5.minutes }
before do around do |example|
Timecop.freeze(Time.now) Timecop.freeze(Time.now) { example.run }
end
after do
Timecop.return
end end
describe '#perform' do describe '#perform' do
......
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