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
e32e1d01
Commit
e32e1d01
authored
Oct 02, 2011
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
speedup some tests
parent
cf925122
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
60 deletions
+61
-60
base_test_case.rb
test/base_test_case.rb
+22
-0
test_channel_statistics.rb
test/test_channel_statistics.rb
+16
-24
test_create_many_channels.rb
test/test_create_many_channels.rb
+8
-12
test_keepalive.rb
test/test_keepalive.rb
+0
-12
test_publish_messages.rb
test/test_publish_messages.rb
+12
-9
test_send_signals.rb
test/test_send_signals.rb
+3
-3
No files found.
test/base_test_case.rb
View file @
e32e1d01
...
...
@@ -6,6 +6,7 @@ require 'ruby-debug'
require
'test/unit'
require
'em-http'
require
'json'
require
'socket'
module
BaseTestCase
def
setup
...
...
@@ -181,6 +182,12 @@ module BaseTestCase
pub
end
def
publish_message_in_socket
(
channel
,
body
,
socket
)
post_channel_message
=
"POST /pub?id=
#{
channel
}
HTTP/1.0
\r\n
Content-Length:
#{
body
.
size
}
\r\n\r\n
#{
body
}
"
socket
.
print
(
post_channel_message
)
read_response
(
socket
)
end
def
create_channel_by_subscribe
(
channel
,
headers
,
timeout
=
60
,
&
block
)
EventMachine
.
run
{
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
,
:timeout
=>
timeout
...
...
@@ -200,6 +207,21 @@ module BaseTestCase
end
end
def
open_socket
TCPSocket
.
open
(
nginx_host
,
nginx_port
)
end
def
read_response
(
socket
)
response
=
socket
.
readpartial
(
1
)
while
(
tmp
=
socket
.
read_nonblock
(
256
))
response
+=
tmp
end
ensure
fail
(
"Any response"
)
if
response
.
nil?
headers
,
body
=
response
.
split
(
"
\r\n\r\n
"
,
2
)
return
headers
,
body
end
@@config_template
=
%q{
pid <%= @pid_file %>;
error_log <%= @main_error_log %> debug;
...
...
test/test_channel_statistics.rb
View file @
e32e1d01
...
...
@@ -349,6 +349,7 @@ class TestChannelStatistics < Test::Unit::TestCase
def
config_test_get_detailed_channels_statistics_to_many_channels
@max_reserved_memory
=
'200m'
@keepalive
=
"on"
end
def
test_get_detailed_channels_statistics_to_many_channels
...
...
@@ -359,18 +360,13 @@ class TestChannelStatistics < Test::Unit::TestCase
#create channels
0
.
step
(
number_of_channels
-
1
,
10
)
do
|
i
|
EventMachine
.
run
{
publish_message_inline
(
"
#{
channel
}#{
i
+
1
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
2
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
3
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
4
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
5
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
6
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
7
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
8
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
9
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
10
}
"
,
headers
,
body
)
{
EventMachine
.
stop
}
}
socket
=
open_socket
1
.
upto
(
10
)
do
|
j
|
channel_name
=
"
#{
channel
}#{
i
+
j
}
"
headers
,
body
=
publish_message_in_socket
(
channel_name
,
body
,
socket
)
fail
(
"Don't create the channel"
)
unless
headers
.
include?
(
"HTTP/1.1 200 OK"
)
end
socket
.
close
end
EventMachine
.
run
{
...
...
@@ -510,6 +506,7 @@ class TestChannelStatistics < Test::Unit::TestCase
def
config_test_get_detailed_channels_statistics_to_many_channels_using_prefix
@max_reserved_memory
=
'200m'
@keepalive
=
"on"
end
def
test_get_detailed_channels_statistics_to_many_channels_using_prefix
...
...
@@ -520,18 +517,13 @@ class TestChannelStatistics < Test::Unit::TestCase
#create channels
0
.
step
(
number_of_channels
-
1
,
10
)
do
|
i
|
EventMachine
.
run
{
publish_message_inline
(
"
#{
channel
}#{
i
+
1
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
2
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
3
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
4
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
5
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
6
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
7
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
8
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
9
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
10
}
"
,
headers
,
body
)
{
EventMachine
.
stop
}
}
socket
=
open_socket
1
.
upto
(
10
)
do
|
j
|
channel_name
=
"
#{
channel
}#{
i
+
j
}
"
headers
,
body
=
publish_message_in_socket
(
channel_name
,
body
,
socket
)
fail
(
"Don't create the channel"
)
unless
headers
.
include?
(
"HTTP/1.1 200 OK"
)
end
socket
.
close
end
EventMachine
.
run
{
...
...
test/test_create_many_channels.rb
View file @
e32e1d01
...
...
@@ -5,6 +5,7 @@ class TestCreateManyChannels < Test::Unit::TestCase
def
config_test_create_many_channels
@max_reserved_memory
=
"256m"
@keepalive
=
"on"
end
def
test_create_many_channels
...
...
@@ -14,18 +15,13 @@ class TestCreateManyChannels < Test::Unit::TestCase
channel
=
'ch_test_create_many_channels_'
0
.
step
(
channels_to_be_created
-
1
,
10
)
do
|
i
|
EventMachine
.
run
{
publish_message_inline
(
"
#{
channel
}#{
i
+
1
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
2
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
3
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
4
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
5
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
6
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
7
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
8
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
9
}
"
,
headers
,
body
)
publish_message_inline
(
"
#{
channel
}#{
i
+
10
}
"
,
headers
,
body
)
{
EventMachine
.
stop
}
}
socket
=
open_socket
1
.
upto
(
10
)
do
|
j
|
channel_name
=
"
#{
channel
}#{
i
+
j
}
"
headers
,
body
=
publish_message_in_socket
(
channel_name
,
body
,
socket
)
fail
(
"Don't create the channel"
)
unless
headers
.
include?
(
"HTTP/1.1 200 OK"
)
end
socket
.
close
end
end
end
test/test_keepalive.rb
View file @
e32e1d01
require
File
.
expand_path
(
'base_test_case'
,
File
.
dirname
(
__FILE__
))
require
'socket'
class
TestKeepalive
<
Test
::
Unit
::
TestCase
include
BaseTestCase
...
...
@@ -38,15 +37,4 @@ class TestKeepalive < Test::Unit::TestCase
assert_equal
(
"{
\"
channel
\"
:
\"
#{
channel
}
\"
,
\"
published_messages
\"
:
\"
1
\"
,
\"
stored_messages
\"
:
\"
1
\"
,
\"
subscribers
\"
:
\"
0
\"
}
\r\n
"
,
body
,
"Wrong response"
)
end
def
read_response
(
socket
)
response
=
socket
.
readpartial
(
1
)
while
(
tmp
=
socket
.
read_nonblock
(
256
))
response
+=
tmp
end
ensure
fail
(
"Any response"
)
if
response
.
nil?
headers
,
body
=
response
.
split
(
"
\r\n\r\n
"
,
2
)
return
headers
,
body
end
end
test/test_publish_messages.rb
View file @
e32e1d01
...
...
@@ -69,6 +69,7 @@ class TestPublishMessages < Test::Unit::TestCase
@message_template
=
"~text~"
@max_reserved_memory
=
"256m"
@ping_message_interval
=
nil
@keepalive
=
"on"
end
def
test_publish_many_messages_in_the_same_channel
...
...
@@ -84,22 +85,24 @@ class TestPublishMessages < Test::Unit::TestCase
response
+=
chunk
recieved_messages
=
response
.
split
(
"
\r\n
"
)
if
recieved_messages
.
length
>
=
messagens_to_publish
if
recieved_messages
.
length
=
=
messagens_to_publish
assert_equal
(
body_prefix
+
messagens_to_publish
.
to_s
,
recieved_messages
.
last
,
"Didn't receive all messages"
)
EventMachine
.
stop
end
}
req
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
)
i
=
0
EM
.
add_periodic_timer
(
0.001
)
do
i
+=
1
if
i
<=
messagens_to_publish
pub
=
req
.
post
:head
=>
headers
,
:body
=>
body_prefix
+
i
.
to_s
,
:timeout
=>
30
pub
.
callback
{
fail
(
"Massage was not published: "
+
body_prefix
+
i
.
to_s
)
if
pub
.
response_header
.
status
!=
200
}
EM
.
add_timer
(
0.05
)
do
0
.
step
(
messagens_to_publish
-
1
,
10
)
do
|
i
|
socket
=
open_socket
1
.
upto
(
10
)
do
|
j
|
resp_headers
,
body
=
publish_message_in_socket
(
channel
,
body_prefix
+
(
i
+
j
).
to_s
,
socket
)
fail
(
"Message was not published: "
+
body_prefix
+
(
i
+
j
).
to_s
)
unless
resp_headers
.
include?
(
"HTTP/1.1 200 OK"
)
end
socket
.
close
end
end
add_test_timeout
}
end
...
...
test/test_send_signals.rb
View file @
e32e1d01
...
...
@@ -5,9 +5,9 @@ class TestSendSignals < Test::Unit::TestCase
def
config_test_send_hup_signal
ENV
[
'NGINX_WORKERS'
]
=
'1'
@memory_cleanup_timeout
=
'
2m
'
@min_message_buffer_timeout
=
'
2m
'
@subscriber_connection_timeout
=
'
2m
'
@memory_cleanup_timeout
=
'
40s
'
@min_message_buffer_timeout
=
'
60s
'
@subscriber_connection_timeout
=
'
65s
'
@master_process
=
'on'
@daemon
=
'on'
@header_template
=
'HEADER'
...
...
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