2020-10-24 23:57:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe GracefulTimeoutHandling, type: :controller do
|
|
|
|
controller(ApplicationController) do
|
|
|
|
include GracefulTimeoutHandling
|
|
|
|
|
|
|
|
skip_before_action :authenticate_user!
|
|
|
|
|
|
|
|
def index
|
2021-06-08 01:23:25 +05:30
|
|
|
raise ActiveRecord::QueryCanceled
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for json request' do
|
|
|
|
subject { get :index, format: :json }
|
|
|
|
|
|
|
|
it 'renders graceful error message' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(json_response['error']).to eq(_('There is too much data to calculate. Please change your selection.'))
|
|
|
|
expect(response.code).to eq '200'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs exception' do
|
|
|
|
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(kind_of(ActiveRecord::QueryCanceled))
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for html request' do
|
|
|
|
subject { get :index, format: :html }
|
|
|
|
|
|
|
|
it 'has no effect' do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to raise_error(ActiveRecord::QueryCanceled)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|