2019-07-16 16:10:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe ChaosController do
|
2019-07-16 16:10:44 -04:00
|
|
|
describe '#leakmem' do
|
|
|
|
it 'calls synchronously' do
|
|
|
|
expect(Gitlab::Chaos).to receive(:leak_mem).with(100, 30.seconds)
|
|
|
|
|
|
|
|
get :leakmem
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'call synchronously with params' do
|
|
|
|
expect(Gitlab::Chaos).to receive(:leak_mem).with(1, 2.seconds)
|
|
|
|
|
|
|
|
get :leakmem, params: { memory_mb: 1, duration_s: 2 }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls asynchronously' do
|
|
|
|
expect(Chaos::LeakMemWorker).to receive(:perform_async).with(100, 30.seconds)
|
|
|
|
|
|
|
|
get :leakmem, params: { async: 1 }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#cpu_spin' do
|
|
|
|
it 'calls synchronously' do
|
|
|
|
expect(Gitlab::Chaos).to receive(:cpu_spin).with(30.seconds)
|
|
|
|
|
|
|
|
get :cpu_spin
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls synchronously with params' do
|
|
|
|
expect(Gitlab::Chaos).to receive(:cpu_spin).with(3.seconds)
|
|
|
|
|
|
|
|
get :cpu_spin, params: { duration_s: 3 }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls asynchronously' do
|
|
|
|
expect(Chaos::CpuSpinWorker).to receive(:perform_async).with(30.seconds)
|
|
|
|
|
|
|
|
get :cpu_spin, params: { async: 1 }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#db_spin' do
|
|
|
|
it 'calls synchronously' do
|
|
|
|
expect(Gitlab::Chaos).to receive(:db_spin).with(30.seconds, 1.second)
|
|
|
|
|
|
|
|
get :db_spin
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls synchronously with params' do
|
|
|
|
expect(Gitlab::Chaos).to receive(:db_spin).with(4.seconds, 5.seconds)
|
|
|
|
|
|
|
|
get :db_spin, params: { duration_s: 4, interval_s: 5 }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls asynchronously' do
|
|
|
|
expect(Chaos::DbSpinWorker).to receive(:perform_async).with(30.seconds, 1.second)
|
|
|
|
|
|
|
|
get :db_spin, params: { async: 1 }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#sleep' do
|
|
|
|
it 'calls synchronously' do
|
|
|
|
expect(Gitlab::Chaos).to receive(:sleep).with(30.seconds)
|
|
|
|
|
|
|
|
get :sleep
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls synchronously with params' do
|
|
|
|
expect(Gitlab::Chaos).to receive(:sleep).with(5.seconds)
|
|
|
|
|
|
|
|
get :sleep, params: { duration_s: 5 }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls asynchronously' do
|
|
|
|
expect(Chaos::SleepWorker).to receive(:perform_async).with(30.seconds)
|
|
|
|
|
|
|
|
get :sleep, params: { async: 1 }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#kill' do
|
|
|
|
it 'calls synchronously' do
|
2021-04-09 02:09:30 -04:00
|
|
|
expect(Gitlab::Chaos).to receive(:kill).with('KILL')
|
2019-07-16 16:10:44 -04:00
|
|
|
|
|
|
|
get :kill
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls asynchronously' do
|
2021-04-09 02:09:30 -04:00
|
|
|
expect(Chaos::KillWorker).to receive(:perform_async).with('KILL')
|
2019-07-16 16:10:44 -04:00
|
|
|
|
|
|
|
get :kill, params: { async: 1 }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|
|
|
|
end
|
2021-01-21 10:08:36 -05:00
|
|
|
|
2021-04-09 02:09:30 -04:00
|
|
|
describe '#quit' do
|
|
|
|
it 'calls synchronously' do
|
|
|
|
expect(Gitlab::Chaos).to receive(:kill).with('QUIT')
|
|
|
|
|
|
|
|
get :quit
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls asynchronously' do
|
|
|
|
expect(Chaos::KillWorker).to receive(:perform_async).with('QUIT')
|
|
|
|
|
|
|
|
get :quit, params: { async: 1 }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-21 10:08:36 -05:00
|
|
|
describe '#gc' do
|
|
|
|
let(:gc_stat) { GC.stat.stringify_keys }
|
|
|
|
|
|
|
|
it 'runs a full GC on the current web worker' do
|
2022-06-10 05:11:12 -04:00
|
|
|
allow(Prometheus::PidProvider).to receive(:worker_id).and_return('worker-0')
|
|
|
|
allow(Gitlab::Chaos).to receive(:run_gc).and_return(gc_stat)
|
2021-01-21 10:08:36 -05:00
|
|
|
|
|
|
|
post :gc
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response_json['worker_id']).to eq('worker-0')
|
|
|
|
expect(response_json['gc_stat']).to eq(gc_stat)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def response_json
|
|
|
|
Gitlab::Json.parse(response.body)
|
|
|
|
end
|
2019-07-16 16:10:44 -04:00
|
|
|
end
|