Commit 5138cb69 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

add a matcher to check status and content length of response

parent 70a38059
module CustomHttpMatchers
class BeHttpStatus
def initialize(expected)
@expected = expected
@should_has_content = nil
end
def matches?(target)
@target = target
ret = @target.response_header.status.eql?(@expected)
ret = @should_has_content ? has_content? : !has_content? unless (@should_has_content.nil? || !ret)
ret
end
alias == matches?
def without_body
@should_has_content = false
self
end
def with_body
@should_has_content = true
self
end
def failure_message_for_should
"expected that the #{@target.req.method} to #{@target.req.uri} to #{description}"
end
def failure_message_for_should_not
"expected that the #{@target.req.method} to #{@target.req.uri} not to #{description}"
end
def description
returned_values = " but returned with status #{@target.response_header.status} and content_length equals to #{@target.response_header.content_length}"
about_content = " and #{@should_has_content ? "with body" : "without body"}" unless @should_has_content.nil?
"be returned with status #{@expected}#{about_content}#{returned_values}"
end
private
def has_content?
@target.response_header.content_length > 0
end
end
def be_http_status(expected)
BeHttpStatus.new(expected)
end
end
...@@ -22,7 +22,7 @@ describe "Broadcast Properties" do ...@@ -22,7 +22,7 @@ describe "Broadcast Properties" do
pub.callback do pub.callback do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + channel_broad_fail).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + channel_broad_fail).get :head => headers
sub_1.callback do |chunk| sub_1.callback do |chunk|
sub_1.response_header.status.should eql(403) sub_1.should be_http_status(403).without_body
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + channel_broad).get :head => headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + channel_broad).get :head => headers
sub_2.stream do |chunk2| sub_2.stream do |chunk2|
...@@ -48,7 +48,7 @@ describe "Broadcast Properties" do ...@@ -48,7 +48,7 @@ describe "Broadcast Properties" do
pub.callback do pub.callback do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + channel_broad1 + '/' + channel_broad2 + '/' + channel_broad3).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + channel_broad1 + '/' + channel_broad2 + '/' + channel_broad3).get :head => headers
sub_1.callback do |chunk| sub_1.callback do |chunk|
sub_1.response_header.status.should eql(403) sub_1.should be_http_status(403).without_body
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + channel_broad1 + '/' + channel_broad2).get :head => headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + channel_broad1 + '/' + channel_broad2).get :head => headers
sub_2.stream do sub_2.stream do
EventMachine.stop EventMachine.stop
......
...@@ -12,8 +12,7 @@ describe "Channel Statistics" do ...@@ -12,8 +12,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(404) pub_1.should be_http_status(404).without_body
pub_1.response_header.content_length.should eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -31,8 +30,7 @@ describe "Channel Statistics" do ...@@ -31,8 +30,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["channel"].to_s.should eql(channel) response["channel"].to_s.should eql(channel)
response["published_messages"].to_i.should eql(1) response["published_messages"].to_i.should eql(1)
...@@ -52,8 +50,7 @@ describe "Channel Statistics" do ...@@ -52,8 +50,7 @@ describe "Channel Statistics" do
create_channel_by_subscribe(channel, headers) do create_channel_by_subscribe(channel, headers) do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
pub_1.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_1.response) response = JSON.parse(pub_1.response)
response["channel"].to_s.should eql(channel) response["channel"].to_s.should eql(channel)
response["published_messages"].to_i.should eql(0) response["published_messages"].to_i.should eql(0)
...@@ -70,8 +67,7 @@ describe "Channel Statistics" do ...@@ -70,8 +67,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["infos"].length.should eql(0) response["infos"].length.should eql(0)
EventMachine.stop EventMachine.stop
...@@ -91,8 +87,7 @@ describe "Channel Statistics" do ...@@ -91,8 +87,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["infos"].length.should eql(1) response["infos"].length.should eql(1)
response["infos"][0]["channel"].to_s.should eql(channel) response["infos"][0]["channel"].to_s.should eql(channel)
...@@ -116,8 +111,7 @@ describe "Channel Statistics" do ...@@ -116,8 +111,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["infos"].length.should eql(1) response["infos"].length.should eql(1)
response["channels"].to_i.should eql(0) response["channels"].to_i.should eql(0)
...@@ -140,8 +134,7 @@ describe "Channel Statistics" do ...@@ -140,8 +134,7 @@ describe "Channel Statistics" do
create_channel_by_subscribe(channel, headers) do create_channel_by_subscribe(channel, headers) do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
pub_1.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_1.response) response = JSON.parse(pub_1.response)
response["infos"].length.should eql(1) response["infos"].length.should eql(1)
response["infos"][0]["channel"].to_s.should eql(channel) response["infos"][0]["channel"].to_s.should eql(channel)
...@@ -159,8 +152,7 @@ describe "Channel Statistics" do ...@@ -159,8 +152,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
pub_1.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_1.response) response = JSON.parse(pub_1.response)
response.has_key?("channels").should be_true response.has_key?("channels").should be_true
response["channels"].to_i.should eql(0) response["channels"].to_i.should eql(0)
...@@ -181,8 +173,7 @@ describe "Channel Statistics" do ...@@ -181,8 +173,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response.has_key?("channels").should be_true response.has_key?("channels").should be_true
response["channels"].to_i.should eql(1) response["channels"].to_i.should eql(1)
...@@ -205,8 +196,7 @@ describe "Channel Statistics" do ...@@ -205,8 +196,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response.has_key?("channels").should be_true response.has_key?("channels").should be_true
response["channels"].to_i.should eql(0) response["channels"].to_i.should eql(0)
...@@ -227,8 +217,7 @@ describe "Channel Statistics" do ...@@ -227,8 +217,7 @@ describe "Channel Statistics" do
create_channel_by_subscribe(channel, headers) do create_channel_by_subscribe(channel, headers) do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
pub_1.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_1.response) response = JSON.parse(pub_1.response)
response.has_key?("channels").should be_true response.has_key?("channels").should be_true
response["channels"].to_i.should eql(1) response["channels"].to_i.should eql(1)
...@@ -254,19 +243,19 @@ describe "Channel Statistics" do ...@@ -254,19 +243,19 @@ describe "Channel Statistics" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(5) multi.responses[:callback].length.should eql(5)
multi.responses[:callback][:a].response_header.status.should_not eql(405) multi.responses[:callback][:a].should_not be_http_status(405)
multi.responses[:callback][:a].req.method.should eql("GET") multi.responses[:callback][:a].req.method.should eql("GET")
multi.responses[:callback][:b].response_header.status.should eql(405) multi.responses[:callback][:b].should be_http_status(405)
multi.responses[:callback][:b].req.method.should eql("PUT") multi.responses[:callback][:b].req.method.should eql("PUT")
multi.responses[:callback][:c].response_header.status.should eql(405) multi.responses[:callback][:c].should be_http_status(405)
multi.responses[:callback][:c].req.method.should eql("POST") multi.responses[:callback][:c].req.method.should eql("POST")
multi.responses[:callback][:d].response_header.status.should eql(405) multi.responses[:callback][:d].should be_http_status(405)
multi.responses[:callback][:d].req.method.should eql("DELETE") multi.responses[:callback][:d].req.method.should eql("DELETE")
multi.responses[:callback][:e].response_header.status.should eql(405) multi.responses[:callback][:e].should be_http_status(405)
multi.responses[:callback][:e].req.method.should eql("HEAD") multi.responses[:callback][:e].req.method.should eql("HEAD")
EventMachine.stop EventMachine.stop
...@@ -297,31 +286,31 @@ describe "Channel Statistics" do ...@@ -297,31 +286,31 @@ describe "Channel Statistics" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(7) multi.responses[:callback].length.should eql(7)
multi.responses[:callback][:a].response_header.status.should eql(200) multi.responses[:callback][:a].should be_http_status(200).with_body
multi.responses[:callback][:a].req.method.should eql("GET") multi.responses[:callback][:a].req.method.should eql("GET")
multi.responses[:callback][:a].response_header["CONTENT_TYPE"].should eql("application/json") multi.responses[:callback][:a].response_header["CONTENT_TYPE"].should eql("application/json")
multi.responses[:callback][:b].response_header.status.should eql(200) multi.responses[:callback][:b].should be_http_status(200).with_body
multi.responses[:callback][:b].req.method.should eql("GET") multi.responses[:callback][:b].req.method.should eql("GET")
multi.responses[:callback][:b].response_header["CONTENT_TYPE"].should eql("text/plain") multi.responses[:callback][:b].response_header["CONTENT_TYPE"].should eql("text/plain")
multi.responses[:callback][:c].response_header.status.should eql(200) multi.responses[:callback][:c].should be_http_status(200).with_body
multi.responses[:callback][:c].req.method.should eql("GET") multi.responses[:callback][:c].req.method.should eql("GET")
multi.responses[:callback][:c].response_header["CONTENT_TYPE"].should eql("application/json") multi.responses[:callback][:c].response_header["CONTENT_TYPE"].should eql("application/json")
multi.responses[:callback][:d].response_header.status.should eql(200) multi.responses[:callback][:d].should be_http_status(200).with_body
multi.responses[:callback][:d].req.method.should eql("GET") multi.responses[:callback][:d].req.method.should eql("GET")
multi.responses[:callback][:d].response_header["CONTENT_TYPE"].should eql("application/yaml") multi.responses[:callback][:d].response_header["CONTENT_TYPE"].should eql("application/yaml")
multi.responses[:callback][:e].response_header.status.should eql(200) multi.responses[:callback][:e].should be_http_status(200).with_body
multi.responses[:callback][:e].req.method.should eql("GET") multi.responses[:callback][:e].req.method.should eql("GET")
multi.responses[:callback][:e].response_header["CONTENT_TYPE"].should eql("application/xml") multi.responses[:callback][:e].response_header["CONTENT_TYPE"].should eql("application/xml")
multi.responses[:callback][:f].response_header.status.should eql(200) multi.responses[:callback][:f].should be_http_status(200).with_body
multi.responses[:callback][:f].req.method.should eql("GET") multi.responses[:callback][:f].req.method.should eql("GET")
multi.responses[:callback][:f].response_header["CONTENT_TYPE"].should eql("text/x-json") multi.responses[:callback][:f].response_header["CONTENT_TYPE"].should eql("text/x-json")
multi.responses[:callback][:g].response_header.status.should eql(200) multi.responses[:callback][:g].should be_http_status(200).with_body
multi.responses[:callback][:g].req.method.should eql("GET") multi.responses[:callback][:g].req.method.should eql("GET")
multi.responses[:callback][:g].response_header["CONTENT_TYPE"].should eql("text/x-yaml") multi.responses[:callback][:g].response_header["CONTENT_TYPE"].should eql("text/x-yaml")
...@@ -350,8 +339,7 @@ describe "Channel Statistics" do ...@@ -350,8 +339,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["infos"].length.should eql(number_of_channels) response["infos"].length.should eql(number_of_channels)
EventMachine.stop EventMachine.stop
...@@ -365,8 +353,7 @@ describe "Channel Statistics" do ...@@ -365,8 +353,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=prefix_*').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=prefix_*').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["infos"].length.should eql(0) response["infos"].length.should eql(0)
EventMachine.stop EventMachine.stop
...@@ -388,8 +375,7 @@ describe "Channel Statistics" do ...@@ -388,8 +375,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ch_test_*').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ch_test_*').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["infos"].length.should eql(1) response["infos"].length.should eql(1)
response["infos"][0]["channel"].to_s.should eql(channel) response["infos"][0]["channel"].to_s.should eql(channel)
...@@ -415,8 +401,7 @@ describe "Channel Statistics" do ...@@ -415,8 +401,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=*').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=*').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["infos"].length.should eql(2) response["infos"].length.should eql(2)
response["infos"][0]["channel"].to_s.should eql(channel) response["infos"][0]["channel"].to_s.should eql(channel)
...@@ -444,8 +429,7 @@ describe "Channel Statistics" do ...@@ -444,8 +429,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=bd_test_*').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=bd_test_*').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["infos"].length.should eql(1) response["infos"].length.should eql(1)
response["channels"].to_i.should eql(0) response["channels"].to_i.should eql(0)
...@@ -468,8 +452,7 @@ describe "Channel Statistics" do ...@@ -468,8 +452,7 @@ describe "Channel Statistics" do
create_channel_by_subscribe(channel, headers) do create_channel_by_subscribe(channel, headers) do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ch_test_*').get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ch_test_*').get :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
pub_1.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_1.response) response = JSON.parse(pub_1.response)
response["infos"].length.should eql(1) response["infos"].length.should eql(1)
response["infos"][0]["channel"].to_s.should eql(channel) response["infos"][0]["channel"].to_s.should eql(channel)
...@@ -501,8 +484,7 @@ describe "Channel Statistics" do ...@@ -501,8 +484,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ch_test_get_detailed_channels_statistics_to_many_channels_using_prefix_10*').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ch_test_get_detailed_channels_statistics_to_many_channels_using_prefix_10*').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["infos"].length.should eql(1111) response["infos"].length.should eql(1111)
EventMachine.stop EventMachine.stop
...@@ -522,8 +504,7 @@ describe "Channel Statistics" do ...@@ -522,8 +504,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["hostname"].to_s.should_not be_empty response["hostname"].to_s.should_not be_empty
response["time"].to_s.should_not be_empty response["time"].to_s.should_not be_empty
...@@ -535,8 +516,7 @@ describe "Channel Statistics" do ...@@ -535,8 +516,7 @@ describe "Channel Statistics" do
sleep(2) sleep(2)
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers
pub_3.callback do pub_3.callback do
pub_3.response_header.status.should eql(200) pub_3.should be_http_status(200).with_body
pub_3.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_3.response) response = JSON.parse(pub_3.response)
response["uptime"].to_i.should be_in_the_interval(2, 3) response["uptime"].to_i.should be_in_the_interval(2, 3)
EventMachine.stop EventMachine.stop
...@@ -557,8 +537,7 @@ describe "Channel Statistics" do ...@@ -557,8 +537,7 @@ describe "Channel Statistics" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["hostname"].to_s.should_not be_empty response["hostname"].to_s.should_not be_empty
response["time"].to_s.should_not be_empty response["time"].to_s.should_not be_empty
...@@ -574,8 +553,7 @@ describe "Channel Statistics" do ...@@ -574,8 +553,7 @@ describe "Channel Statistics" do
sleep(2) sleep(2)
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_3.callback do pub_3.callback do
pub_3.response_header.status.should eql(200) pub_3.should be_http_status(200).with_body
pub_3.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_3.response) response = JSON.parse(pub_3.response)
response["uptime"].to_i.should be_in_the_interval(2, 3) response["uptime"].to_i.should be_in_the_interval(2, 3)
response["by_worker"][0]["uptime"].to_i.should be_in_the_interval(2, 3) response["by_worker"][0]["uptime"].to_i.should be_in_the_interval(2, 3)
......
...@@ -35,7 +35,7 @@ describe "Cleanup Memory" do ...@@ -35,7 +35,7 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
result = JSON.parse(pub_2.response) result = JSON.parse(pub_2.response)
stored_messages_setp_1 = result["stored_messages"].to_i stored_messages_setp_1 = result["stored_messages"].to_i
published_messages_setp_1 = result["published_messages"].to_i published_messages_setp_1 = result["published_messages"].to_i
...@@ -46,7 +46,7 @@ describe "Cleanup Memory" do ...@@ -46,7 +46,7 @@ describe "Cleanup Memory" do
EM.add_timer(45) do EM.add_timer(45) do
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_3.callback do pub_3.callback do
fail("Don't received the stats") if (pub_3.response_header.status != 200) || (pub_3.response_header.content_length == 0) pub_3.should be_http_status(200).with_body
JSON.parse(pub_3.response)["stored_messages"].to_i.should eql(0) JSON.parse(pub_3.response)["stored_messages"].to_i.should eql(0)
execute_changes_on_environment(conf) do execute_changes_on_environment(conf) do
...@@ -60,14 +60,14 @@ describe "Cleanup Memory" do ...@@ -60,14 +60,14 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
published_messages_setp_2 = JSON.parse(pub_2.response)["published_messages"].to_i published_messages_setp_2 = JSON.parse(pub_2.response)["published_messages"].to_i
fail("Don't publish more messages") if published_messages_setp_1 == published_messages_setp_2 fail("Don't publish more messages") if published_messages_setp_1 == published_messages_setp_2
EM.add_timer(50) do EM.add_timer(50) do
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_3.callback do pub_3.callback do
fail("Don't received the stats") if (pub_3.response_header.status != 200) || (pub_3.response_header.content_length == 0) pub_3.should be_http_status(200).with_body
JSON.parse(pub_3.response)["stored_messages"].to_i.should eql(0) JSON.parse(pub_3.response)["stored_messages"].to_i.should eql(0)
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
...@@ -76,7 +76,7 @@ describe "Cleanup Memory" do ...@@ -76,7 +76,7 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_4.callback do pub_4.callback do
fail("Don't received the stats") if (pub_4.response_header.status != 200) || (pub_4.response_header.content_length == 0) pub_4.should be_http_status(200).with_body
result = JSON.parse(pub_4.response) result = JSON.parse(pub_4.response)
result["stored_messages"].to_i.should eql(stored_messages_setp_1) result["stored_messages"].to_i.should eql(stored_messages_setp_1)
(result["published_messages"].to_i - published_messages_setp_2).should eql(published_messages_setp_1) (result["published_messages"].to_i - published_messages_setp_2).should eql(published_messages_setp_1)
...@@ -119,7 +119,7 @@ describe "Cleanup Memory" do ...@@ -119,7 +119,7 @@ describe "Cleanup Memory" do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_1.callback do pub_1.callback do
fill_memory_timer.cancel fill_memory_timer.cancel
fail("Don't received the stats") if (pub_1.response_header.status != 200) || (pub_1.response_header.content_length == 0) pub_1.should be_http_status(200).with_body
stored_messages_setp_1 = JSON.parse(pub_1.response)["stored_messages"].to_i stored_messages_setp_1 = JSON.parse(pub_1.response)["stored_messages"].to_i
stored_messages_setp_1.should eql(messages_to_publish) stored_messages_setp_1.should eql(messages_to_publish)
...@@ -127,7 +127,7 @@ describe "Cleanup Memory" do ...@@ -127,7 +127,7 @@ describe "Cleanup Memory" do
EM.add_timer(5) do # wait cleanup timer to be executed one time EM.add_timer(5) do # wait cleanup timer to be executed one time
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
stored_messages_setp_2 = JSON.parse(pub_2.response)["stored_messages"].to_i stored_messages_setp_2 = JSON.parse(pub_2.response)["stored_messages"].to_i
stored_messages_setp_2.should be <= stored_messages_setp_1 stored_messages_setp_2.should be <= stored_messages_setp_1
stored_messages_setp_2.should be > 0 stored_messages_setp_2.should be > 0
...@@ -163,7 +163,7 @@ describe "Cleanup Memory" do ...@@ -163,7 +163,7 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
result = JSON.parse(pub_2.response) result = JSON.parse(pub_2.response)
stored_messages_setp_1 = result["stored_messages"].to_i stored_messages_setp_1 = result["stored_messages"].to_i
published_messages_setp_1 = result["published_messages"].to_i published_messages_setp_1 = result["published_messages"].to_i
...@@ -181,14 +181,14 @@ describe "Cleanup Memory" do ...@@ -181,14 +181,14 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
published_messages_setp_2 = JSON.parse(pub_2.response)["published_messages"].to_i published_messages_setp_2 = JSON.parse(pub_2.response)["published_messages"].to_i
fail("Don't publish more messages") if published_messages_setp_1 == published_messages_setp_2 fail("Don't publish more messages") if published_messages_setp_1 == published_messages_setp_2
EM.add_timer(60) do EM.add_timer(60) do
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_3.callback do pub_3.callback do
fail("Don't received the stats") if (pub_3.response_header.status != 200) || (pub_3.response_header.content_length == 0) pub_3.should be_http_status(200).with_body
JSON.parse(pub_3.response)["stored_messages"].to_i.should eql(0) JSON.parse(pub_3.response)["stored_messages"].to_i.should eql(0)
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
...@@ -196,7 +196,7 @@ describe "Cleanup Memory" do ...@@ -196,7 +196,7 @@ describe "Cleanup Memory" do
:error => Proc.new do |status3, content3| :error => Proc.new do |status3, content3|
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_4.callback do pub_4.callback do
fail("Don't received the stats") if (pub_4.response_header.status != 200) || (pub_4.response_header.content_length == 0) pub_4.should be_http_status(200).with_body
result = JSON.parse(pub_4.response) result = JSON.parse(pub_4.response)
result["stored_messages"].to_i.should eql(stored_messages_setp_1) result["stored_messages"].to_i.should eql(stored_messages_setp_1)
(result["published_messages"].to_i - published_messages_setp_2).should eql(published_messages_setp_1) (result["published_messages"].to_i - published_messages_setp_2).should eql(published_messages_setp_1)
...@@ -238,7 +238,7 @@ describe "Cleanup Memory" do ...@@ -238,7 +238,7 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
channels_setp_1 = JSON.parse(pub_2.response)["channels"].to_i channels_setp_1 = JSON.parse(pub_2.response)["channels"].to_i
fail("Don't create any channel") if channels_setp_1 == 0 fail("Don't create any channel") if channels_setp_1 == 0
...@@ -251,13 +251,13 @@ describe "Cleanup Memory" do ...@@ -251,13 +251,13 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
fail("Don't create more channel") if published_messages_setp_1 == JSON.parse(pub_2.response)["published_messages"].to_i fail("Don't create more channel") if published_messages_setp_1 == JSON.parse(pub_2.response)["published_messages"].to_i
EM.add_timer(40) do EM.add_timer(40) do
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_3.callback do pub_3.callback do
fail("Don't received the stats") if (pub_3.response_header.status != 200) || (pub_3.response_header.content_length == 0) pub_3.should be_http_status(200).with_body
channels = JSON.parse(pub_3.response)["channels"].to_i channels = JSON.parse(pub_3.response)["channels"].to_i
channels.should eql(0) channels.should eql(0)
...@@ -270,7 +270,7 @@ describe "Cleanup Memory" do ...@@ -270,7 +270,7 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_4.callback do pub_4.callback do
fail("Don't received the stats") if (pub_4.response_header.status != 200) || (pub_4.response_header.content_length == 0) pub_4.should be_http_status(200).with_body
channels_setp_2 = JSON.parse(pub_4.response)["channels"].to_i channels_setp_2 = JSON.parse(pub_4.response)["channels"].to_i
channels_setp_2.should eql(channels_setp_1) channels_setp_2.should eql(channels_setp_1)
...@@ -317,7 +317,7 @@ describe "Cleanup Memory" do ...@@ -317,7 +317,7 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
result = JSON.parse(pub_2.response) result = JSON.parse(pub_2.response)
published_messages_setp_1 = result["published_messages"].to_i published_messages_setp_1 = result["published_messages"].to_i
...@@ -332,14 +332,14 @@ describe "Cleanup Memory" do ...@@ -332,14 +332,14 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
published_messages_setp_2 = JSON.parse(pub_2.response)["published_messages"].to_i published_messages_setp_2 = JSON.parse(pub_2.response)["published_messages"].to_i
published_messages_setp_2.should_not eql(published_messages_setp_1) published_messages_setp_2.should_not eql(published_messages_setp_1)
EM.add_timer(35) do EM.add_timer(35) do
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_3.callback do pub_3.callback do
fail("Don't received the stats") if (pub_3.response_header.status != 200) || (pub_3.response_header.content_length == 0) pub_3.should be_http_status(200).with_body
JSON.parse(pub_3.response)["channels"].to_i.should eql(0) JSON.parse(pub_3.response)["channels"].to_i.should eql(0)
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
...@@ -347,7 +347,7 @@ describe "Cleanup Memory" do ...@@ -347,7 +347,7 @@ describe "Cleanup Memory" do
:error => Proc.new do |status3, content3| :error => Proc.new do |status3, content3|
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_4.callback do pub_4.callback do
fail("Don't received the stats") if (pub_4.response_header.status != 200) || (pub_4.response_header.content_length == 0) pub_4.should be_http_status(200).with_body
result = JSON.parse(pub_4.response) result = JSON.parse(pub_4.response)
(result["published_messages"].to_i - published_messages_setp_2).should eql(published_messages_setp_1) (result["published_messages"].to_i - published_messages_setp_2).should eql(published_messages_setp_1)
EventMachine.stop EventMachine.stop
...@@ -387,7 +387,7 @@ describe "Cleanup Memory" do ...@@ -387,7 +387,7 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
result = JSON.parse(pub_2.response) result = JSON.parse(pub_2.response)
published_messages_setp_1 = result["published_messages"].to_i published_messages_setp_1 = result["published_messages"].to_i
...@@ -400,14 +400,14 @@ describe "Cleanup Memory" do ...@@ -400,14 +400,14 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
published_messages_setp_2 = JSON.parse(pub_2.response)["published_messages"].to_i published_messages_setp_2 = JSON.parse(pub_2.response)["published_messages"].to_i
fail("Don't create more channel") if published_messages_setp_1 == published_messages_setp_2 fail("Don't create more channel") if published_messages_setp_1 == published_messages_setp_2
EM.add_timer(35) do EM.add_timer(35) do
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_3.callback do pub_3.callback do
fail("Don't received the stats") if (pub_3.response_header.status != 200) || (pub_3.response_header.content_length == 0) pub_3.should be_http_status(200).with_body
JSON.parse(pub_3.response)["channels"].to_i.should eql(0) JSON.parse(pub_3.response)["channels"].to_i.should eql(0)
EM.add_timer(35) do EM.add_timer(35) do
...@@ -416,7 +416,7 @@ describe "Cleanup Memory" do ...@@ -416,7 +416,7 @@ describe "Cleanup Memory" do
:error => Proc.new do |status3, content3| :error => Proc.new do |status3, content3|
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_4.callback do pub_4.callback do
fail("Don't received the stats") if (pub_4.response_header.status != 200) || (pub_4.response_header.content_length == 0) pub_4.should be_http_status(200).with_body
result = JSON.parse(pub_4.response) result = JSON.parse(pub_4.response)
(result["published_messages"].to_i - published_messages_setp_2).should eql(published_messages_setp_1) (result["published_messages"].to_i - published_messages_setp_2).should eql(published_messages_setp_1)
EventMachine.stop EventMachine.stop
...@@ -463,7 +463,7 @@ describe "Cleanup Memory" do ...@@ -463,7 +463,7 @@ describe "Cleanup Memory" do
end end
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
result = JSON.parse(pub_2.response) result = JSON.parse(pub_2.response)
published_messages_setp_1 = result["published_messages"].to_i published_messages_setp_1 = result["published_messages"].to_i
fail("Don't create any message") if published_messages_setp_1 == 0 fail("Don't create any message") if published_messages_setp_1 == 0
...@@ -478,7 +478,7 @@ describe "Cleanup Memory" do ...@@ -478,7 +478,7 @@ describe "Cleanup Memory" do
fill_memory_timer.cancel fill_memory_timer.cancel
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
result = JSON.parse(pub_2.response) result = JSON.parse(pub_2.response)
(result["published_messages"].to_i / 2).should eql(published_messages_setp_1) (result["published_messages"].to_i / 2).should eql(published_messages_setp_1)
EventMachine.stop EventMachine.stop
...@@ -509,7 +509,7 @@ describe "Cleanup Memory" do ...@@ -509,7 +509,7 @@ describe "Cleanup Memory" do
create_and_delete_channel_in_loop(channel, body, headers) do create_and_delete_channel_in_loop(channel, body, headers) do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
result = JSON.parse(pub_2.response) result = JSON.parse(pub_2.response)
published_messages_setp_1 = result["published_messages"].to_i published_messages_setp_1 = result["published_messages"].to_i
fail("Don't create any message") if published_messages_setp_1 == 0 fail("Don't create any message") if published_messages_setp_1 == 0
...@@ -519,7 +519,7 @@ describe "Cleanup Memory" do ...@@ -519,7 +519,7 @@ describe "Cleanup Memory" do
create_and_delete_channel_in_loop(channel, body, headers) do create_and_delete_channel_in_loop(channel, body, headers) do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
fail("Don't received the stats") if (pub_2.response_header.status != 200) || (pub_2.response_header.content_length == 0) pub_2.should be_http_status(200).with_body
result = JSON.parse(pub_2.response) result = JSON.parse(pub_2.response)
(result["published_messages"].to_i / 2).should eql(published_messages_setp_1) (result["published_messages"].to_i / 2).should eql(published_messages_setp_1)
EventMachine.stop EventMachine.stop
...@@ -591,7 +591,7 @@ describe "Cleanup Memory" do ...@@ -591,7 +591,7 @@ describe "Cleanup Memory" do
def execute_changes_on_environment(conf, &block) def execute_changes_on_environment(conf, &block)
pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :timeout => 30 pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :timeout => 30
pub.callback do pub.callback do
fail("Don't received the stats") if (pub.response_header.status != 200) || (pub.response_header.content_length == 0) pub.should be_http_status(200).with_body
resp_1 = JSON.parse(pub.response) resp_1 = JSON.parse(pub.response)
resp_1["by_worker"].count.should eql(1) resp_1["by_worker"].count.should eql(1)
pid = resp_1["by_worker"][0]['pid'].to_i pid = resp_1["by_worker"][0]['pid'].to_i
...@@ -615,7 +615,7 @@ describe "Cleanup Memory" do ...@@ -615,7 +615,7 @@ describe "Cleanup Memory" do
def execute_changes_on_environment(conf, &block) def execute_changes_on_environment(conf, &block)
pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :timeout => 30 pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :timeout => 30
pub.callback do pub.callback do
fail("Don't received the stats") if (pub.response_header.status != 200) || (pub.response_header.content_length == 0) pub.should be_http_status(200).with_body
resp_1 = JSON.parse(pub.response) resp_1 = JSON.parse(pub.response)
resp_1["by_worker"].count.should eql(1) resp_1["by_worker"].count.should eql(1)
pid = resp_1["by_worker"][0]['pid'].to_i pid = resp_1["by_worker"][0]['pid'].to_i
......
...@@ -40,8 +40,7 @@ describe "Measure Memory" do ...@@ -40,8 +40,7 @@ describe "Measure Memory" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
resp = JSON.parse(pub_2.response) resp = JSON.parse(pub_2.response)
expected_message = shared_size / (message_estimate_size + body.size) expected_message = shared_size / (message_estimate_size + body.size)
...@@ -73,8 +72,7 @@ describe "Measure Memory" do ...@@ -73,8 +72,7 @@ describe "Measure Memory" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
resp = JSON.parse(pub_2.response) resp = JSON.parse(pub_2.response)
expected_channel = (shared_size - ((body.size + message_estimate_size) * resp["published_messages"].to_i)) / (channel_estimate_size + 4) # 4 channel id size expected_channel = (shared_size - ((body.size + message_estimate_size) * resp["published_messages"].to_i)) / (channel_estimate_size + 4) # 4 channel id size
...@@ -93,8 +91,7 @@ describe "Measure Memory" do ...@@ -93,8 +91,7 @@ describe "Measure Memory" do
subscriber_in_loop(1000, headers) do subscriber_in_loop(1000, headers) do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
resp = JSON.parse(pub_2.response) resp = JSON.parse(pub_2.response)
expected_subscriber = (shared_size - ((channel_estimate_size + 4) * resp["channels"].to_i)) / subscriber_estimate_size # 4 channel id size expected_subscriber = (shared_size - ((channel_estimate_size + 4) * resp["channels"].to_i)) / subscriber_estimate_size # 4 channel id size
......
...@@ -41,8 +41,7 @@ describe "Send Signals" do ...@@ -41,8 +41,7 @@ describe "Send Signals" do
# check statistics # check statistics
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
pub_1.response_header.content_length.should_not eql(0)
resp_1 = JSON.parse(pub_1.response) resp_1 = JSON.parse(pub_1.response)
resp_1.has_key?("channels").should be_true resp_1.has_key?("channels").should be_true
resp_1["channels"].to_i.should eql(1) resp_1["channels"].to_i.should eql(1)
...@@ -127,8 +126,7 @@ describe "Send Signals" do ...@@ -127,8 +126,7 @@ describe "Send Signals" do
# check statistics # check statistics
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
pub_1.response_header.content_length.should_not eql(0)
resp_1 = JSON.parse(pub_1.response) resp_1 = JSON.parse(pub_1.response)
resp_1.has_key?("channels").should be_true resp_1.has_key?("channels").should be_true
resp_1["channels"].to_i.should eql(1) resp_1["channels"].to_i.should eql(1)
...@@ -144,8 +142,7 @@ describe "Send Signals" do ...@@ -144,8 +142,7 @@ describe "Send Signals" do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
resp_2 = JSON.parse(pub_2.response) resp_2 = JSON.parse(pub_2.response)
resp_2.has_key?("channels").should be_true resp_2.has_key?("channels").should be_true
resp_2["channels"].to_i.should eql(1) resp_2["channels"].to_i.should eql(1)
......
...@@ -10,7 +10,7 @@ describe "Publisher Channel id collision" do ...@@ -10,7 +10,7 @@ describe "Publisher Channel id collision" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel).post :body => 'x' pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel).post :body => 'x'
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -20,7 +20,7 @@ describe "Publisher Channel id collision" do ...@@ -20,7 +20,7 @@ describe "Publisher Channel id collision" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel).get :timeout => 30 pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel).get :timeout => 30
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200)
EventMachine.stop EventMachine.stop
end end
end end
......
...@@ -8,8 +8,7 @@ describe "Publisher Properties" do ...@@ -8,8 +8,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=').get :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=').get :head => headers
pub.callback do pub.callback do
pub.response_header.content_length.should eql(0) pub.should be_http_status(400).without_body
pub.response_header.status.should eql(400)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("No channel id provided.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("No channel id provided.")
EventMachine.stop EventMachine.stop
end end
...@@ -26,8 +25,7 @@ describe "Publisher Properties" do ...@@ -26,8 +25,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_1.to_s).get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_1.to_s).get :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(404) pub_1.should be_http_status(404).without_body
pub_1.response_header.content_length.should eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -35,8 +33,7 @@ describe "Publisher Properties" do ...@@ -35,8 +33,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_2.to_s ).post :head => headers, :body => body pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_2.to_s ).post :head => headers, :body => body
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["channel"].to_s.should eql(channel_2) response["channel"].to_s.should eql(channel_2)
EventMachine.stop EventMachine.stop
...@@ -54,8 +51,7 @@ describe "Publisher Properties" do ...@@ -54,8 +51,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
pub_1.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_1.response) response = JSON.parse(pub_1.response)
response["channel"].to_s.should eql(channel) response["channel"].to_s.should eql(channel)
EventMachine.stop EventMachine.stop
...@@ -65,8 +61,7 @@ describe "Publisher Properties" do ...@@ -65,8 +61,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).get :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).get :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).with_body
pub_2.response_header.content_length.should_not eql(0)
response = JSON.parse(pub_2.response) response = JSON.parse(pub_2.response)
response["channel"].to_s.should eql(channel) response["channel"].to_s.should eql(channel)
EventMachine.stop EventMachine.stop
...@@ -89,25 +84,25 @@ describe "Publisher Properties" do ...@@ -89,25 +84,25 @@ describe "Publisher Properties" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(5) multi.responses[:callback].length.should eql(5)
multi.responses[:callback][:a].response_header.status.should_not eql(405) multi.responses[:callback][:a].should_not be_http_status(405)
multi.responses[:callback][:a].req.method.should eql("GET") multi.responses[:callback][:a].req.method.should eql("GET")
multi.responses[:callback][:b].response_header.status.should eql(405) multi.responses[:callback][:b].should be_http_status(405)
multi.responses[:callback][:b].response_header['ALLOW'].should eql(accepted_methods) multi.responses[:callback][:b].response_header['ALLOW'].should eql(accepted_methods)
multi.responses[:callback][:b].req.method.should eql("PUT") multi.responses[:callback][:b].req.method.should eql("PUT")
multi.responses[:callback][:c].response_header.status.should_not eql(405) multi.responses[:callback][:c].should_not be_http_status(405)
multi.responses[:callback][:c].req.method.should eql("POST") multi.responses[:callback][:c].req.method.should eql("POST")
multi.responses[:callback][:d].req.method.should eql("DELETE") multi.responses[:callback][:d].req.method.should eql("DELETE")
if conf.publisher_mode == 'admin' if conf.publisher_mode == 'admin'
multi.responses[:callback][:d].response_header.status.should_not eql(405) multi.responses[:callback][:d].should_not be_http_status(405)
else else
multi.responses[:callback][:d].response_header.status.should eql(405) multi.responses[:callback][:d].should be_http_status(405)
multi.responses[:callback][:d].response_header['ALLOW'].should eql(accepted_methods) multi.responses[:callback][:d].response_header['ALLOW'].should eql(accepted_methods)
end end
multi.responses[:callback][:e].response_header.status.should eql(405) multi.responses[:callback][:e].should be_http_status(405)
multi.responses[:callback][:e].req.method.should eql("HEAD") multi.responses[:callback][:e].req.method.should eql("HEAD")
multi.responses[:callback][:e].response_header['ALLOW'].should eql(accepted_methods) multi.responses[:callback][:e].response_header['ALLOW'].should eql(accepted_methods)
...@@ -125,8 +120,7 @@ describe "Publisher Properties" do ...@@ -125,8 +120,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(403) pub_1.should be_http_status(403).without_body
pub_1.response_header.content_length.should eql(0)
pub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id not authorized for this method.") pub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id not authorized for this method.")
EventMachine.stop EventMachine.stop
end end
...@@ -150,8 +144,7 @@ describe "Publisher Properties" do ...@@ -150,8 +144,7 @@ describe "Publisher Properties" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(3) multi.responses[:callback].length.should eql(3)
multi.responses[:callback].each do |name, response| multi.responses[:callback].each do |name, response|
response.response_header.status.should eql(403) response.should be_http_status(403).without_body
response.response_header.content_length.should eql(0)
response.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id not authorized for this method.") response.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id not authorized for this method.")
end end
...@@ -173,7 +166,7 @@ describe "Publisher Properties" do ...@@ -173,7 +166,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(413) pub_1.should be_http_status(413)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -192,7 +185,7 @@ describe "Publisher Properties" do ...@@ -192,7 +185,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
fail("Let a file on client body temp dir") unless Dir.entries(conf.client_body_temp).select {|f| f if File.file?(File.expand_path(f, conf.client_body_temp)) }.empty? fail("Let a file on client body temp dir") unless Dir.entries(conf.client_body_temp).select {|f| f if File.file?(File.expand_path(f, conf.client_body_temp)) }.empty?
EventMachine.stop EventMachine.stop
end end
...@@ -212,7 +205,7 @@ describe "Publisher Properties" do ...@@ -212,7 +205,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).with_body
fail("Let a file on client body temp dir") unless Dir.entries(conf.client_body_temp).select {|f| f if File.file?(File.expand_path(f, conf.client_body_temp)) }.empty? fail("Let a file on client body temp dir") unless Dir.entries(conf.client_body_temp).select {|f| f if File.file?(File.expand_path(f, conf.client_body_temp)) }.empty?
EventMachine.stop EventMachine.stop
end end
...@@ -292,8 +285,7 @@ describe "Publisher Properties" do ...@@ -292,8 +285,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body
pub.callback do pub.callback do
pub.response_header.content_length.should eql(0) pub.should be_http_status(400).without_body
pub.response_header.status.should eql(400)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id is too large.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id is too large.")
EventMachine.stop EventMachine.stop
end end
...@@ -309,8 +301,7 @@ describe "Publisher Properties" do ...@@ -309,8 +301,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + 1.to_s).post :head => headers, :body => body pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + 1.to_s).post :head => headers, :body => body
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).with_body
pub.response_header.content_length.should_not eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -318,8 +309,7 @@ describe "Publisher Properties" do ...@@ -318,8 +309,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + 2.to_s).post :head => headers, :body => body pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + 2.to_s).post :head => headers, :body => body
pub.callback do pub.callback do
pub.response_header.status.should eql(403) pub.should be_http_status(403).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Number of channels were exceeded.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Number of channels were exceeded.")
EventMachine.stop EventMachine.stop
end end
...@@ -335,8 +325,7 @@ describe "Publisher Properties" do ...@@ -335,8 +325,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + 1.to_s).post :head => headers, :body => body pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + 1.to_s).post :head => headers, :body => body
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).with_body
pub.response_header.content_length.should_not eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -344,8 +333,7 @@ describe "Publisher Properties" do ...@@ -344,8 +333,7 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + 2.to_s).post :head => headers, :body => body pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + 2.to_s).post :head => headers, :body => body
pub.callback do pub.callback do
pub.response_header.status.should eql(403) pub.should be_http_status(403).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Number of channels were exceeded.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Number of channels were exceeded.")
EventMachine.stop EventMachine.stop
end end
...@@ -421,14 +409,12 @@ describe "Publisher Properties" do ...@@ -421,14 +409,12 @@ describe "Publisher Properties" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
stats.callback do stats.callback do
stats.response_header.status.should eql(200) stats.should be_http_status(200).with_body
stats.response_header.content_length.should_not eql(0)
response = JSON.parse(stats.response) response = JSON.parse(stats.response)
response["channels"].to_s.should_not be_empty response["channels"].to_s.should_not be_empty
response["channels"].to_i.should eql(0) response["channels"].to_i.should eql(0)
...@@ -460,15 +446,13 @@ describe "Publisher Properties" do ...@@ -460,15 +446,13 @@ describe "Publisher Properties" do
if resp.strip.empty? if resp.strip.empty?
stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'} stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'}
stats.callback do stats.callback do
stats.response_header.status.should eql(200) stats.should be_http_status(200).with_body
stats.response_header.content_length.should_not eql(0)
response = JSON.parse(stats.response) response = JSON.parse(stats.response)
response["subscribers"].to_i.should eql(1) response["subscribers"].to_i.should eql(1)
response["channels"].to_i.should eql(1) response["channels"].to_i.should eql(1)
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
end end
...@@ -480,8 +464,7 @@ describe "Publisher Properties" do ...@@ -480,8 +464,7 @@ describe "Publisher Properties" do
stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'} stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'}
stats.callback do stats.callback do
stats.response_header.status.should eql(200) stats.should be_http_status(200).with_body
stats.response_header.content_length.should_not eql(0)
response = JSON.parse(stats.response) response = JSON.parse(stats.response)
response["subscribers"].to_i.should eql(0) response["subscribers"].to_i.should eql(0)
response["channels"].to_i.should eql(0) response["channels"].to_i.should eql(0)
...@@ -516,16 +499,14 @@ describe "Publisher Properties" do ...@@ -516,16 +499,14 @@ describe "Publisher Properties" do
if resp.strip.empty? if resp.strip.empty?
stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'} stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'}
stats.callback do stats.callback do
stats.response_header.status.should eql(200) stats.should be_http_status(200).with_body
stats.response_header.content_length.should_not eql(0)
response = JSON.parse(stats.response) response = JSON.parse(stats.response)
response["subscribers"].to_i.should eql(1) response["subscribers"].to_i.should eql(1)
response["channels"].to_i.should eql(2) response["channels"].to_i.should eql(2)
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_1.to_s).delete :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_1.to_s).delete :head => headers
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
end end
...@@ -539,15 +520,14 @@ describe "Publisher Properties" do ...@@ -539,15 +520,14 @@ describe "Publisher Properties" do
stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'} stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'}
stats.callback do stats.callback do
stats.response_header.status.should eql(200) stats.should be_http_status(200).with_body
stats.response_header.content_length.should_not eql(0)
response = JSON.parse(stats.response) response = JSON.parse(stats.response)
response["subscribers"].to_i.should eql(1) response["subscribers"].to_i.should eql(1)
response["channels"].to_i.should eql(1) response["channels"].to_i.should eql(1)
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_2.to_s).post :head => headers, :body=> body pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_2.to_s).post :head => headers, :body=> body
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).with_body
end end
end end
elsif !stage2_complete elsif !stage2_complete
...@@ -559,8 +539,7 @@ describe "Publisher Properties" do ...@@ -559,8 +539,7 @@ describe "Publisher Properties" do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_2.to_s).delete :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_2.to_s).delete :head => headers
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
else else
...@@ -571,8 +550,7 @@ describe "Publisher Properties" do ...@@ -571,8 +550,7 @@ describe "Publisher Properties" do
stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'} stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'}
stats.callback do stats.callback do
stats.response_header.status.should eql(200) stats.should be_http_status(200).with_body
stats.response_header.content_length.should_not eql(0)
response = JSON.parse(stats.response) response = JSON.parse(stats.response)
response["subscribers"].to_i.should eql(0) response["subscribers"].to_i.should eql(0)
response["channels"].to_i.should eql(0) response["channels"].to_i.should eql(0)
...@@ -620,8 +598,7 @@ describe "Publisher Properties" do ...@@ -620,8 +598,7 @@ describe "Publisher Properties" do
stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'} stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'}
stats.callback do stats.callback do
stats.response_header.status.should eql(200) stats.should be_http_status(200).with_body
stats.response_header.content_length.should_not eql(0)
response = JSON.parse(stats.response) response = JSON.parse(stats.response)
response["subscribers"].to_i.should eql(2) response["subscribers"].to_i.should eql(2)
response["channels"].to_i.should eql(2) response["channels"].to_i.should eql(2)
...@@ -629,23 +606,20 @@ describe "Publisher Properties" do ...@@ -629,23 +606,20 @@ describe "Publisher Properties" do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_1.to_s).delete :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_1.to_s).delete :head => headers
pub_1.callback do pub_1.callback do
pub_1.response_header.status.should eql(200) pub_1.should be_http_status(200).without_body
pub_1.response_header.content_length.should eql(0)
pub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_2.to_s).delete :head => headers pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_2.to_s).delete :head => headers
pub_2.callback do pub_2.callback do
pub_2.response_header.status.should eql(200) pub_2.should be_http_status(200).without_body
pub_2.response_header.content_length.should eql(0)
pub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
EM.add_timer(5) do EM.add_timer(5) do
stats_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'} stats_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'}
stats_2.callback do stats_2.callback do
stats_2.response_header.status.should eql(200) stats_2.should be_http_status(200).with_body
stats_2.response_header.content_length.should_not eql(0)
response = JSON.parse(stats_2.response) response = JSON.parse(stats_2.response)
response["subscribers"].to_i.should eql(0) response["subscribers"].to_i.should eql(0)
response["channels"].to_i.should eql(0) response["channels"].to_i.should eql(0)
...@@ -677,8 +651,7 @@ describe "Publisher Properties" do ...@@ -677,8 +651,7 @@ describe "Publisher Properties" do
if resp == "#{conf.header_template}\r\n" if resp == "#{conf.header_template}\r\n"
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
end end
...@@ -731,8 +704,7 @@ describe "Publisher Properties" do ...@@ -731,8 +704,7 @@ describe "Publisher Properties" do
EM.add_timer(1) do EM.add_timer(1) do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
end end
...@@ -768,8 +740,7 @@ describe "Publisher Properties" do ...@@ -768,8 +740,7 @@ describe "Publisher Properties" do
if resp.strip.empty? if resp.strip.empty?
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
else else
......
...@@ -7,18 +7,20 @@ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) ...@@ -7,18 +7,20 @@ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Bundler.require(:default, :test) if defined?(Bundler) Bundler.require(:default, :test) if defined?(Bundler)
require 'nginx_configuration' require 'nginx_configuration'
require 'custom_http_matchers'
RSpec.configure do |config| RSpec.configure do |config|
config.after(:each) do config.after(:each) do
NginxTestHelper::Config.delete_config_and_log_files(config_id) if has_passed? NginxTestHelper::Config.delete_config_and_log_files(config_id) if has_passed?
end end
config.order = "random" config.order = "random"
config.include(CustomHttpMatchers)
end end
def publish_message_inline(channel, headers, body, &block) def publish_message_inline(channel, headers, body, &block)
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body
pub.callback do pub.callback do
fail("Request was not accepted") if pub.response_header.status != 200 pub.should be_http_status(200)
block.call unless block.nil? block.call unless block.nil?
end end
pub pub
...@@ -27,7 +29,7 @@ end ...@@ -27,7 +29,7 @@ end
def publish_message(channel, headers, body) def publish_message(channel, headers, body)
EventMachine.run do EventMachine.run do
pub = publish_message_inline(channel, headers, body) do pub = publish_message_inline(channel, headers, body) do
pub.response_header.content_length.should_not eql(0) pub.should be_http_status(200).with_body
response = JSON.parse(pub.response) response = JSON.parse(pub.response)
response["channel"].to_s.should eql(channel) response["channel"].to_s.should eql(channel)
EventMachine.stop EventMachine.stop
......
...@@ -33,8 +33,7 @@ describe "Comunication Properties" do ...@@ -33,8 +33,7 @@ describe "Comunication Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.callback do |chunk| sub_1.callback do |chunk|
sub_1.response_header.status.should eql(403) sub_1.should be_http_status(403).without_body
sub_1.response_header.content_length.should eql(0)
sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscriber could not create channels.") sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscriber could not create channels.")
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body
......
...@@ -108,7 +108,7 @@ describe "Subscriber Properties" do ...@@ -108,7 +108,7 @@ describe "Subscriber Properties" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("") sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("")
sub_1.response_header['ETAG'].to_s.should_not eql("") sub_1.response_header['ETAG'].to_s.should_not eql("")
sub_1.response.should eql("#{body}_2\r\n#{body}_1\r\n") sub_1.response.should eql("#{body}_2\r\n#{body}_1\r\n")
...@@ -116,7 +116,7 @@ describe "Subscriber Properties" do ...@@ -116,7 +116,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']})
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(200) sub_2.should be_http_status(200)
sub_2.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_1.response_header['LAST_MODIFIED']) sub_2.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_1.response_header['LAST_MODIFIED'])
sub_2.response_header['ETAG'].to_s.should eql("0") sub_2.response_header['ETAG'].to_s.should eql("0")
sub_2.response.should eql("#{body}1_1\r\n") sub_2.response.should eql("#{body}1_1\r\n")
...@@ -124,7 +124,7 @@ describe "Subscriber Properties" do ...@@ -124,7 +124,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']})
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers
sub_3.callback do sub_3.callback do
sub_3.response_header.status.should eql(200) sub_3.should be_http_status(200)
sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED']) sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED'])
sub_3.response_header['ETAG'].to_s.should eql("0") sub_3.response_header['ETAG'].to_s.should eql("0")
sub_3.response.should eql("#{body}1_2\r\n") sub_3.response.should eql("#{body}1_2\r\n")
...@@ -153,10 +153,9 @@ describe "Subscriber Properties" do ...@@ -153,10 +153,9 @@ describe "Subscriber Properties" do
sub.callback do sub.callback do
stop = Time.now stop = Time.now
time_diff_sec(start, stop).should be_in_the_interval(10, 10.5) time_diff_sec(start, stop).should be_in_the_interval(10, 10.5)
sub.response_header.status.should eql(304) sub.should be_http_status(304).without_body
Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i.should be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i) Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i.should be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i)
sub.response_header['ETAG'].to_s.should eql("0") sub.response_header['ETAG'].to_s.should eql("0")
sub.response_header.content_length.should eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -173,10 +172,9 @@ describe "Subscriber Properties" do ...@@ -173,10 +172,9 @@ describe "Subscriber Properties" do
sub.callback do sub.callback do
stop = Time.now stop = Time.now
time_diff_sec(start, stop).should be_in_the_interval(5, 5.5) time_diff_sec(start, stop).should be_in_the_interval(5, 5.5)
sub.response_header.status.should eql(304) sub.should be_http_status(304).without_body
Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i.should be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i) Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i.should be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i)
sub.response_header['ETAG'].to_s.should eql("0") sub.response_header['ETAG'].to_s.should eql("0")
sub.response_header.content_length.should eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -193,10 +191,9 @@ describe "Subscriber Properties" do ...@@ -193,10 +191,9 @@ describe "Subscriber Properties" do
sub.callback do sub.callback do
stop = Time.now stop = Time.now
time_diff_sec(start, stop).should be_in_the_interval(3, 3.5) time_diff_sec(start, stop).should be_in_the_interval(3, 3.5)
sub.response_header.status.should eql(304) sub.should be_http_status(304).without_body
Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i.should be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i) Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i.should be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i)
sub.response_header['ETAG'].to_s.should eql("0") sub.response_header['ETAG'].to_s.should eql("0")
sub.response_header.content_length.should eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -213,8 +210,7 @@ describe "Subscriber Properties" do ...@@ -213,8 +210,7 @@ describe "Subscriber Properties" do
sub.callback do sub.callback do
stop = Time.now stop = Time.now
time_diff_sec(start, stop).should be_in_the_interval(5, 5.5) time_diff_sec(start, stop).should be_in_the_interval(5, 5.5)
sub.response_header.status.should eql(304) sub.should be_http_status(304).without_body
sub.response_header.content_length.should eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -249,7 +245,7 @@ describe "Subscriber Properties" do ...@@ -249,7 +245,7 @@ describe "Subscriber Properties" do
EM.add_timer(2) do EM.add_timer(2) do
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge({'If-Modified-Since' => 'Thu, 1 Jan 1970 00:00:00 GMT', 'If-None-Match' => 0}) sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge({'If-Modified-Since' => 'Thu, 1 Jan 1970 00:00:00 GMT', 'If-None-Match' => 0})
sub.callback do sub.callback do
sub.response_header.status.should eql(200) sub.should be_http_status(200)
stored_messages.should eql(messagens_to_publish + 1) stored_messages.should eql(messagens_to_publish + 1)
messages = sub.response.split("\r\n") messages = sub.response.split("\r\n")
messages.count.should eql(messagens_to_publish + 1) messages.count.should eql(messagens_to_publish + 1)
...@@ -273,13 +269,13 @@ describe "Subscriber Properties" do ...@@ -273,13 +269,13 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_1.to_s + '/' + channel_2.to_s).get :head => headers.merge({'If-Modified-Since' => 'Thu, 1 Jan 1970 00:00:00 GMT', 'If-None-Match' => 0}) sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_1.to_s + '/' + channel_2.to_s).get :head => headers.merge({'If-Modified-Since' => 'Thu, 1 Jan 1970 00:00:00 GMT', 'If-None-Match' => 0})
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
response = JSON.parse(sub_1.response) response = JSON.parse(sub_1.response)
response["channel"].should eql(channel_1) response["channel"].should eql(channel_1)
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_1.to_s + '/' + channel_2.to_s).get :head => headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']}) sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_1.to_s + '/' + channel_2.to_s).get :head => headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']})
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(200) sub_2.should be_http_status(200)
response = JSON.parse(sub_2.response) response = JSON.parse(sub_2.response)
response["channel"].should eql(channel_2) response["channel"].should eql(channel_2)
sub_2.response_header['ETAG'].to_i.should eql(sub_1.response_header['ETAG'].to_i + 1) sub_2.response_header['ETAG'].to_i.should eql(sub_1.response_header['ETAG'].to_i + 1)
...@@ -303,7 +299,7 @@ describe "Subscriber Properties" do ...@@ -303,7 +299,7 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
response = JSON.parse(sub_1.response) response = JSON.parse(sub_1.response)
response["channel"].should eql(channel) response["channel"].should eql(channel)
response["id"].to_i.should eql(-2) response["id"].to_i.should eql(-2)
...@@ -312,8 +308,7 @@ describe "Subscriber Properties" do ...@@ -312,8 +308,7 @@ describe "Subscriber Properties" do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).without_body
pub.response_header.content_length.should eql(0)
pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
end end
......
...@@ -19,17 +19,17 @@ describe "Subscriber Padding by user agent" do ...@@ -19,17 +19,17 @@ describe "Subscriber Padding by user agent" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1") sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1")
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(1100 + conf.header_template.size + 4) sub_1.response.size.should eql(1100 + conf.header_template.size + 4)
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 2") sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 2")
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(200) sub_2.should be_http_status(200)
sub_2.response.size.should eql(4097 + conf.header_template.size + 4) sub_2.response.size.should eql(4097 + conf.header_template.size + 4)
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 3") sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 3")
sub_3.callback do sub_3.callback do
sub_3.response_header.status.should eql(200) sub_3.should be_http_status(200)
sub_3.response.size.should eql(conf.header_template.size + 2) sub_3.response.size.should eql(conf.header_template.size + 2)
EventMachine.stop EventMachine.stop
...@@ -49,17 +49,17 @@ describe "Subscriber Padding by user agent" do ...@@ -49,17 +49,17 @@ describe "Subscriber Padding by user agent" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1") sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1")
sub_1.callback { sub_1.callback {
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(500 + body.size + 4) sub_1.response.size.should eql(500 + body.size + 4)
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 2") sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 2")
sub_2.callback { sub_2.callback {
sub_2.response_header.status.should eql(200) sub_2.should be_http_status(200)
sub_2.response.size.should eql(body.size + 2) sub_2.response.size.should eql(body.size + 2)
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 3") sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 3")
sub_3.callback { sub_3.callback {
sub_3.response_header.status.should eql(200) sub_3.should be_http_status(200)
sub_3.response.size.should eql(body.size + 2) sub_3.response.size.should eql(body.size + 2)
EventMachine.stop EventMachine.stop
...@@ -83,7 +83,7 @@ describe "Subscriber Padding by user agent" do ...@@ -83,7 +83,7 @@ describe "Subscriber Padding by user agent" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1") sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1")
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(expected_padding + i + 4) sub_1.response.size.should eql(expected_padding + i + 4)
i = 105 i = 105
...@@ -91,7 +91,7 @@ describe "Subscriber Padding by user agent" do ...@@ -91,7 +91,7 @@ describe "Subscriber Padding by user agent" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1") sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1")
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(expected_padding + i + 4) sub_1.response.size.should eql(expected_padding + i + 4)
i = 221 i = 221
...@@ -99,7 +99,7 @@ describe "Subscriber Padding by user agent" do ...@@ -99,7 +99,7 @@ describe "Subscriber Padding by user agent" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1") sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1")
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(expected_padding + i + 4) sub_1.response.size.should eql(expected_padding + i + 4)
i = 331 i = 331
...@@ -107,7 +107,7 @@ describe "Subscriber Padding by user agent" do ...@@ -107,7 +107,7 @@ describe "Subscriber Padding by user agent" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1") sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1")
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(expected_padding + i + 4) sub_1.response.size.should eql(expected_padding + i + 4)
i = 435 i = 435
...@@ -115,7 +115,7 @@ describe "Subscriber Padding by user agent" do ...@@ -115,7 +115,7 @@ describe "Subscriber Padding by user agent" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1") sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1")
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(expected_padding + i + 4) sub_1.response.size.should eql(expected_padding + i + 4)
i = 502 i = 502
...@@ -123,14 +123,14 @@ describe "Subscriber Padding by user agent" do ...@@ -123,14 +123,14 @@ describe "Subscriber Padding by user agent" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1") sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1")
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(expected_padding + i + 4) sub_1.response.size.should eql(expected_padding + i + 4)
i = 550 i = 550
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1") sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge("User-Agent" => "Test 1")
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(i + 2) sub_1.response.size.should eql(i + 2)
EventMachine.stop EventMachine.stop
...@@ -159,12 +159,12 @@ describe "Subscriber Padding by user agent" do ...@@ -159,12 +159,12 @@ describe "Subscriber Padding by user agent" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?ua=test 1').get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?ua=test 1').get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response.size.should eql(1024 + conf.header_template.size + 4) sub_1.response.size.should eql(1024 + conf.header_template.size + 4)
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?ua=test 2').get :head => headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?ua=test 2').get :head => headers
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(200) sub_2.should be_http_status(200)
sub_2.response.size.should eql(conf.header_template.size + 2) sub_2.response.size.should eql(conf.header_template.size + 2)
EventMachine.stop EventMachine.stop
......
...@@ -13,10 +13,9 @@ describe "Subscriber Properties" do ...@@ -13,10 +13,9 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(304) sub_1.should be_http_status(304).without_body
sub_1.response_header['LAST_MODIFIED'].to_s.should eql("") sub_1.response_header['LAST_MODIFIED'].to_s.should eql("")
sub_1.response_header['ETAG'].to_s.should eql("") sub_1.response_header['ETAG'].to_s.should eql("")
sub_1.response_header.content_length.should eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -31,10 +30,9 @@ describe "Subscriber Properties" do ...@@ -31,10 +30,9 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(304) sub_1.should be_http_status(304).without_body
Time.parse(sub_1.response_header['LAST_MODIFIED'].to_s).should eql(Time.parse(sent_headers['If-Modified-Since'])) Time.parse(sub_1.response_header['LAST_MODIFIED'].to_s).should eql(Time.parse(sent_headers['If-Modified-Since']))
sub_1.response_header['ETAG'].to_s.should eql(sent_headers['If-None-Match']) sub_1.response_header['ETAG'].to_s.should eql(sent_headers['If-None-Match'])
sub_1.response_header.content_length.should eql(0)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -55,7 +53,7 @@ describe "Subscriber Properties" do ...@@ -55,7 +53,7 @@ describe "Subscriber Properties" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("") sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("")
sub_1.response_header['ETAG'].to_s.should eql("0") sub_1.response_header['ETAG'].to_s.should eql("0")
sub_1.response.should eql("#{body}\r\n") sub_1.response.should eql("#{body}\r\n")
...@@ -74,7 +72,7 @@ describe "Subscriber Properties" do ...@@ -74,7 +72,7 @@ describe "Subscriber Properties" do
publish_message_inline(channel, {}, body) publish_message_inline(channel, {}, body)
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("") sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("")
sub_1.response_header['ETAG'].to_s.should_not eql("") sub_1.response_header['ETAG'].to_s.should_not eql("")
sub_1.response.should eql("#{body}\r\n") sub_1.response.should eql("#{body}\r\n")
...@@ -82,8 +80,7 @@ describe "Subscriber Properties" do ...@@ -82,8 +80,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']})
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(304) sub_2.should be_http_status(304).without_body
sub_2.response_header.content_length.should eql(0)
sub_2.response_header['LAST_MODIFIED'].to_s.should eql(sub_1.response_header['LAST_MODIFIED']) sub_2.response_header['LAST_MODIFIED'].to_s.should eql(sub_1.response_header['LAST_MODIFIED'])
sub_2.response_header['ETAG'].to_s.should eql(sub_1.response_header['ETAG']) sub_2.response_header['ETAG'].to_s.should eql(sub_1.response_header['ETAG'])
...@@ -93,7 +90,7 @@ describe "Subscriber Properties" do ...@@ -93,7 +90,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']})
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers
sub_3.callback do sub_3.callback do
sub_3.response_header.status.should eql(200) sub_3.should be_http_status(200)
sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED']) sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED'])
sub_3.response_header['ETAG'].to_s.should eql("0") sub_3.response_header['ETAG'].to_s.should eql("0")
sub_3.response.should eql("#{body}1\r\n") sub_3.response.should eql("#{body}1\r\n")
...@@ -118,7 +115,7 @@ describe "Subscriber Properties" do ...@@ -118,7 +115,7 @@ describe "Subscriber Properties" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b1').get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b1').get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("") sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("")
sub_1.response_header['ETAG'].to_s.should eql("2") sub_1.response_header['ETAG'].to_s.should eql("2")
sub_1.response.should eql("#{body}2\r\n") sub_1.response.should eql("#{body}2\r\n")
...@@ -126,8 +123,7 @@ describe "Subscriber Properties" do ...@@ -126,8 +123,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']})
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(304) sub_2.should be_http_status(304).without_body
sub_2.response_header.content_length.should eql(0)
sub_2.response_header['LAST_MODIFIED'].to_s.should eql(sub_1.response_header['LAST_MODIFIED']) sub_2.response_header['LAST_MODIFIED'].to_s.should eql(sub_1.response_header['LAST_MODIFIED'])
sub_2.response_header['ETAG'].to_s.should eql(sub_1.response_header['ETAG']) sub_2.response_header['ETAG'].to_s.should eql(sub_1.response_header['ETAG'])
...@@ -137,7 +133,7 @@ describe "Subscriber Properties" do ...@@ -137,7 +133,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']})
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers
sub_3.callback do sub_3.callback do
sub_3.response_header.status.should eql(200) sub_3.should be_http_status(200)
sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED']) sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED'])
sub_3.response_header['ETAG'].to_s.should eql("0") sub_3.response_header['ETAG'].to_s.should eql("0")
sub_3.response.should eql("#{body}3\r\n") sub_3.response.should eql("#{body}3\r\n")
...@@ -164,7 +160,7 @@ describe "Subscriber Properties" do ...@@ -164,7 +160,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'Last-Event-Id' => 'event 2'}) sent_headers = headers.merge({'Last-Event-Id' => 'event 2'})
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("") sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("")
sub_1.response_header['ETAG'].to_s.should eql("3") sub_1.response_header['ETAG'].to_s.should eql("3")
sub_1.response.should eql("msg 3\r\nmsg 4\r\n") sub_1.response.should eql("msg 3\r\nmsg 4\r\n")
...@@ -172,8 +168,7 @@ describe "Subscriber Properties" do ...@@ -172,8 +168,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']})
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(304) sub_2.should be_http_status(304).without_body
sub_2.response_header.content_length.should eql(0)
sub_2.response_header['LAST_MODIFIED'].to_s.should eql(sub_1.response_header['LAST_MODIFIED']) sub_2.response_header['LAST_MODIFIED'].to_s.should eql(sub_1.response_header['LAST_MODIFIED'])
sub_2.response_header['ETAG'].to_s.should eql(sub_1.response_header['ETAG']) sub_2.response_header['ETAG'].to_s.should eql(sub_1.response_header['ETAG'])
...@@ -183,7 +178,7 @@ describe "Subscriber Properties" do ...@@ -183,7 +178,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']})
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers
sub_3.callback do sub_3.callback do
sub_3.response_header.status.should eql(200) sub_3.should be_http_status(200)
sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED']) sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED'])
sub_3.response_header['ETAG'].to_s.should eql("0") sub_3.response_header['ETAG'].to_s.should eql("0")
sub_3.response.should eql("#{body}3\r\n") sub_3.response.should eql("#{body}3\r\n")
...@@ -208,7 +203,7 @@ describe "Subscriber Properties" do ...@@ -208,7 +203,7 @@ describe "Subscriber Properties" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("") sub_1.response_header['LAST_MODIFIED'].to_s.should_not eql("")
sub_1.response_header['ETAG'].to_s.should_not eql("") sub_1.response_header['ETAG'].to_s.should_not eql("")
sub_1.response.should eql("#{body}_2\r\n#{body}_1\r\n") sub_1.response.should eql("#{body}_2\r\n#{body}_1\r\n")
...@@ -216,8 +211,7 @@ describe "Subscriber Properties" do ...@@ -216,8 +211,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_1.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_1.response_header['ETAG']})
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(304) sub_2.should be_http_status(304).without_body
sub_2.response_header.content_length.should eql(0)
sub_2.response_header['LAST_MODIFIED'].to_s.should eql(sub_1.response_header['LAST_MODIFIED']) sub_2.response_header['LAST_MODIFIED'].to_s.should eql(sub_1.response_header['LAST_MODIFIED'])
sub_2.response_header['ETAG'].to_s.should eql(sub_1.response_header['ETAG']) sub_2.response_header['ETAG'].to_s.should eql(sub_1.response_header['ETAG'])
...@@ -227,7 +221,7 @@ describe "Subscriber Properties" do ...@@ -227,7 +221,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_2.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_2.response_header['ETAG']})
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers
sub_3.callback do sub_3.callback do
sub_3.response_header.status.should eql(200) sub_3.should be_http_status(200)
sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED']) sub_3.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_2.response_header['LAST_MODIFIED'])
sub_3.response_header['ETAG'].to_s.should eql("0") sub_3.response_header['ETAG'].to_s.should eql("0")
sub_3.response.should eql("#{body}1_1\r\n") sub_3.response.should eql("#{body}1_1\r\n")
...@@ -235,8 +229,7 @@ describe "Subscriber Properties" do ...@@ -235,8 +229,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_3.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_3.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_3.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_3.response_header['ETAG']})
sub_4 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers sub_4 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers
sub_4.callback do sub_4.callback do
sub_4.response_header.status.should eql(304) sub_4.should be_http_status(304).without_body
sub_4.response_header.content_length.should eql(0)
sub_4.response_header['LAST_MODIFIED'].to_s.should eql(sub_3.response_header['LAST_MODIFIED']) sub_4.response_header['LAST_MODIFIED'].to_s.should eql(sub_3.response_header['LAST_MODIFIED'])
sub_4.response_header['ETAG'].to_s.should eql(sub_3.response_header['ETAG']) sub_4.response_header['ETAG'].to_s.should eql(sub_3.response_header['ETAG'])
...@@ -246,7 +239,7 @@ describe "Subscriber Properties" do ...@@ -246,7 +239,7 @@ describe "Subscriber Properties" do
sent_headers = headers.merge({'If-Modified-Since' => sub_4.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_4.response_header['ETAG']}) sent_headers = headers.merge({'If-Modified-Since' => sub_4.response_header['LAST_MODIFIED'], 'If-None-Match' => sub_4.response_header['ETAG']})
sub_5 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers sub_5 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel_2.to_s + '/' + channel_1.to_s).get :head => sent_headers
sub_5.callback do sub_5.callback do
sub_5.response_header.status.should eql(200) sub_5.should be_http_status(200)
sub_5.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_4.response_header['LAST_MODIFIED']) sub_5.response_header['LAST_MODIFIED'].to_s.should_not eql(sub_4.response_header['LAST_MODIFIED'])
sub_5.response_header['ETAG'].to_s.should eql("0") sub_5.response_header['ETAG'].to_s.should eql("0")
sub_5.response.should eql("#{body}1_2\r\n") sub_5.response.should eql("#{body}1_2\r\n")
......
...@@ -16,8 +16,7 @@ describe "Subscriber Properties" do ...@@ -16,8 +16,7 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/').get :head => headers sub = EventMachine::HttpRequest.new(nginx_address + '/sub/').get :head => headers
sub.callback do sub.callback do
sub.response_header.content_length.should eql(0) sub.should be_http_status(400).without_body
sub.response_header.status.should eql(400)
sub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("No channel id provided.") sub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("No channel id provided.")
EventMachine.stop EventMachine.stop
end end
...@@ -46,23 +45,23 @@ describe "Subscriber Properties" do ...@@ -46,23 +45,23 @@ describe "Subscriber Properties" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(5) multi.responses[:callback].length.should eql(5)
multi.responses[:callback][:a].response_header.status.should eql(405) multi.responses[:callback][:a].should be_http_status(405)
multi.responses[:callback][:a].req.method.should eql("HEAD") multi.responses[:callback][:a].req.method.should eql("HEAD")
multi.responses[:callback][:a].response_header['ALLOW'].should eql("GET") multi.responses[:callback][:a].response_header['ALLOW'].should eql("GET")
multi.responses[:callback][:b].response_header.status.should eql(405) multi.responses[:callback][:b].should be_http_status(405)
multi.responses[:callback][:b].req.method.should eql("PUT") multi.responses[:callback][:b].req.method.should eql("PUT")
multi.responses[:callback][:b].response_header['ALLOW'].should eql("GET") multi.responses[:callback][:b].response_header['ALLOW'].should eql("GET")
multi.responses[:callback][:c].response_header.status.should eql(405) multi.responses[:callback][:c].should be_http_status(405)
multi.responses[:callback][:c].req.method.should eql("POST") multi.responses[:callback][:c].req.method.should eql("POST")
multi.responses[:callback][:c].response_header['ALLOW'].should eql("GET") multi.responses[:callback][:c].response_header['ALLOW'].should eql("GET")
multi.responses[:callback][:d].response_header.status.should eql(405) multi.responses[:callback][:d].should be_http_status(405)
multi.responses[:callback][:d].req.method.should eql("DELETE") multi.responses[:callback][:d].req.method.should eql("DELETE")
multi.responses[:callback][:d].response_header['ALLOW'].should eql("GET") multi.responses[:callback][:d].response_header['ALLOW'].should eql("GET")
multi.responses[:callback][:e].response_header.status.should_not eql(405) multi.responses[:callback][:e].should_not be_http_status(405)
multi.responses[:callback][:e].req.method.should eql("GET") multi.responses[:callback][:e].req.method.should eql("GET")
EventMachine.stop EventMachine.stop
...@@ -78,8 +77,7 @@ describe "Subscriber Properties" do ...@@ -78,8 +77,7 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(403) sub_1.should be_http_status(403).without_body
sub_1.response_header.content_length.should eql(0)
sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id not authorized for this method.") sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id not authorized for this method.")
EventMachine.stop EventMachine.stop
end end
...@@ -102,8 +100,7 @@ describe "Subscriber Properties" do ...@@ -102,8 +100,7 @@ describe "Subscriber Properties" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(3) multi.responses[:callback].length.should eql(3)
multi.responses[:callback].each do |name, response| multi.responses[:callback].each do |name, response|
response.response_header.status.should eql(403) response.should be_http_status(403).without_body
response.response_header.content_length.should eql(0)
response.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id not authorized for this method.") response.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id not authorized for this method.")
end end
...@@ -129,7 +126,7 @@ describe "Subscriber Properties" do ...@@ -129,7 +126,7 @@ describe "Subscriber Properties" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(7) multi.responses[:callback].length.should eql(7)
multi.responses[:callback].each do |name, response| multi.responses[:callback].each do |name, response|
response.response_header.status.should eql(200) response.should be_http_status(200)
end end
EventMachine.stop EventMachine.stop
...@@ -145,8 +142,7 @@ describe "Subscriber Properties" do ...@@ -145,8 +142,7 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s ).get :head => headers sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s ).get :head => headers
sub.callback do sub.callback do
sub.response_header.content_length.should eql(0) sub.should be_http_status(400).without_body
sub.response_header.status.should eql(400)
sub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id is too large.") sub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel id is too large.")
EventMachine.stop EventMachine.stop
end end
...@@ -167,20 +163,18 @@ describe "Subscriber Properties" do ...@@ -167,20 +163,18 @@ describe "Subscriber Properties" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(4) multi.responses[:callback].length.should eql(4)
multi.responses[:callback][:a].response_header.content_length.should eql(0) multi.responses[:callback][:a].should be_http_status(403).without_body
multi.responses[:callback][:a].response_header.status.should eql(403)
multi.responses[:callback][:a].response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribed too much broadcast channels.") multi.responses[:callback][:a].response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribed too much broadcast channels.")
multi.responses[:callback][:a].req.uri.to_s.should eql(nginx_address + '/sub/bd_test_broadcast_channels_without_common_channel') multi.responses[:callback][:a].req.uri.to_s.should eql(nginx_address + '/sub/bd_test_broadcast_channels_without_common_channel')
multi.responses[:callback][:b].response_header.content_length.should eql(0) multi.responses[:callback][:b].should be_http_status(403).without_body
multi.responses[:callback][:b].response_header.status.should eql(403)
multi.responses[:callback][:b].response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribed too much broadcast channels.") multi.responses[:callback][:b].response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribed too much broadcast channels.")
multi.responses[:callback][:b].req.uri.to_s.should eql(nginx_address + '/sub/bd_') multi.responses[:callback][:b].req.uri.to_s.should eql(nginx_address + '/sub/bd_')
multi.responses[:callback][:c].response_header.status.should eql(200) multi.responses[:callback][:c].should be_http_status(200)
multi.responses[:callback][:c].req.uri.to_s.should eql(nginx_address + '/sub/bd1') multi.responses[:callback][:c].req.uri.to_s.should eql(nginx_address + '/sub/bd1')
multi.responses[:callback][:d].response_header.status.should eql(200) multi.responses[:callback][:d].should be_http_status(200)
multi.responses[:callback][:d].req.uri.to_s.should eql(nginx_address + '/sub/bd') multi.responses[:callback][:d].req.uri.to_s.should eql(nginx_address + '/sub/bd')
EventMachine.stop EventMachine.stop
...@@ -202,18 +196,17 @@ describe "Subscriber Properties" do ...@@ -202,18 +196,17 @@ describe "Subscriber Properties" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(4) multi.responses[:callback].length.should eql(4)
multi.responses[:callback][:a].response_header.content_length.should eql(0) multi.responses[:callback][:a].should be_http_status(403).without_body
multi.responses[:callback][:a].response_header.status.should eql(403)
multi.responses[:callback][:a].response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribed too much broadcast channels.") multi.responses[:callback][:a].response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribed too much broadcast channels.")
multi.responses[:callback][:a].req.uri.to_s.should eql(nginx_address + '/sub/bd1/bd2/bd3/bd4/bd_1/bd_2/bd_3') multi.responses[:callback][:a].req.uri.to_s.should eql(nginx_address + '/sub/bd1/bd2/bd3/bd4/bd_1/bd_2/bd_3')
multi.responses[:callback][:b].response_header.status.should eql(200) multi.responses[:callback][:b].should be_http_status(200)
multi.responses[:callback][:b].req.uri.to_s.should eql(nginx_address + '/sub/bd1/bd2/bd_1/bd_2') multi.responses[:callback][:b].req.uri.to_s.should eql(nginx_address + '/sub/bd1/bd2/bd_1/bd_2')
multi.responses[:callback][:c].response_header.status.should eql(200) multi.responses[:callback][:c].should be_http_status(200)
multi.responses[:callback][:c].req.uri.to_s.should eql(nginx_address + '/sub/bd1/bd_1') multi.responses[:callback][:c].req.uri.to_s.should eql(nginx_address + '/sub/bd1/bd_1')
multi.responses[:callback][:d].response_header.status.should eql(200) multi.responses[:callback][:d].should be_http_status(200)
multi.responses[:callback][:d].req.uri.to_s.should eql(nginx_address + '/sub/bd1/bd2') multi.responses[:callback][:d].req.uri.to_s.should eql(nginx_address + '/sub/bd1/bd2')
EventMachine.stop EventMachine.stop
...@@ -229,8 +222,7 @@ describe "Subscriber Properties" do ...@@ -229,8 +222,7 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(403) sub_1.should be_http_status(403).without_body
sub_1.response_header.content_length.should eql(0)
sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscriber could not create channels.") sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscriber could not create channels.")
EventMachine.stop EventMachine.stop
end end
...@@ -249,7 +241,7 @@ describe "Subscriber Properties" do ...@@ -249,7 +241,7 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -269,7 +261,7 @@ describe "Subscriber Properties" do ...@@ -269,7 +261,7 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + broadcast_channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + broadcast_channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
EventMachine.stop EventMachine.stop
end end
end end
...@@ -289,8 +281,7 @@ describe "Subscriber Properties" do ...@@ -289,8 +281,7 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(403) sub_1.should be_http_status(403).without_body
sub_1.response_header.content_length.should eql(0)
sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscriber could not create channels.") sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscriber could not create channels.")
EventMachine.stop EventMachine.stop
end end
...@@ -312,8 +303,7 @@ describe "Subscriber Properties" do ...@@ -312,8 +303,7 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + broadcast_channel.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '/' + broadcast_channel.to_s).get :head => headers
sub_1.callback do sub_1.callback do
sub_1.response_header.status.should eql(403) sub_1.should be_http_status(403).without_body
sub_1.response_header.content_length.should eql(0)
sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscriber could not create channels.") sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscriber could not create channels.")
EventMachine.stop EventMachine.stop
end end
...@@ -579,13 +569,11 @@ describe "Subscriber Properties" do ...@@ -579,13 +569,11 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + 1.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + 1.to_s).get :head => headers
sub_1.stream do sub_1.stream do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response_header.content_length.should_not eql(0)
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + 2.to_s).get :head => headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + 2.to_s).get :head => headers
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(403) sub_2.should be_http_status(403).without_body
sub_2.response_header.content_length.should eql(0)
sub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Number of channels were exceeded.") sub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Number of channels were exceeded.")
EventMachine.stop EventMachine.stop
end end
...@@ -601,13 +589,11 @@ describe "Subscriber Properties" do ...@@ -601,13 +589,11 @@ describe "Subscriber Properties" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/ch1/' + channel.to_s + 1.to_s).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/ch1/' + channel.to_s + 1.to_s).get :head => headers
sub_1.stream do sub_1.stream do
sub_1.response_header.status.should eql(200) sub_1.should be_http_status(200)
sub_1.response_header.content_length.should_not eql(0)
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/ch1/' + channel.to_s + 2.to_s).get :head => headers sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/ch1/' + channel.to_s + 2.to_s).get :head => headers
sub_2.callback do sub_2.callback do
sub_2.response_header.status.should eql(403) sub_2.should be_http_status(403).without_body
sub_2.response_header.content_length.should eql(0)
sub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Number of channels were exceeded.") sub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Number of channels were exceeded.")
EventMachine.stop EventMachine.stop
end end
...@@ -785,14 +771,13 @@ describe "Subscriber Properties" do ...@@ -785,14 +771,13 @@ describe "Subscriber Properties" do
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_4 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_4 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_4.callback do sub_4.callback do
sub_4.response_header.status.should eql(403) sub_4.should be_http_status(403).without_body
sub_4.response_header.content_length.should eql(0)
sub_4.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribers limit per channel has been exceeded.") sub_4.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribers limit per channel has been exceeded.")
end end
sub_5 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + other_channel.to_s).get :head => headers sub_5 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + other_channel.to_s).get :head => headers
sub_5.callback do sub_5.callback do
sub_5.response_header.status.should eql(200) sub_5.should be_http_status(200)
EventMachine.stop EventMachine.stop
end end
end end
......
...@@ -33,23 +33,23 @@ describe "Subscriber WebSocket" do ...@@ -33,23 +33,23 @@ describe "Subscriber WebSocket" do
multi.callback do multi.callback do
multi.responses[:callback].length.should eql(5) multi.responses[:callback].length.should eql(5)
multi.responses[:callback][:a].response_header.status.should eql(405) multi.responses[:callback][:a].should be_http_status(405)
multi.responses[:callback][:a].req.method.should eql("HEAD") multi.responses[:callback][:a].req.method.should eql("HEAD")
multi.responses[:callback][:a].response_header['ALLOW'].should eql("GET") multi.responses[:callback][:a].response_header['ALLOW'].should eql("GET")
multi.responses[:callback][:b].response_header.status.should eql(405) multi.responses[:callback][:b].should be_http_status(405)
multi.responses[:callback][:b].req.method.should eql("PUT") multi.responses[:callback][:b].req.method.should eql("PUT")
multi.responses[:callback][:b].response_header['ALLOW'].should eql("GET") multi.responses[:callback][:b].response_header['ALLOW'].should eql("GET")
multi.responses[:callback][:c].response_header.status.should eql(405) multi.responses[:callback][:c].should be_http_status(405)
multi.responses[:callback][:c].req.method.should eql("POST") multi.responses[:callback][:c].req.method.should eql("POST")
multi.responses[:callback][:c].response_header['ALLOW'].should eql("GET") multi.responses[:callback][:c].response_header['ALLOW'].should eql("GET")
multi.responses[:callback][:d].response_header.status.should eql(405) multi.responses[:callback][:d].should be_http_status(405)
multi.responses[:callback][:d].req.method.should eql("DELETE") multi.responses[:callback][:d].req.method.should eql("DELETE")
multi.responses[:callback][:d].response_header['ALLOW'].should eql("GET") multi.responses[:callback][:d].response_header['ALLOW'].should eql("GET")
multi.responses[:callback][:e].response_header.status.should_not eql(405) multi.responses[:callback][:e].should_not be_http_status(405)
multi.responses[:callback][:e].req.method.should eql("GET") multi.responses[:callback][:e].req.method.should eql("GET")
EventMachine.stop EventMachine.stop
...@@ -311,8 +311,7 @@ describe "Subscriber WebSocket" do ...@@ -311,8 +311,7 @@ describe "Subscriber WebSocket" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30 pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).with_body
pub.response_header.content_length.should_not eql(0)
response = JSON.parse(pub.response) response = JSON.parse(pub.response)
response["channel"].to_s.should eql(channel) response["channel"].to_s.should eql(channel)
response["published_messages"].to_i.should eql(1) response["published_messages"].to_i.should eql(1)
...@@ -350,8 +349,7 @@ describe "Subscriber WebSocket" do ...@@ -350,8 +349,7 @@ describe "Subscriber WebSocket" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30 pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).with_body
pub.response_header.content_length.should_not eql(0)
response = JSON.parse(pub.response) response = JSON.parse(pub.response)
response["channel"].to_s.should eql(channel) response["channel"].to_s.should eql(channel)
response["published_messages"].to_i.should eql(0) response["published_messages"].to_i.should eql(0)
...@@ -378,8 +376,7 @@ describe "Subscriber WebSocket" do ...@@ -378,8 +376,7 @@ describe "Subscriber WebSocket" do
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30 pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30
pub.callback do pub.callback do
pub.response_header.status.should eql(200) pub.should be_http_status(200).with_body
pub.response_header.content_length.should_not eql(0)
response = JSON.parse(pub.response) response = JSON.parse(pub.response)
response["channel"].to_s.should eql(channel) response["channel"].to_s.should eql(channel)
response["published_messages"].to_i.should eql(0) response["published_messages"].to_i.should eql(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment