diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2019-07-04 15:52:02 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-07-04 15:52:02 +0000 |
commit | d132f73d42aec530c78680f53bf8a612bac61a3b (patch) | |
tree | 6a00ae449c40dcdf3c2d9b50c0e9559340b4ff84 /spec/models/namespace | |
parent | f62aa64b74b988c5539496147674996f44aafdbf (diff) | |
download | gitlab-ce-d132f73d42aec530c78680f53bf8a612bac61a3b.tar.gz |
Implements lease_release on NamespaceAggregation
Sets lease_release? to false to prevent the job to be re-executed more
often than lease timeout
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/64079
Diffstat (limited to 'spec/models/namespace')
-rw-r--r-- | spec/models/namespace/aggregation_schedule_spec.rb | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/spec/models/namespace/aggregation_schedule_spec.rb b/spec/models/namespace/aggregation_schedule_spec.rb index 8ed0248e1b2..0f1283717e0 100644 --- a/spec/models/namespace/aggregation_schedule_spec.rb +++ b/spec/models/namespace/aggregation_schedule_spec.rb @@ -53,10 +53,39 @@ RSpec.describe Namespace::AggregationSchedule, :clean_gitlab_redis_shared_state, expect(Namespaces::RootStatisticsWorker) .to receive(:perform_in).once - .with(described_class::DEFAULT_LEASE_TIMEOUT, aggregation_schedule.namespace_id ) + .with(described_class::DEFAULT_LEASE_TIMEOUT, aggregation_schedule.namespace_id) aggregation_schedule.save! end + + it 'does not release the lease' do + stub_exclusive_lease(lease_key, timeout: described_class::DEFAULT_LEASE_TIMEOUT) + + aggregation_schedule.save! + + exclusive_lease = aggregation_schedule.exclusive_lease + expect(exclusive_lease.exists?).to be_truthy + end + + it 'only executes the workers once' do + # Avoid automatic deletion of Namespace::AggregationSchedule + # for testing purposes. + expect(Namespaces::RootStatisticsWorker) + .to receive(:perform_async).once + .and_return(nil) + + expect(Namespaces::RootStatisticsWorker) + .to receive(:perform_in).once + .with(described_class::DEFAULT_LEASE_TIMEOUT, aggregation_schedule.namespace_id) + .and_return(nil) + + # Scheduling workers for the first time + aggregation_schedule.schedule_root_storage_statistics + + # Executing again, this time workers should not be scheduled + # due to the lease not been released. + aggregation_schedule.schedule_root_storage_statistics + end end context 'with a personalized lease timeout' do |