adding test for the human hot_threads call

Fixes #5766
This commit is contained in:
Pier-Hugues Pellerin 2016-08-16 11:58:08 -04:00
parent 6c88649afe
commit db5edacf9a
2 changed files with 53 additions and 7 deletions

View file

@ -14,7 +14,7 @@ module LogStash
options = {
:ignore_idle_threads => as_boolean(ignore_idle_threads),
:human => params.has_key?("human")
:human => human?
}
options[:threads] = params["threads"].to_i if params.has_key?("threads")
@ -26,6 +26,11 @@ module LogStash
selected_fields = extract_fields(params["filter"].to_s.strip)
respond_with node.all(selected_fields)
end
protected
def human?
params.has_key?("human") && (params["human"].nil? || as_boolean(params["human"]) == true)
end
end
end
end

View file

@ -39,25 +39,66 @@ describe LogStash::Api::Modules::Node do
end
context "when asking for human output" do
[
"/hot_threads?human",
"/hot_threads?human=true",
"/hot_threads?human=1",
"/hot_threads?human=t",
].each do |path|
before(:all) do
do_request { get path }
end
let(:payload) { last_response.body }
it "should return a text/plain content type" do
expect(last_response.content_type).to eq("text/plain;charset=utf-8")
end
it "should return a plain text payload" do
expect{ JSON.parse(payload) }.to raise_error
end
end
end
context "When asking for human output and threads count" do
before(:all) do
do_request { get "/hot_threads?human" }
do_request { get "/hot_threads?human=t&threads=2"}
end
let(:payload) { last_response.body }
it "should return a text/plain content type" do
expect(last_response.content_type).to eq("text/plain;charset=utf-8")
it "should return information for <= # requested threads" do
expect(payload.scan(/thread name/).size).to eq(2)
end
end
it "should return a plain text payload" do
expect{ JSON.parse(payload) }.to raise_error
context "when not asking for human output" do
[
"/hot_threads?human=false",
"/hot_threads?human=0",
"/hot_threads?human=f",
].each do |path|
before(:all) do
do_request { get path }
end
it "should return a json payload content type" do
expect(last_response.content_type).to eq("application/json")
end
let(:payload) { last_response.body }
it "should return a json payload" do
expect{ JSON.parse(payload) }.not_to raise_error
end
end
end
describe "Generic JSON testing" do
extend ResourceDSLMethods
root_structure = {
"pipeline" => {
"workers" => Numeric,