Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nginx-push-stream-module
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
nginx-push-stream-module
Commits
f8675232
Commit
f8675232
authored
Dec 26, 2010
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improving tests
parent
813aab64
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
506 additions
and
52 deletions
+506
-52
base_test_case.rb
test/base_test_case.rb
+21
-6
suite.rb
test/suite.rb
+6
-2
test_broadcast_properties.rb
test/test_broadcast_properties.rb
+77
-0
test_comunication_properties.rb
test/test_comunication_properties.rb
+140
-0
test_create_many_channels.rb
test/test_create_many_channels.rb
+1
-3
test_publish_messages.rb
test/test_publish_messages.rb
+4
-12
test_publisher_properties.rb
test/test_publisher_properties.rb
+118
-0
test_setup_parameters.rb
test/test_setup_parameters.rb
+20
-20
test_subscriber_connection_cleanup.rb
test/test_subscriber_connection_cleanup.rb
+36
-9
test_subscriber_properties.rb
test/test_subscriber_properties.rb
+83
-0
No files found.
test/base_test_case.rb
View file @
f8675232
...
@@ -6,8 +6,12 @@ require 'ftools'
...
@@ -6,8 +6,12 @@ require 'ftools'
module
BaseTestCase
module
BaseTestCase
def
setup
def
setup
config_test_name
=
"config_
#{
self
.
method_name
}
"
self
.
send
(
config_test_name
)
if
self
.
respond_to?
(
config_test_name
)
if
@test_config_file
and
@test_config_file
!=
""
if
@test_config_file
and
@test_config_file
!=
""
self
.
create_config_file
self
.
create_config_file
self
.
stop_server
self
.
start_server
self
.
start_server
end
end
end
end
...
@@ -65,6 +69,13 @@ module BaseTestCase
...
@@ -65,6 +69,13 @@ module BaseTestCase
(
finish
-
start
)
(
finish
-
start
)
end
end
def
fail_if_connecttion_error
(
client
)
client
.
errback
{
|
error
|
fail
(
"Erro inexperado na execucao do teste:
#{
error
.
last_effective_url
.
nil?
?
""
:
error
.
last_effective_url
.
request_uri
}
#{
error
.
response
}
"
)
EventMachine
.
stop
}
end
@@config_template
=
%q{
@@config_template
=
%q{
pid logs/nginx.pid;
pid logs/nginx.pid;
error_log logs/nginx-main_error.log debug;
error_log logs/nginx-main_error.log debug;
...
@@ -112,12 +123,14 @@ http {
...
@@ -112,12 +123,14 @@ http {
set $push_stream_channel_id $arg_id;
set $push_stream_channel_id $arg_id;
# message template
# message template
push_stream_message_template "<%= @message_template.nil? ? '<script>p(~id~,\'~channel~\',\'~text~\');</script>' : @message_template %>";
push_stream_message_template "<%= @message_template.nil? ? '<script>p(~id~,\'~channel~\',\'~text~\');</script>' : @message_template %>";
# store messages
push_stream_store_messages <%= @store_messages.nil? ? 'on' : @store_messages %>;
# max messages to store in memory
# max messages to store in memory
push_stream_max_message_buffer_length <%= @max_message_buffer_length.nil? ? 20 : @max_message_buffer_length %>;
push_stream_max_message_buffer_length <%= @max_message_buffer_length.nil? ? 20 : @max_message_buffer_length %>;
# min messages to store in memory
push_stream_min_message_buffer_length <%= @min_message_buffer_length.nil? ? 0 : @min_message_buffer_length %>;
# message ttl
# message ttl
push_stream_min_message_buffer_timeout 50m;
push_stream_min_message_buffer_timeout <%= @min_message_buffer_timeout.nil? ? '50m' : @min_message_buffer_timeout %>;
push_stream_max_channel_id_length <%= @max_channel_id_length.nil? ? 10 : @max_channel_id_length %>;
# client_max_body_size MUST be equal to client_body_buffer_size or
# client_max_body_size MUST be equal to client_body_buffer_size or
# you will be sorry.
# you will be sorry.
...
@@ -136,16 +149,18 @@ http {
...
@@ -136,16 +149,18 @@ http {
# message template
# message template
push_stream_message_template "<%= @message_template.nil? ? '<script>p(~id~,\'~channel~\',\'~text~\');</script>' : @message_template %>";
push_stream_message_template "<%= @message_template.nil? ? '<script>p(~id~,\'~channel~\',\'~text~\');</script>' : @message_template %>";
# content-type
# content-type
push_stream_content_type "
text/html; charset=utf-8
";
push_stream_content_type "
<%= @content_type.nil? ? 'text/html; charset=utf-8' : @content_type %>
";
# subscriber may create channels on demand or only authorized
# subscriber may create channels on demand or only authorized
# (publisher) may do it?
# (publisher) may do it?
push_stream_authorized_channels_only
off
;
push_stream_authorized_channels_only
<%= @authorized_channels_only.nil? ? 'off' : @authorized_channels_only %>
;
# ping frequency
# ping frequency
push_stream_ping_message_interval <%= @ping_message_interval.nil? ? '10s' : @ping_message_interval %>;
push_stream_ping_message_interval <%= @ping_message_interval.nil? ? '10s' : @ping_message_interval %>;
# disconnection candidates test frequency
# disconnection candidates test frequency
push_stream_subscriber_disconnect_interval
1s
;
push_stream_subscriber_disconnect_interval
<%= @subscriber_disconnect_interval.nil? ? '0s' : @subscriber_disconnect_interval %>
;
# connection ttl to enable recycle
# connection ttl to enable recycle
push_stream_subscriber_connection_timeout <%= @subscriber_connection_timeout.nil? ? '0s' : @subscriber_connection_timeout %>;
push_stream_subscriber_connection_timeout <%= @subscriber_connection_timeout.nil? ? '0s' : @subscriber_connection_timeout %>;
push_stream_broadcast_channel_prefix "<%= @broadcast_channel_prefix.nil? ? 'broad_' : @broadcast_channel_prefix %>";
push_stream_broadcast_channel_max_qtd <%= @broadcast_channel_max_qtd.nil? ? '3' : @broadcast_channel_max_qtd %>;
# solving some leakage problem with persitent connections in
# solving some leakage problem with persitent connections in
# Nginx's chunked filter (ngx_http_chunked_filter_module.c)
# Nginx's chunked filter (ngx_http_chunked_filter_module.c)
chunked_transfer_encoding off;
chunked_transfer_encoding off;
...
...
test/suite.rb
View file @
f8675232
require
'test/unit'
require
'test/unit'
require
File
.
expand_path
(
'test_broadcast_properties'
,
File
.
dirname
(
__FILE__
))
require
File
.
expand_path
(
'test_comunication_properties'
,
File
.
dirname
(
__FILE__
))
require
File
.
expand_path
(
'test_create_many_channels'
,
File
.
dirname
(
__FILE__
))
require
File
.
expand_path
(
'test_publish_messages'
,
File
.
dirname
(
__FILE__
))
require
File
.
expand_path
(
'test_publish_messages'
,
File
.
dirname
(
__FILE__
))
require
File
.
expand_path
(
'test_publisher_properties'
,
File
.
dirname
(
__FILE__
))
#require File.expand_path('test_setup_parameters', File.dirname(__FILE__))
require
File
.
expand_path
(
'test_subscriber_connection_cleanup'
,
File
.
dirname
(
__FILE__
))
require
File
.
expand_path
(
'test_subscriber_connection_cleanup'
,
File
.
dirname
(
__FILE__
))
require
File
.
expand_path
(
'test_setup_parameters'
,
File
.
dirname
(
__FILE__
))
require
File
.
expand_path
(
'test_subscriber_properties'
,
File
.
dirname
(
__FILE__
))
require
File
.
expand_path
(
'test_create_many_channels'
,
File
.
dirname
(
__FILE__
))
test/test_broadcast_properties.rb
0 → 100644
View file @
f8675232
require
'rubygems'
require
'em-http'
require
'test/unit'
require
File
.
expand_path
(
'base_test_case'
,
File
.
dirname
(
__FILE__
))
class
TestBroadcastProperties
<
Test
::
Unit
::
TestCase
include
BaseTestCase
def
config_test_broadcast_channel_prefix
@test_config_file
=
"test_broadcast_channel_prefix.conf"
@authorized_channels_only
=
"on"
@header_template
=
"connected"
@broadcast_channel_prefix
=
"XXX_"
end
def
test_broadcast_channel_prefix
channel
=
'ch1'
channel_broad
=
'XXX_123'
channel_broad_fail
=
'YYY_123'
headers
=
{
'accept'
=>
'text/html'
}
body
=
'broadcast channel prefix'
EventMachine
.
run
{
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
pub
.
callback
{
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'/'
+
channel_broad_fail
).
get
:head
=>
headers
,
:timeout
=>
60
sub_1
.
callback
{
|
chunk
|
assert_equal
(
403
,
sub_1
.
response_header
.
status
,
"Subscriber was not forbidden"
)
sub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'/'
+
channel_broad
).
get
:head
=>
headers
,
:timeout
=>
60
sub_2
.
stream
{
|
chunk
|
assert_equal
(
"
#{
@header_template
}
\r\n
"
,
chunk
,
"Didn't received header template"
)
EventMachine
.
stop
}
fail_if_connecttion_error
(
sub_2
)
}
fail_if_connecttion_error
(
sub_1
)
}
fail_if_connecttion_error
(
pub
)
}
end
def
config_test_broadcast_channel_max_qtd
@test_config_file
=
"test_broadcast_channel_max_qtd.conf"
@authorized_channels_only
=
"on"
@header_template
=
"connected"
@broadcast_channel_prefix
=
"XXX_"
@broadcast_channel_max_qtd
=
2
end
def
test_broadcast_channel_max_qtd
channel
=
'ch2'
channel_broad1
=
'XXX_123'
channel_broad2
=
'XXX_321'
channel_broad3
=
'XXX_213'
headers
=
{
'accept'
=>
'text/html'
}
body
=
'broadcast channel prefix'
EventMachine
.
run
{
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
pub
.
callback
{
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'/'
+
channel_broad1
+
'/'
+
channel_broad2
+
'/'
+
channel_broad3
).
get
:head
=>
headers
,
:timeout
=>
60
sub_1
.
stream
{
|
chunk
|
assert_equal
(
403
,
sub_1
.
response_header
.
status
,
"Subscriber was not forbidden"
)
sub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'/'
+
channel_broad1
+
'/'
+
channel_broad2
).
get
:head
=>
headers
,
:timeout
=>
60
sub_2
.
stream
{
|
chunk
|
EventMachine
.
stop
}
fail_if_connecttion_error
(
sub_2
)
}
fail_if_connecttion_error
(
sub_1
)
}
fail_if_connecttion_error
(
pub
)
}
end
end
test/test_comunication_properties.rb
0 → 100644
View file @
f8675232
require
'rubygems'
require
'em-http'
require
'test/unit'
require
File
.
expand_path
(
'base_test_case'
,
File
.
dirname
(
__FILE__
))
class
TestComunicationProperties
<
Test
::
Unit
::
TestCase
include
BaseTestCase
def
config_test_all_authorized
@test_config_file
=
"test_all_authorized.conf"
@authorized_channels_only
=
"off"
@header_template
=
"connected"
end
def
test_all_authorized
channel
=
'ch1'
headers
=
{
'accept'
=>
'text/html'
}
EventMachine
.
run
{
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
60
sub
.
stream
{
|
chunk
|
assert_equal
(
"
#{
@header_template
}
\r\n
"
,
chunk
,
"Didn't received header template"
)
EventMachine
.
stop
}
fail_if_connecttion_error
(
sub
)
}
end
def
config_test_only_authorized
@test_config_file
=
"test_only_authorized.conf"
@authorized_channels_only
=
"on"
@header_template
=
"connected"
end
def
test_only_authorized
channel
=
'ch2'
headers
=
{
'accept'
=>
'text/html'
}
body
=
'message to create a channel'
EventMachine
.
run
{
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
60
sub_1
.
callback
{
|
chunk
|
assert_equal
(
403
,
sub_1
.
response_header
.
status
,
"Subscriber was not forbidden"
)
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
pub
.
callback
{
sub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
60
sub_2
.
stream
{
|
chunk
|
assert_equal
(
"
#{
@header_template
}
\r\n
"
,
chunk
,
"Didn't received header template"
)
EventMachine
.
stop
}
fail_if_connecttion_error
(
sub_2
)
}
fail_if_connecttion_error
(
pub
)
}
fail_if_connecttion_error
(
sub_1
)
}
end
def
config_test_message_buffer_timeout
@test_config_file
=
"test_message_buffer_timeout.conf"
@authorized_channels_only
=
"off"
@header_template
=
"connected"
@message_template
=
"~text~"
@min_message_buffer_timeout
=
"12s"
end
def
test_message_buffer_timeout
channel
=
'ch3'
headers
=
{
'accept'
=>
'text/html'
}
body
=
'message to test buffer timeout '
EventMachine
.
run
{
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
fail_if_connecttion_error
(
pub
)
EM
.
add_timer
(
2
)
do
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'.b1'
).
get
:head
=>
headers
,
:timeout
=>
60
sub_1
.
stream
{
|
chunk
|
assert_equal
(
"
#{
@header_template
}
\r\n
#{
body
}
\r\n
"
,
chunk
,
"Didn't received header and message"
)
sub_1
.
close_connection
}
fail_if_connecttion_error
(
sub_1
)
end
EM
.
add_timer
(
6
)
do
sub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'.b1'
).
get
:head
=>
headers
,
:timeout
=>
60
sub_2
.
stream
{
|
chunk
|
assert_equal
(
"
#{
@header_template
}
\r\n
#{
body
}
\r\n
"
,
chunk
,
"Didn't received header and message"
)
sub_2
.
close_connection
}
fail_if_connecttion_error
(
sub_2
)
end
EM
.
add_timer
(
13
)
do
sub_3
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'.b1'
).
get
:head
=>
headers
,
:timeout
=>
60
sub_3
.
stream
{
|
chunk
|
assert_equal
(
"
#{
@header_template
}
\r\n
"
,
chunk
,
"Didn't received header"
)
sub_3
.
close_connection
EventMachine
.
stop
}
fail_if_connecttion_error
(
sub_3
)
end
}
end
def
config_test_message_template
@test_config_file
=
"test_message_template.conf"
@authorized_channels_only
=
"off"
@header_template
=
"header"
@message_template
=
'{\"duplicated\":\"~channel~\", \"channel\":\"~channel~\", \"message\":\"~text~\", \"message_id\":\"~id~\"}'
@ping_message_interval
=
"1s"
end
def
test_message_template
channel
=
'ch4'
headers
=
{
'accept'
=>
'text/html'
}
body
=
'message to create a channel'
EventMachine
.
run
{
chunksReceived
=
0
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'.b1'
).
get
:head
=>
headers
,
:timeout
=>
60
sub
.
stream
{
|
chunk
|
chunksReceived
+=
1
if
chunksReceived
==
1
assert_equal
(
"
#{
@header_template
}
\r\n
"
,
chunk
,
"Didn't received header template"
)
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
fail_if_connecttion_error
(
pub
)
end
if
chunksReceived
==
2
assert_equal
(
"{
\"
duplicated
\"
:
\"
ch4
\"
,
\"
channel
\"
:
\"
#{
channel
}
\"
,
\"
message
\"
:
\"
#{
body
}
\"
,
\"
message_id
\"
:
\"
1
\"
}
\r\n
"
,
chunk
,
"Didn't received message formatted:
#{
chunk
}
"
)
end
if
chunksReceived
==
3
assert_equal
(
"{
\"
duplicated
\"
:
\"\"
,
\"
channel
\"
:
\"\"
,
\"
message
\"
:
\"\"
,
\"
message_id
\"
:
\"
-1
\"
}
\r\n
"
,
chunk
,
"Didn't received ping message:
#{
chunk
}
"
)
EventMachine
.
stop
end
}
fail_if_connecttion_error
(
sub
)
}
end
end
test/test_create_many_channels.rb
View file @
f8675232
...
@@ -28,9 +28,7 @@ class TestCreateManyChannels < Test::Unit::TestCase
...
@@ -28,9 +28,7 @@ class TestCreateManyChannels < Test::Unit::TestCase
pub
.
callback
{
pub
.
callback
{
channels_callback
+=
1
channels_callback
+=
1
}
}
pub
.
errback
{
|
error
|
fail_if_connecttion_error
(
pub
)
fail
(
"Erro inexperado na execucao do teste:
#{
error
.
last_effective_url
.
nil?
?
""
:
error
.
last_effective_url
.
request_uri
}
#{
error
.
response
}
"
)
}
else
else
EventMachine
.
stop
EventMachine
.
stop
end
end
...
...
test/test_publish_messages.rb
View file @
f8675232
...
@@ -25,14 +25,10 @@ class TestPublishMessages < Test::Unit::TestCase
...
@@ -25,14 +25,10 @@ class TestPublishMessages < Test::Unit::TestCase
assert_equal
(
body
+
"
\r\n
"
,
chunk
,
"The published message was not received correctly"
)
assert_equal
(
body
+
"
\r\n
"
,
chunk
,
"The published message was not received correctly"
)
EventMachine
.
stop
EventMachine
.
stop
}
}
sub
.
errback
{
|
error
|
fail_if_connecttion_error
(
sub
)
fail
(
"Erro inexperado na execucao do teste:
#{
error
.
last_effective_url
.
nil?
?
""
:
error
.
last_effective_url
.
request_uri
}
#{
error
.
response
}
"
)
}
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
pub
.
errback
{
|
error
|
fail_if_connecttion_error
(
pub
)
fail
(
"Erro inexperado na execucao do teste:
#{
error
.
last_effective_url
.
nil?
?
""
:
error
.
last_effective_url
.
request_uri
}
#{
error
.
response
}
"
)
}
}
}
end
end
...
@@ -59,18 +55,14 @@ class TestPublishMessages < Test::Unit::TestCase
...
@@ -59,18 +55,14 @@ class TestPublishMessages < Test::Unit::TestCase
sub
.
callback
{
sub
.
callback
{
assert_equal
(
messagens_to_publish
,
recieved_messages
,
"The published messages was not received correctly"
)
assert_equal
(
messagens_to_publish
,
recieved_messages
,
"The published messages was not received correctly"
)
}
}
sub
.
errback
{
|
error
|
fail_if_connecttion_error
(
sub
)
fail
(
"Erro inexperado na execucao do teste:
#{
error
.
last_effective_url
.
nil?
?
""
:
error
.
last_effective_url
.
request_uri
}
#{
error
.
response
}
"
)
}
i
=
0
i
=
0
EM
.
add_periodic_timer
(
0.05
)
do
EM
.
add_periodic_timer
(
0.05
)
do
i
+=
1
i
+=
1
if
i
<=
messagens_to_publish
if
i
<=
messagens_to_publish
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body_prefix
+
i
.
to_s
,
:timeout
=>
30
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body_prefix
+
i
.
to_s
,
:timeout
=>
30
pub
.
errback
{
|
error
|
fail_if_connecttion_error
(
pub
)
fail
(
"Erro inexperado na execucao do teste:
#{
error
.
last_effective_url
.
nil?
?
""
:
error
.
last_effective_url
.
request_uri
}
#{
error
.
response
}
"
)
}
end
end
end
end
}
}
...
...
test/test_publisher_properties.rb
0 → 100644
View file @
f8675232
require
'rubygems'
require
'popen4'
require
'em-http'
require
'test/unit'
require
'json'
require
File
.
expand_path
(
'base_test_case'
,
File
.
dirname
(
__FILE__
))
class
TestPublisherProperties
<
Test
::
Unit
::
TestCase
include
BaseTestCase
def
initialize
(
opts
)
super
(
opts
)
@header_template
=
""
@message_template
=
"~text~"
end
def
config_test_stored_messages
@test_config_file
=
"test_store_messages.conf"
@store_messages
=
"on"
end
def
test_stored_messages
headers
=
{
'accept'
=>
'application/json'
}
body
=
'published message'
channel
=
'ch1'
EventMachine
.
run
{
pub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
pub_1
.
callback
{
response
=
JSON
.
parse
(
pub_1
.
response
)
assert_equal
(
1
,
response
[
"stored_messages"
].
to_i
,
"Not stored messages"
)
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
pub_2
.
callback
{
response
=
JSON
.
parse
(
pub_2
.
response
)
assert_equal
(
2
,
response
[
"stored_messages"
].
to_i
,
"Not stored messages"
)
EventMachine
.
stop
}
fail_if_connecttion_error
(
pub_2
)
}
fail_if_connecttion_error
(
pub_1
)
}
end
def
config_test_not_stored_messages
@test_config_file
=
"test_not_store_messages.conf"
@store_messages
=
"off"
end
def
test_not_stored_messages
headers
=
{
'accept'
=>
'application/json'
}
body
=
'published message'
channel
=
'ch2'
EventMachine
.
run
{
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
pub
.
callback
{
response
=
JSON
.
parse
(
pub
.
response
)
assert_equal
(
0
,
response
[
"stored_messages"
].
to_i
,
"Stored messages"
)
EventMachine
.
stop
}
fail_if_connecttion_error
(
pub
)
}
end
def
config_test_max_stored_messages
@test_config_file
=
"test_max_stored_messages.conf"
@store_messages
=
"on"
@max_message_buffer_length
=
4
end
def
test_max_stored_messages
headers
=
{
'accept'
=>
'application/json'
}
body_prefix
=
'published message '
channel
=
'ch3'
messagens_to_publish
=
10
EventMachine
.
run
{
i
=
0
EM
.
add_periodic_timer
(
0.05
)
do
i
+=
1
if
i
<=
messagens_to_publish
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body_prefix
+
i
.
to_s
,
:timeout
=>
30
pub
.
callback
{
response
=
JSON
.
parse
(
pub
.
response
)
assert
(
response
[
"stored_messages"
].
to_i
<=
@max_message_buffer_length
,
"Stored more messages then configured"
)
}
fail_if_connecttion_error
(
pub
)
else
EventMachine
.
stop
end
end
}
end
def
config_test_max_channel_id_length
@test_config_file
=
"test_max_channel_id_length.conf"
@max_channel_id_length
=
5
end
def
test_max_channel_id_length
headers
=
{
'accept'
=>
'application/json'
}
body
=
'published message'
channel
=
'123456'
EventMachine
.
run
{
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
,
:timeout
=>
30
pub
.
callback
{
response
=
JSON
.
parse
(
pub
.
response
)
assert_equal
(
"12345"
,
response
[
"channel"
],
"No crop the channel id"
)
EventMachine
.
stop
}
fail_if_connecttion_error
(
pub
)
}
end
end
test/test_setup_parameters.rb
View file @
f8675232
require
'rubygems'
#
require 'rubygems'
require
'popen4'
#
require 'popen4'
require
'test/unit'
#
require 'test/unit'
require
File
.
expand_path
(
'base_test_case'
,
File
.
dirname
(
__FILE__
))
#
require File.expand_path('base_test_case', File.dirname(__FILE__))
#
class
TestSetuParameters
<
Test
::
Unit
::
TestCase
#
class TestSetuParameters < Test::Unit::TestCase
include
BaseTestCase
#
include BaseTestCase
#
def
test_min_buffer_messages_greater_them_max_buffer_messages
#
def test_min_buffer_messages_greater_them_max_buffer_messages
expected_error_message
=
"push_stream_max_message_buffer_length cannot be smaller than push_stream_min_message_buffer_length"
#
expected_error_message = "push_stream_max_message_buffer_length cannot be smaller than push_stream_min_message_buffer_length"
@test_config_file
=
"test_min_buffer_messages_greater_them_max_buffer_messages.conf"
#
@test_config_file = "test_min_buffer_messages_greater_them_max_buffer_messages.conf"
@max_message_buffer_length
=
20
#
@max_message_buffer_length = 20
@min_message_buffer_length
=
21
#
@min_message_buffer_length = 21
#
self
.
create_config_file
#
self.create_config_file
stderr_msg
=
self
.
start_server
#
stderr_msg = self.start_server
assert
(
stderr_msg
.
include?
(
expected_error_message
),
"Message error not founded: '
#{
expected_error_message
}
' recieved
#{
stderr_msg
}
"
)
# assert(stderr_msg.include?(expected_error_message), "Message error not founded: '#{ expected_error_message }' recieved '#{ stderr_msg }'
")
end
#
end
#
end
#
end
test/test_subscriber_connection_cleanup.rb
View file @
f8675232
...
@@ -6,34 +6,61 @@ require File.expand_path('base_test_case', File.dirname(__FILE__))
...
@@ -6,34 +6,61 @@ require File.expand_path('base_test_case', File.dirname(__FILE__))
class
TestSubscriberConnectionCleanup
<
Test
::
Unit
::
TestCase
class
TestSubscriberConnectionCleanup
<
Test
::
Unit
::
TestCase
include
BaseTestCase
include
BaseTestCase
def
initialize
(
opts
)
def
config_test_subscriber_connection_timeout
super
(
opts
)
@test_config_file
=
"test_subscriber_connection_timeout.conf"
@test_config_file
=
"test_subscriber_connection_cleanup.conf"
@subscriber_connection_timeout
=
"37s"
@subscriber_connection_timeout
=
"37s"
@subscriber_disconnect_interval
=
"1s"
@header_template
=
"HEADER_TEMPLATE"
@header_template
=
"HEADER_TEMPLATE"
@ping_message_interval
=
"0s"
@ping_message_interval
=
"0s"
end
end
def
test_subscriber_connection_
cleanup
def
test_subscriber_connection_
timeout
channel
=
'ch1'
channel
=
'ch1'
headers
=
{
'accept'
=>
'text/html'
}
headers
=
{
'accept'
=>
'text/html'
}
start
=
Time
.
now
start
=
Time
.
now
receivedHeaderTemplate
=
false
receivedHeaderTemplate
=
false
EventMachine
.
run
{
EventMachine
.
run
{
http
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
60
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
60
http
.
stream
{
|
chunk
|
sub
.
stream
{
|
chunk
|
assert
(
chunk
.
include?
(
@header_template
),
"Didn't received header template"
)
assert
(
chunk
.
include?
(
@header_template
),
"Didn't received header template"
)
}
}
http
.
callback
{
sub
.
callback
{
stop
=
Time
.
now
stop
=
Time
.
now
elapsed
=
time_diff_sec
(
start
,
stop
)
elapsed
=
time_diff_sec
(
start
,
stop
)
assert
(
elapsed
>=
37
&&
elapsed
<=
38.5
,
"Disconnect was in
#{
elapsed
}
seconds"
)
assert
(
elapsed
>=
37
&&
elapsed
<=
38.5
,
"Disconnect was in
#{
elapsed
}
seconds"
)
EventMachine
.
stop
EventMachine
.
stop
}
}
http
.
errback
{
|
error
|
fail_if_connecttion_error
(
sub
)
fail
(
"Erro inexperado na execucao do teste:
#{
error
.
last_effective_url
.
nil?
?
""
:
error
.
last_effective_url
.
request_uri
}
#{
error
.
response
}
"
)
}
}
end
def
config_test_subscriber_disconnect_interval
@test_config_file
=
"test_subscriber_disconnect_interval.conf"
@subscriber_connection_timeout
=
"37s"
@ping_message_interval
=
"5s"
@subscriber_disconnect_interval
=
"5s"
end
def
test_subscriber_disconnect_interval
channel
=
'ch2'
headers
=
{
'accept'
=>
'text/html'
}
start
=
Time
.
now
chuncksReceived
=
0
EventMachine
.
run
{
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
60
sub
.
stream
{
|
chunk
|
chuncksReceived
+=
1
;
}
sub
.
callback
{
stop
=
Time
.
now
elapsed
=
time_diff_sec
(
start
,
stop
)
assert
(
elapsed
>=
40
&&
elapsed
<=
40.5
,
"Disconnect was in
#{
elapsed
}
seconds"
)
assert_equal
(
9
,
chuncksReceived
,
"Received
#{
chuncksReceived
}
chuncks"
)
EventMachine
.
stop
}
fail_if_connecttion_error
(
sub
)
}
}
end
end
end
end
test/test_subscriber_properties.rb
0 → 100644
View file @
f8675232
require
'rubygems'
require
'em-http'
require
'test/unit'
require
File
.
expand_path
(
'base_test_case'
,
File
.
dirname
(
__FILE__
))
class
TestSubscriberProperties
<
Test
::
Unit
::
TestCase
include
BaseTestCase
def
config_test_header_template
@test_config_file
=
"test_header_template.conf"
@header_template
=
"HEADER
\r\n
TEMPLATE
\r\n
1234
\r\n
"
@authorized_channels_only
=
"off"
end
def
test_header_template
channel
=
'ch1'
headers
=
{
'accept'
=>
'text/html'
}
EventMachine
.
run
{
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
60
sub
.
stream
{
|
chunk
|
assert_equal
(
"
#{
@header_template
}
\r\n
"
,
chunk
,
"Didn't received header template"
)
EventMachine
.
stop
}
fail_if_connecttion_error
(
sub
)
}
end
def
config_test_content_type
@test_config_file
=
"test_content_type.conf"
@content_type
=
"custom content type"
@authorized_channels_only
=
"off"
end
def
test_content_type
channel
=
'ch2'
headers
=
{
'accept'
=>
'text/html'
}
EventMachine
.
run
{
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
60
sub
.
stream
{
|
chunk
|
assert_equal
(
@content_type
,
sub
.
response_header
[
'CONTENT_TYPE'
],
"Didn't received correct content type"
)
EventMachine
.
stop
}
fail_if_connecttion_error
(
sub
)
}
end
def
config_test_ping_message_interval
@test_config_file
=
"test_ping_message_interval.conf"
@subscriber_connection_timeout
=
"0s"
@ping_message_interval
=
"2s"
end
def
test_ping_message_interval
channel
=
'ch3'
headers
=
{
'accept'
=>
'text/html'
}
step1
=
step2
=
step3
=
step4
=
nil
chuncksReceived
=
0
EventMachine
.
run
{
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
60
sub
.
stream
{
|
chunk
|
chuncksReceived
+=
1
;
step1
=
Time
.
now
if
chuncksReceived
==
1
step2
=
Time
.
now
if
chuncksReceived
==
2
step3
=
Time
.
now
if
chuncksReceived
==
3
step4
=
Time
.
now
if
chuncksReceived
==
4
if
chuncksReceived
==
4
EventMachine
.
stop
end
}
sub
.
callback
{
interval1
=
time_diff_sec
(
step2
,
step1
).
round
interval2
=
time_diff_sec
(
step4
,
step3
).
round
assert_equal
(
interval1
,
interval2
,
"Wrong
#{
interval1
}
,
#{
interval2
}
intervals"
)
}
fail_if_connecttion_error
(
sub
)
}
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment