summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 09:09:17 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 09:09:17 +0000
commiteaea945e0355826c58c3dcf887496ea91064f85c (patch)
tree0f20e03304d35e68375e99a606b9b94483e37ee5 /spec/lib/gitlab
parentcce8cf03d3bebe8b05375e4db0004328f84b28a2 (diff)
downloadgitlab-ce-eaea945e0355826c58c3dcf887496ea91064f85c.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/closing_issue_extractor_spec.rb4
-rw-r--r--spec/lib/gitlab/database/batch_count_spec.rb46
2 files changed, 42 insertions, 8 deletions
diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb
index 510876a5945..4e1bf2840dc 100644
--- a/spec/lib/gitlab/closing_issue_extractor_spec.rb
+++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb
@@ -103,7 +103,7 @@ describe Gitlab::ClosingIssueExtractor do
end
it do
- message = "Awesome commit (Fixes: #{reference})"
+ message = "Awesome commit (fixes: #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
@@ -396,7 +396,7 @@ describe Gitlab::ClosingIssueExtractor do
end
it 'allows mixed comma-separated and non-comma-separated issue numbers in single line message' do
- message = "Closes #{reference}, #{reference2} and #{reference3}"
+ message = "Closes #{reference}, #{reference2} #{reference3}"
expect(subject.closed_by_message(message))
.to match_array([issue, other_issue, third_issue])
diff --git a/spec/lib/gitlab/database/batch_count_spec.rb b/spec/lib/gitlab/database/batch_count_spec.rb
index b126d8579fc..ec161cd6dcb 100644
--- a/spec/lib/gitlab/database/batch_count_spec.rb
+++ b/spec/lib/gitlab/database/batch_count_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
describe Gitlab::Database::BatchCount do
+ let_it_be(:fallback) { ::Gitlab::Database::BatchCounter::FALLBACK }
+ let_it_be(:small_batch_size) { ::Gitlab::Database::BatchCounter::MIN_REQUIRED_BATCH_SIZE - 1 }
let(:model) { Issue }
let(:column) { :author_id }
@@ -37,9 +39,8 @@ describe Gitlab::Database::BatchCount do
expect(described_class.batch_count(model, batch_size: 50_000)).to eq(5)
end
- it 'will not count table with batch_size 1K' do
- fallback = ::Gitlab::Database::BatchCounter::FALLBACK
- expect(described_class.batch_count(model, batch_size: fallback / 2)).to eq(fallback)
+ it 'will not count table with a batch size less than allowed' do
+ expect(described_class.batch_count(model, batch_size: small_batch_size)).to eq(fallback)
end
it 'counts with a small edge case batch_sizes than result' do
@@ -57,6 +58,25 @@ describe Gitlab::Database::BatchCount do
end.to raise_error 'BatchCount can not be run inside a transaction'
end
end
+
+ it 'counts with a start and finish' do
+ expect(described_class.batch_count(model, start: model.minimum(:id), finish: model.maximum(:id))).to eq(5)
+ end
+
+ context 'disallowed configurations' do
+ it 'returns fallback if start is bigger than finish' do
+ expect(described_class.batch_count(model, start: 1, finish: 0)).to eq(fallback)
+ end
+
+ it 'returns fallback if loops more than allowed' do
+ large_finish = Gitlab::Database::BatchCounter::MAX_ALLOWED_LOOPS * Gitlab::Database::BatchCounter::DEFAULT_BATCH_SIZE + 1
+ expect(described_class.batch_count(model, start: 1, finish: large_finish)).to eq(fallback)
+ end
+
+ it 'returns fallback if batch size is less than min required' do
+ expect(described_class.batch_count(model, batch_size: small_batch_size)).to eq(fallback)
+ end
+ end
end
describe '#batch_distinct_count' do
@@ -80,9 +100,8 @@ describe Gitlab::Database::BatchCount do
expect(described_class.batch_distinct_count(model, column, batch_size: 50_000)).to eq(2)
end
- it 'will not count table with batch_size 1K' do
- fallback = ::Gitlab::Database::BatchCounter::FALLBACK
- expect(described_class.batch_distinct_count(model, column, batch_size: fallback / 2)).to eq(fallback)
+ it 'will not count table with a batch size less than allowed' do
+ expect(described_class.batch_distinct_count(model, column, batch_size: small_batch_size)).to eq(fallback)
end
it 'counts with a small edge case batch_sizes than result' do
@@ -98,5 +117,20 @@ describe Gitlab::Database::BatchCount do
it 'counts with User min and max as start and finish' do
expect(described_class.batch_distinct_count(model, column, start: User.minimum(:id), finish: User.maximum(:id))).to eq(2)
end
+
+ context 'disallowed configurations' do
+ it 'returns fallback if start is bigger than finish' do
+ expect(described_class.batch_distinct_count(model, column, start: 1, finish: 0)).to eq(fallback)
+ end
+
+ it 'returns fallback if loops more than allowed' do
+ large_finish = Gitlab::Database::BatchCounter::MAX_ALLOWED_LOOPS * Gitlab::Database::BatchCounter::DEFAULT_DISTINCT_BATCH_SIZE + 1
+ expect(described_class.batch_distinct_count(model, column, start: 1, finish: large_finish)).to eq(fallback)
+ end
+
+ it 'returns fallback if batch size is less than min required' do
+ expect(described_class.batch_distinct_count(model, column, batch_size: small_batch_size)).to eq(fallback)
+ end
+ end
end
end