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:
Diffstat (limited to 'spec/requests/api/unleash_spec.rb')
-rw-r--r--spec/requests/api/unleash_spec.rb42
1 files changed, 41 insertions, 1 deletions
diff --git a/spec/requests/api/unleash_spec.rb b/spec/requests/api/unleash_spec.rb
index 6cb801538c6..7bdb89fb286 100644
--- a/spec/requests/api/unleash_spec.rb
+++ b/spec/requests/api/unleash_spec.rb
@@ -168,7 +168,7 @@ RSpec.describe API::Unleash do
end
%w(/feature_flags/unleash/:project_id/features /feature_flags/unleash/:project_id/client/features).each do |features_endpoint|
- describe "GET #{features_endpoint}" do
+ describe "GET #{features_endpoint}", :use_clean_rails_redis_caching do
let(:features_url) { features_endpoint.sub(':project_id', project_id.to_s) }
let(:client) { create(:operations_feature_flags_client, project: project) }
@@ -176,6 +176,46 @@ RSpec.describe API::Unleash do
it_behaves_like 'authenticated request'
+ context 'when a client fetches feature flags several times' do
+ let(:headers) { { 'UNLEASH-INSTANCEID' => client.token, 'UNLEASH-APPNAME' => 'production' } }
+
+ before do
+ create_list(:operations_feature_flag, 3, project: project)
+ end
+
+ it 'serializes feature flags for the first time and read cached data from the second time' do
+ expect(API::Entities::Unleash::ClientFeatureFlags)
+ .to receive(:represent).with(instance_of(Operations::FeatureFlagsClient), any_args)
+ .once
+
+ 5.times { get api(features_url), params: params, headers: headers }
+ end
+
+ it 'increments the cache key when feature flags are modified' do
+ expect(API::Entities::Unleash::ClientFeatureFlags)
+ .to receive(:represent).with(instance_of(Operations::FeatureFlagsClient), any_args)
+ .twice
+
+ 2.times { get api(features_url), params: params, headers: headers }
+
+ ::FeatureFlags::CreateService.new(project, project.owner, name: 'feature_flag').execute
+
+ 3.times { get api(features_url), params: params, headers: headers }
+ end
+
+ context 'when cache_unleash_client_api is disabled' do
+ before do
+ stub_feature_flags(cache_unleash_client_api: false)
+ end
+
+ it 'serializes feature flags every time' do
+ expect(::API::Entities::UnleashFeature).to receive(:represent).exactly(5).times
+
+ 5.times { get api(features_url), params: params, headers: headers }
+ end
+ end
+ end
+
context 'with version 2 feature flags' do
it 'does not return a flag without any strategies' do
create(:operations_feature_flag, project: project,