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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 03:08:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 03:08:51 +0300
commit1ce6af4aad0107b6d604f89a3c0b530476a10165 (patch)
tree4956b0d395cd9232bca14f83daca3cd8616cc842 /spec/lib/gitlab/etag_caching
parent24256212ea84e6fb6509f6fb317a2d2bac3d0d06 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/etag_caching')
-rw-r--r--spec/lib/gitlab/etag_caching/middleware_spec.rb69
1 files changed, 60 insertions, 9 deletions
diff --git a/spec/lib/gitlab/etag_caching/middleware_spec.rb b/spec/lib/gitlab/etag_caching/middleware_spec.rb
index 24df67b3058..5e9df555241 100644
--- a/spec/lib/gitlab/etag_caching/middleware_spec.rb
+++ b/spec/lib/gitlab/etag_caching/middleware_spec.rb
@@ -8,6 +8,7 @@ describe Gitlab::EtagCaching::Middleware do
let(:app_status_code) { 200 }
let(:if_none_match) { nil }
let(:enabled_path) { '/gitlab-org/gitlab-foss/noteable/issue/1/notes' }
+ let(:endpoint) { 'issue_notes' }
context 'when ETag caching is not enabled for current route' do
let(:path) { '/gitlab-org/gitlab-foss/tree/master/noteable/issue/1/notes' }
@@ -50,9 +51,9 @@ describe Gitlab::EtagCaching::Middleware do
it 'tracks "etag_caching_key_not_found" event' do
expect(Gitlab::Metrics).to receive(:add_event)
- .with(:etag_caching_middleware_used, endpoint: 'issue_notes')
+ .with(:etag_caching_middleware_used, endpoint: endpoint)
expect(Gitlab::Metrics).to receive(:add_event)
- .with(:etag_caching_key_not_found, endpoint: 'issue_notes')
+ .with(:etag_caching_key_not_found, endpoint: endpoint)
middleware.call(build_request(path, if_none_match))
end
@@ -74,6 +75,37 @@ describe Gitlab::EtagCaching::Middleware do
end
end
+ shared_examples 'sends a process_action.action_controller notification' do |status_code|
+ let(:expected_items) do
+ {
+ etag_route: endpoint,
+ params: {},
+ format: :html,
+ method: 'GET',
+ path: enabled_path,
+ status: status_code
+ }
+ end
+
+ it 'sends the expected payload' do
+ payload = payload_for('process_action.action_controller') do
+ middleware.call(build_request(path, if_none_match))
+ end
+
+ expect(payload).to include(expected_items)
+
+ expect(payload[:headers].env['HTTP_IF_NONE_MATCH']).to eq('W/"123"')
+ end
+
+ it 'log subscriber processes action' do
+ expect_any_instance_of(ActionController::LogSubscriber).to receive(:process_action)
+ .with(instance_of(ActiveSupport::Notifications::Event))
+ .and_call_original
+
+ middleware.call(build_request(path, if_none_match))
+ end
+ end
+
context 'when If-None-Match header matches ETag in store' do
let(:path) { enabled_path }
let(:if_none_match) { 'W/"123"' }
@@ -94,6 +126,8 @@ describe Gitlab::EtagCaching::Middleware do
expect(status).to eq 304
end
+ it_behaves_like 'sends a process_action.action_controller notification', 304
+
it 'returns empty body' do
_, _, body = middleware.call(build_request(path, if_none_match))
@@ -102,9 +136,9 @@ describe Gitlab::EtagCaching::Middleware do
it 'tracks "etag_caching_cache_hit" event' do
expect(Gitlab::Metrics).to receive(:add_event)
- .with(:etag_caching_middleware_used, endpoint: 'issue_notes')
+ .with(:etag_caching_middleware_used, endpoint: endpoint)
expect(Gitlab::Metrics).to receive(:add_event)
- .with(:etag_caching_cache_hit, endpoint: 'issue_notes')
+ .with(:etag_caching_cache_hit, endpoint: endpoint)
middleware.call(build_request(path, if_none_match))
end
@@ -120,6 +154,8 @@ describe Gitlab::EtagCaching::Middleware do
expect(status).to eq 429
end
+
+ it_behaves_like 'sends a process_action.action_controller notification', 429
end
end
@@ -141,9 +177,9 @@ describe Gitlab::EtagCaching::Middleware do
mock_app_response
expect(Gitlab::Metrics).to receive(:add_event)
- .with(:etag_caching_middleware_used, endpoint: 'issue_notes')
+ .with(:etag_caching_middleware_used, endpoint: endpoint)
expect(Gitlab::Metrics).to receive(:add_event)
- .with(:etag_caching_resource_changed, endpoint: 'issue_notes')
+ .with(:etag_caching_resource_changed, endpoint: endpoint)
middleware.call(build_request(path, if_none_match))
end
@@ -159,9 +195,9 @@ describe Gitlab::EtagCaching::Middleware do
it 'tracks "etag_caching_header_missing" event' do
expect(Gitlab::Metrics).to receive(:add_event)
- .with(:etag_caching_middleware_used, endpoint: 'issue_notes')
+ .with(:etag_caching_middleware_used, endpoint: endpoint)
expect(Gitlab::Metrics).to receive(:add_event)
- .with(:etag_caching_header_missing, endpoint: 'issue_notes')
+ .with(:etag_caching_header_missing, endpoint: endpoint)
middleware.call(build_request(path, if_none_match))
end
@@ -197,6 +233,21 @@ describe Gitlab::EtagCaching::Middleware do
end
def build_request(path, if_none_match)
- { 'PATH_INFO' => path, 'HTTP_IF_NONE_MATCH' => if_none_match }
+ { 'PATH_INFO' => path,
+ 'HTTP_IF_NONE_MATCH' => if_none_match,
+ 'rack.input' => '',
+ 'REQUEST_METHOD' => 'GET' }
+ end
+
+ def payload_for(event)
+ payload = nil
+ subscription = ActiveSupport::Notifications.subscribe event do |_, _, _, _, extra_payload|
+ payload = extra_payload
+ end
+
+ yield
+
+ ActiveSupport::Notifications.unsubscribe(subscription)
+ payload
end
end