Commit b34dd89a authored by Sean Arnold's avatar Sean Arnold Committed by Stan Hu

Replace Time.now => Time.current in ee models

- models folder
- specs folder
parent c74cd3aa
......@@ -61,7 +61,7 @@ module Geo
model_record.update!(
verification_checksum: checksum,
verified_at: Time.now,
verified_at: Time.current,
verification_failure: failure,
verification_retry_at: retry_at,
verification_retry_count: retry_count
......
......@@ -6,7 +6,7 @@ module Geo::Syncable
included do
scope :failed, -> { where(success: false) }
scope :synced, -> { where(success: true) }
scope :retry_due, -> { where('retry_at is NULL OR retry_at < ?', Time.now) }
scope :retry_due, -> { where('retry_at is NULL OR retry_at < ?', Time.current) }
scope :missing_on_primary, -> { where(missing_on_primary: true) }
end
end
......@@ -38,7 +38,7 @@ module EE
description_versions =
issuable_description_versions.where('id BETWEEN ? AND ?', start_id, self.id)
description_versions.update_all(deleted_at: Time.now)
description_versions.update_all(deleted_at: Time.current)
issuable&.expire_note_etag_cache
end
......
......@@ -123,12 +123,12 @@ module EE
end
after_transition ready: :started do |group, _|
group.ldap_sync_last_sync_at = DateTime.now
group.ldap_sync_last_sync_at = DateTime.current
group.save
end
after_transition started: :ready do |group, _|
current_time = DateTime.now
current_time = DateTime.current
group.ldap_sync_last_update_at = current_time
group.ldap_sync_last_successful_update_at = current_time
group.ldap_sync_error = nil
......@@ -136,7 +136,7 @@ module EE
end
after_transition started: :failed do |group, _|
group.ldap_sync_last_update_at = DateTime.now
group.ldap_sync_last_update_at = DateTime.current
group.save
end
end
......
......@@ -22,7 +22,7 @@ module EE
end
def review_end_at
merged_at || Time.now
merged_at || Time.current
end
end
end
......
......@@ -15,16 +15,16 @@ module EE
state_machine :status, initial: :none do
before_transition [:none, :finished, :failed] => :scheduled do |state, _|
state.last_update_scheduled_at = Time.now
state.last_update_scheduled_at = Time.current
end
before_transition scheduled: :started do |state, _|
state.last_update_started_at = Time.now
state.last_update_started_at = Time.current
end
before_transition scheduled: :failed do |state, _|
if state.mirror?
state.last_update_at = Time.now
state.last_update_at = Time.current
state.set_next_execution_to_now
end
end
......@@ -41,7 +41,7 @@ module EE
before_transition started: :failed do |state, _|
if state.mirror?
state.last_update_at = Time.now
state.last_update_at = Time.current
state.increment_retry_count
state.set_next_execution_timestamp
end
......@@ -49,7 +49,7 @@ module EE
before_transition started: :finished do |state, _|
if state.mirror?
timestamp = Time.now
timestamp = Time.current
state.last_update_at = timestamp
state.last_successful_update_at = timestamp
......@@ -101,7 +101,7 @@ module EE
return false if hard_failed?
return false if updating_mirror?
next_execution_timestamp <= Time.now
next_execution_timestamp <= Time.current
end
def last_update_status
......@@ -137,7 +137,7 @@ module EE
# We schedule the next sync time based on the duration of the
# last mirroring period and add it a fixed backoff period with a random jitter
def set_next_execution_timestamp
timestamp = Time.now
timestamp = Time.current
retry_factor = [1, self.retry_count].max
delay = [base_delay(timestamp), ::Gitlab::Mirror.min_delay].max
delay = [delay * retry_factor, ::Gitlab::Mirror.max_delay].min
......@@ -159,7 +159,7 @@ module EE
def set_next_execution_to_now(prioritized: false)
return unless mirror?
self.next_execution_timestamp = prioritized ? 5.minutes.ago : Time.now
self.next_execution_timestamp = prioritized ? 5.minutes.ago : Time.current
end
def retry_limit_exceeded?
......
......@@ -306,7 +306,7 @@ module EE
end
def admin_unsubscribe!
update_column :admin_email_unsubscribed_at, Time.now
update_column :admin_email_unsubscribed_at, Time.current
end
override :allow_password_authentication_for_web?
......
......@@ -20,7 +20,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord
def self.index_first_n_namespaces_of_plan(plan, number_of_namespaces)
indexed_namespaces = self.select(:namespace_id)
now = Time.now
now = Time.current
ids = GitlabSubscription
.with_hosted_plan(plan)
......
......@@ -8,7 +8,7 @@ class Geo::ContainerRepositoryRegistry < Geo::BaseRegistry
scope :repository_id_not_in, -> (ids) { where.not(container_repository_id: ids) }
scope :failed, -> { with_state(:failed) }
scope :synced, -> { with_state(:synced) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.now))) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.current))) }
state_machine :state, initial: :pending do
state :started
......@@ -17,7 +17,7 @@ class Geo::ContainerRepositoryRegistry < Geo::BaseRegistry
state :pending
before_transition any => :started do |registry, _|
registry.last_synced_at = Time.now
registry.last_synced_at = Time.current
end
before_transition any => :pending do |registry, _|
......
......@@ -10,7 +10,7 @@ class Geo::DesignRegistry < Geo::BaseRegistry
scope :pending, -> { with_state(:pending) }
scope :failed, -> { with_state(:failed) }
scope :synced, -> { with_state(:synced) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.now))) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.current))) }
state_machine :state, initial: :pending do
state :started
......@@ -19,7 +19,7 @@ class Geo::DesignRegistry < Geo::BaseRegistry
state :pending
before_transition any => :started do |registry, _|
registry.last_synced_at = Time.now
registry.last_synced_at = Time.current
end
before_transition any => :pending do |registry, _|
......
......@@ -20,7 +20,7 @@ class Geo::PackageFileRegistry < Geo::BaseRegistry
scope :never, -> { where(last_synced_at: nil) }
scope :failed, -> { with_state(:failed) }
scope :synced, -> { with_state(:synced) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.now))) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.current))) }
scope :ordered, -> { order(:id) }
state_machine :state, initial: :pending do
......@@ -30,7 +30,7 @@ class Geo::PackageFileRegistry < Geo::BaseRegistry
state :failed, value: STATE_VALUES[:failed]
before_transition any => :started do |registry, _|
registry.last_synced_at = Time.now
registry.last_synced_at = Time.current
end
before_transition any => :pending do |registry, _|
......
......@@ -68,8 +68,8 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
def self.retry_due
where(
arel_table[:repository_retry_at].lt(Time.now)
.or(arel_table[:wiki_retry_at].lt(Time.now))
arel_table[:repository_retry_at].lt(Time.current)
.or(arel_table[:wiki_retry_at].lt(Time.current))
.or(arel_table[:repository_retry_at].eq(nil))
.or(arel_table[:wiki_retry_at].eq(nil))
)
......@@ -180,7 +180,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
repository_checksum_mismatch: false,
last_repository_verification_failure: nil,
repository_verification_retry_count: nil,
resync_repository_was_scheduled_at: Time.now,
resync_repository_was_scheduled_at: Time.current,
repository_retry_count: nil,
repository_retry_at: nil
)
......@@ -223,7 +223,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
ensure_valid_type!(type)
update!(
"last_#{type}_synced_at" => Time.now,
"last_#{type}_synced_at" => Time.current,
"#{type}_retry_count" => retry_count(type))
end
......@@ -235,7 +235,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
ensure_valid_type!(type)
update!(
# Indicate that the sync succeeded (but separately mark as synced atomically)
"last_#{type}_successful_sync_at" => Time.now,
"last_#{type}_successful_sync_at" => Time.current,
"#{type}_retry_count" => nil,
"#{type}_retry_at" => nil,
"force_to_redownload_#{type}" => false,
......@@ -404,7 +404,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
#
# This operation happens only in the database and the resync will be triggered after by the cron job
def flag_repository_for_resync!
repository_updated!(:repository, Time.now)
repository_updated!(:repository, Time.current)
end
# Flag the repository to perform a full re-download
......
......@@ -246,7 +246,7 @@ class GeoNodeStatus < ApplicationRecord
latest_event = Geo::EventLog.latest_event
self.last_event_id = latest_event&.id
self.last_event_date = latest_event&.created_at
self.last_successful_status_check_at = Time.now
self.last_successful_status_check_at = Time.current
self.storage_shards = StorageShard.all
self.storage_configuration_digest = StorageShard.build_digest
......
......@@ -29,7 +29,7 @@ module Gitlab
end
def default_date
Time.now.utc.yesterday.to_date
Time.current.utc.yesterday.to_date
end
def default_key
......
......@@ -40,11 +40,11 @@ module Vulnerabilities
state :failed
before_transition created: :running do |export|
export.started_at = Time.now
export.started_at = Time.current
end
before_transition any => [:finished, :failed] do |export|
export.finished_at = Time.now
export.finished_at = Time.current
end
end
......
......@@ -40,8 +40,8 @@ describe MergeRequest::Metrics do
end
context 'when MR is not merged' do
it 'is Time.now' do
expect(subject.review_end_at).to be_like_time(Time.now)
it 'is Time.current' do
expect(subject.review_end_at).to be_like_time(Time.current)
end
end
end
......
......@@ -345,7 +345,7 @@ describe Epic do
end
it_behaves_like 'within_timeframe scope' do
let_it_be(:now) { Time.now }
let_it_be(:now) { Time.current }
let_it_be(:group) { create(:group) }
let_it_be(:resource_1) { create(:epic, group: group, start_date: now - 1.day, end_date: now + 1.day) }
let_it_be(:resource_2) { create(:epic, group: group, start_date: now + 2.days, end_date: now + 3.days) }
......@@ -458,7 +458,7 @@ describe Epic do
describe '#close' do
subject(:epic) { create(:epic, state: 'opened') }
it 'sets closed_at to Time.now when an epic is closed' do
it 'sets closed_at to Time.current when an epic is closed' do
expect { epic.close }.to change { epic.closed_at }.from(nil)
end
......@@ -468,7 +468,7 @@ describe Epic do
end
describe '#reopen' do
subject(:epic) { create(:epic, state: 'closed', closed_at: Time.now, closed_by: user) }
subject(:epic) { create(:epic, state: 'closed', closed_at: Time.current, closed_by: user) }
it 'sets closed_at to nil when an epic is reopend' do
expect { epic.reopen }.to change { epic.closed_at }.to(nil)
......
......@@ -284,7 +284,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
describe '#repository_sync_due?' do
where(:last_synced_at, :resync, :retry_at, :expected) do
now = Time.now
now = Time.current
past = now - 1.year
future = now + 1.year
......@@ -313,13 +313,13 @@ describe Geo::ProjectRegistry, :geo_fdw do
)
end
it { expect(registry.repository_sync_due?(Time.now)).to eq(expected) }
it { expect(registry.repository_sync_due?(Time.current)).to eq(expected) }
end
end
describe '#wiki_sync_due?' do
where(:last_synced_at, :resync, :retry_at, :expected) do
now = Time.now
now = Time.current
past = now - 1.year
future = now + 1.year
......@@ -348,7 +348,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
)
end
it { expect(registry.wiki_sync_due?(Time.now)).to eq(expected) }
it { expect(registry.wiki_sync_due?(Time.current)).to eq(expected) }
end
end
......@@ -405,7 +405,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
it 'sets last_repository_synced_at to now' do
subject.start_sync!(type)
expect(subject.last_repository_synced_at).to be_like_time(Time.now)
expect(subject.last_repository_synced_at).to be_like_time(Time.current)
end
context 'when repository_retry_count is nil' do
......@@ -423,7 +423,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
it 'sets last_wiki_synced_at to now' do
subject.start_sync!(type)
expect(subject.last_wiki_synced_at).to be_like_time(Time.now)
expect(subject.last_wiki_synced_at).to be_like_time(Time.current)
end
context 'when wiki_retry_count is nil' do
......@@ -456,7 +456,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
Timecop.freeze do
subject.finish_sync!(type)
expect(subject.reload.last_repository_successful_sync_at).to be_within(1).of(Time.now)
expect(subject.reload.last_repository_successful_sync_at).to be_within(1).of(Time.current)
end
end
......@@ -551,7 +551,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
Timecop.freeze do
subject.finish_sync!(type)
expect(subject.reload.last_wiki_successful_sync_at).to be_within(1).of(Time.now)
expect(subject.reload.last_wiki_successful_sync_at).to be_within(1).of(Time.current)
end
end
......@@ -645,7 +645,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
subject.fail_sync!(type, message, error)
expect(subject.repository_retry_at > Time.now).to be(true)
expect(subject.repository_retry_at > Time.current).to be(true)
end
it 'ensures repository_retry_at is capped at one hour' do
......@@ -730,7 +730,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
subject.fail_sync!(type, message, error)
expect(subject.wiki_retry_at > Time.now).to be(true)
expect(subject.wiki_retry_at > Time.current).to be(true)
end
it 'ensures wiki_retry_at is capped at one hour' do
......@@ -840,7 +840,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
repository_retry_count: 1,
repository_verification_retry_count: 1)
subject.repository_updated!(event.source, Time.now)
subject.repository_updated!(event.source, Time.current)
end
it 'resets sync state' do
......@@ -851,7 +851,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
force_to_redownload_repository: nil,
last_repository_sync_failure: nil,
repository_missing_on_primary: nil,
resync_repository_was_scheduled_at: be_within(1.minute).of(Time.now)
resync_repository_was_scheduled_at: be_within(1.minute).of(Time.current)
)
end
......@@ -878,7 +878,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
wiki_retry_count: 1,
wiki_verification_retry_count: 1)
subject.repository_updated!(event.source, Time.now)
subject.repository_updated!(event.source, Time.current)
end
it 'resets sync state' do
......@@ -889,7 +889,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
force_to_redownload_wiki: nil,
last_wiki_sync_failure: nil,
wiki_missing_on_primary: nil,
resync_wiki_was_scheduled_at: be_within(1.minute).of(Time.now)
resync_wiki_was_scheduled_at: be_within(1.minute).of(Time.current)
)
end
......@@ -1098,7 +1098,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
context 'when repository has successfully synced' do
it 'returns true' do
registry = create(:geo_project_registry, last_repository_successful_sync_at: Time.now)
registry = create(:geo_project_registry, last_repository_successful_sync_at: Time.current)
expect(registry.repository_has_successfully_synced?).to be_truthy
end
......
......@@ -1077,7 +1077,7 @@ describe GeoNodeStatus, :geo, :geo_fdw do
shared_examples 'timestamp parameters' do |timestamp_column, date_column|
it 'returns the value it was assigned via UNIX timestamp' do
now = Time.now.beginning_of_day.utc
now = Time.current.beginning_of_day.utc
subject.update_attribute(timestamp_column, now.to_i)
expect(subject.public_send(date_column)).to eq(now)
......
......@@ -45,7 +45,7 @@ describe HistoricalData do
context 'with multiple historical data points for the current license' do
before do
(1..3).each do |i|
described_class.create!(date: Time.now - i.days, active_user_count: i * 100)
described_class.create!(date: Time.current - i.days, active_user_count: i * 100)
end
end
......
......@@ -13,7 +13,7 @@ describe IssuablesAnalytics do
end
before do
Timecop.freeze(Time.now) do
Timecop.freeze(Time.current) do
seed.each_pair do |months_back, issues_count|
create_list(:issue, issues_count, project: project, created_at: months_back.months.ago)
end
......
......@@ -29,7 +29,7 @@ describe ProjectFeatureUsage, type: :model do
subject.log_jira_dvcs_integration_usage
expect(subject.jira_dvcs_server_last_sync_at).to be_nil
expect(subject.jira_dvcs_cloud_last_sync_at).to be_like_time(Time.now)
expect(subject.jira_dvcs_cloud_last_sync_at).to be_like_time(Time.current)
end
end
......@@ -37,7 +37,7 @@ describe ProjectFeatureUsage, type: :model do
Timecop.freeze do
subject.log_jira_dvcs_integration_usage(cloud: false)
expect(subject.jira_dvcs_server_last_sync_at).to be_like_time(Time.now)
expect(subject.jira_dvcs_server_last_sync_at).to be_like_time(Time.current)
expect(subject.jira_dvcs_cloud_last_sync_at).to be_nil
end
end
......
......@@ -59,7 +59,7 @@ describe ProjectImportState, type: :model do
end
context 'with index status' do
let(:index_status) { IndexStatus.create!(project: project, indexed_at: Time.now, last_commit: 'foo') }
let(:index_status) { IndexStatus.create!(project: project, indexed_at: Time.current, last_commit: 'foo') }
it 'schedules a full index of the repository' do
expect(ElasticCommitIndexerWorker).to receive(:perform_async).with(import_state.project_id)
......@@ -73,10 +73,10 @@ describe ProjectImportState, type: :model do
describe 'when create' do
it 'sets next execution timestamp to now' do
Timecop.freeze(Time.now) do
Timecop.freeze(Time.current) do
import_state = create(:import_state, :mirror)
expect(import_state.next_execution_timestamp).to be_like_time(Time.now)
expect(import_state.next_execution_timestamp).to be_like_time(Time.current)
end
end
end
......@@ -223,7 +223,7 @@ describe ProjectImportState, type: :model do
:finished,
:mirror,
:repository,
next_execution_timestamp: Time.now - 2.minutes)
next_execution_timestamp: Time.current - 2.minutes)
expect(import_state.mirror_update_due?).to be true
end
......@@ -235,7 +235,7 @@ describe ProjectImportState, type: :model do
:finished,
:mirror,
:repository,
next_execution_timestamp: Time.now - 2.minutes)
next_execution_timestamp: Time.current - 2.minutes)
end
before do
......@@ -250,7 +250,7 @@ describe ProjectImportState, type: :model do
context 'when mirror has no content' do
it 'returns false' do
import_state = create(:import_state, :finished, :mirror)
import_state.next_execution_timestamp = Time.now - 2.minutes
import_state.next_execution_timestamp = Time.current - 2.minutes
expect(import_state.mirror_update_due?).to be false
end
......@@ -301,7 +301,7 @@ describe ProjectImportState, type: :model do
end
context 'when mirror has updated' do
let(:timestamp) { Time.now }
let(:timestamp) { Time.current }
before do
import_state.last_update_at = timestamp
......@@ -341,15 +341,15 @@ describe ProjectImportState, type: :model do
end
it 'returns false when first update failed' do
import_state.last_update_at = Time.now
import_state.last_update_at = Time.current
expect(import_state.ever_updated_successfully?).to be_falsey
end
it 'returns true when a successful update timestamp exists' do
# It does not matter if the last update was successful or not
import_state.last_update_at = Time.now
import_state.last_successful_update_at = Time.now - 5.minutes
import_state.last_update_at = Time.current
import_state.last_successful_update_at = Time.current - 5.minutes
expect(import_state.ever_updated_successfully?).to be_truthy
end
......@@ -358,7 +358,7 @@ describe ProjectImportState, type: :model do
describe '#set_next_execution_timestamp' do
let(:import_state) { create(:import_state, :mirror, :finished) }
let!(:timestamp) { Time.now.change(usec: 0) }
let!(:timestamp) { Time.current.change(usec: 0) }
let!(:jitter) { 2.seconds }
before do
......@@ -458,7 +458,7 @@ describe ProjectImportState, type: :model do
import_state = create(:import_state,
:repository,
:mirror,
next_execution_timestamp: Time.now - 2.minutes)
next_execution_timestamp: Time.current - 2.minutes)
expect(import_state.force_import_job!).to be_nil
end
......@@ -470,7 +470,7 @@ describe ProjectImportState, type: :model do
end
it 'sets next execution timestamp to 5 minutes ago and schedules UpdateAllMirrorsWorker' do
timestamp = Time.now
timestamp = Time.current
import_state = create(:import_state, :mirror)
expect(UpdateAllMirrorsWorker).to receive(:perform_async)
......@@ -482,7 +482,7 @@ describe ProjectImportState, type: :model do
context 'when mirror is hard failed' do
it 'resets retry count and schedules a mirroring worker' do
timestamp = Time.now
timestamp = Time.current
import_state = create(:import_state, :mirror, :hard_failed)
expect(UpdateAllMirrorsWorker).to receive(:perform_async)
......
......@@ -322,7 +322,7 @@ describe Project do
project.save
end.to change { ProjectImportState.count }.by(1)
expect(project.import_state.next_execution_timestamp).to be_like_time(Time.now)
expect(project.import_state.next_execution_timestamp).to be_like_time(Time.current)
end
end
end
......@@ -337,7 +337,7 @@ describe Project do
project.update(mirror: true, mirror_user_id: project.creator.id, import_url: generate(:url))
end.to change { ProjectImportState.count }.by(1)
expect(project.import_state.next_execution_timestamp).to be_like_time(Time.now)
expect(project.import_state.next_execution_timestamp).to be_like_time(Time.current)
end
end
end
......@@ -351,7 +351,7 @@ describe Project do
project.update(mirror: true, mirror_user_id: project.creator.id)
end.not_to change { ProjectImportState.count }
expect(project.import_state.next_execution_timestamp).to be_like_time(Time.now)
expect(project.import_state.next_execution_timestamp).to be_like_time(Time.current)
end
end
end
......@@ -359,7 +359,7 @@ describe Project do
end
describe '.mirrors_to_sync' do
let(:timestamp) { Time.now }
let(:timestamp) { Time.current }
context 'when mirror is scheduled' do
it 'returns empty' do
......
......@@ -236,7 +236,7 @@ describe User do
end
describe '#forget_me!' do
subject { create(:user, remember_created_at: Time.now) }
subject { create(:user, remember_created_at: Time.current) }
it 'clears remember_created_at' do
subject.forget_me!
......
......@@ -84,7 +84,7 @@ describe Vulnerabilities::Export do
vulnerability_export.start!
end
it { is_expected.to have_attributes(status: 'running', started_at: Time.now) }
it { is_expected.to have_attributes(status: 'running', started_at: Time.current) }
end
context 'when the export is running' do
......@@ -95,7 +95,7 @@ describe Vulnerabilities::Export do
vulnerability_export.finish!
end
it { is_expected.to have_attributes(status: 'finished', finished_at: Time.now) }
it { is_expected.to have_attributes(status: 'finished', finished_at: Time.current) }
end
context 'and it fails' do
......@@ -105,7 +105,7 @@ describe Vulnerabilities::Export do
vulnerability_export.failed!
end
it { is_expected.to have_attributes(status: 'failed', finished_at: Time.now) }
it { is_expected.to have_attributes(status: 'failed', finished_at: Time.current) }
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