Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-07-04 17:15:24 +0300
committerRémy Coutable <remy@rymai.me>2017-07-06 12:18:26 +0300
commit00ac76cc4ce87954d770abae411c54eb8bf23360 (patch)
treee9727ab4149ecd6ece8e3ebe692998e53821b3c8 /spec/lib/gitlab/performance_bar_spec.rb
parent75bd0c3a444cb58f1a7ed5f0c540dddbde6f09ed (diff)
Cache the allowed user IDs for the performance bar, in Redis for 10 minutes
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/lib/gitlab/performance_bar_spec.rb')
-rw-r--r--spec/lib/gitlab/performance_bar_spec.rb52
1 files changed, 28 insertions, 24 deletions
diff --git a/spec/lib/gitlab/performance_bar_spec.rb b/spec/lib/gitlab/performance_bar_spec.rb
index cab267cde30..ecdecc03304 100644
--- a/spec/lib/gitlab/performance_bar_spec.rb
+++ b/spec/lib/gitlab/performance_bar_spec.rb
@@ -25,6 +25,27 @@ describe Gitlab::PerformanceBar do
end
end
+ shared_examples 'allowed user IDs are cached in Redis for 10 minutes' do
+ before do
+ # Warm the Redis cache
+ described_class.allowed_user?(user)
+ end
+
+ it 'caches the allowed user IDs in Redis', :redis do
+ expect do
+ expect(described_class.allowed_user?(user)).to be_truthy
+ end.not_to exceed_query_limit(0)
+ end
+
+ it 'caches the allowed user IDs for 10 minutes', :redis do
+ ttl_cached_user_ids = Gitlab::Redis.with do |redis|
+ redis.ttl(described_class.cache_key)
+ end
+
+ expect(ttl_cached_user_ids).to be <= 10.minutes
+ end
+ end
+
describe '.allowed_user?' do
let(:user) { create(:user) }
@@ -45,6 +66,8 @@ describe Gitlab::PerformanceBar do
it 'returns false' do
expect(described_class.allowed_user?(user)).to be_falsy
end
+
+ it_behaves_like 'allowed user IDs are cached in Redis for 10 minutes'
end
context 'when user is a member of the allowed group' do
@@ -55,28 +78,8 @@ describe Gitlab::PerformanceBar do
it 'returns true' do
expect(described_class.allowed_user?(user)).to be_truthy
end
- end
- end
- end
- describe '.allowed_group' do
- before do
- stub_performance_bar_setting(allowed_group: 'my-group')
- end
-
- context 'when allowed group does not exist' do
- it 'returns false' do
- expect(described_class.allowed_group).to be_falsy
- end
- end
-
- context 'when allowed group exists' do
- let!(:my_group) { create(:group, path: 'my-group') }
-
- context 'when user is not a member of the allowed group' do
- it 'returns the group' do
- expect(described_class.allowed_group).to eq(my_group)
- end
+ it_behaves_like 'allowed user IDs are cached in Redis for 10 minutes'
end
end
@@ -85,21 +88,22 @@ describe Gitlab::PerformanceBar do
before do
create(:group, path: 'my-group')
+ nested_my_group.add_developer(user)
stub_performance_bar_setting(allowed_group: 'my-org/my-group')
end
it 'returns the nested group' do
- expect(described_class.allowed_group).to eq(nested_my_group)
+ expect(described_class.allowed_user?(user)).to be_truthy
end
end
context 'when a nested group has the same path', :nested_groups do
before do
- create(:group, :nested, path: 'my-group')
+ create(:group, :nested, path: 'my-group').add_developer(user)
end
it 'returns false' do
- expect(described_class.allowed_group).to be_falsy
+ expect(described_class.allowed_user?(user)).to be_falsy
end
end
end