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
cbfa6b69
Commit
cbfa6b69
authored
Oct 05, 2013
by
Wandenberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make cleanup test more stable and faster using a socket to publish messages
parent
c5abed57
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
176 additions
and
253 deletions
+176
-253
cleanup_memory_spec.rb
misc/spec/mix/cleanup_memory_spec.rb
+163
-244
spec_helper.rb
misc/spec/spec_helper.rb
+13
-9
No files found.
misc/spec/mix/cleanup_memory_spec.rb
View file @
cbfa6b69
...
...
@@ -30,10 +30,8 @@ describe "Cleanup Memory" do
# ensure channel will not be cleaned up
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status
,
content
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status
,
content
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -53,10 +51,7 @@ describe "Cleanup Memory" do
# connect a subscriber on new worker
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status2
,
content2
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status2
,
content2
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -65,10 +60,7 @@ describe "Cleanup Memory" do
fail
(
"Don't publish more messages"
)
if
published_messages_setp_1
==
published_messages_setp_2
wait_until_trash_is_empty
(
start
,
expected_time_for_clear
,
{
:check_stored_messages
=>
true
})
do
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status3
,
content3
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status3
,
content3
|
pub_4
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_4
.
callback
do
pub_4
.
should
be_http_status
(
200
).
with_body
...
...
@@ -79,21 +71,15 @@ describe "Cleanup Memory" do
EventMachine
.
stop
end
end
})
end
end
end
end
})
end
end
end
end
end
})
end
end
end
end
it
"should discard old messages"
,
:cleanup
=>
true
do
...
...
@@ -137,8 +123,8 @@ describe "Cleanup Memory" do
end
end
it
"should cleanup message memory without max messages stored per channel
XXX
"
,
:cleanup
=>
true
do
channel
=
'ch_test_message_cleanup_without_max_messages_stored_per_chann'
it
"should cleanup message memory without max messages stored per channel"
,
:cleanup
=>
true
do
channel
=
'ch_test_message_cleanup_without_max_messages_stored_per_chann
el
'
body
=
'message to create a channel'
expected_time_for_clear
=
25
...
...
@@ -151,10 +137,7 @@ describe "Cleanup Memory" do
# ensure channel will not be cleaned up
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status
,
content
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status
,
content
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -170,10 +153,7 @@ describe "Cleanup Memory" do
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
wait_until_trash_is_empty
(
start
,
expected_time_for_clear
,
{
:check_stored_messages
=>
true
})
do
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status2
,
content2
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status2
,
content2
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats?id='
+
channel
.
to_s
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -182,10 +162,7 @@ describe "Cleanup Memory" do
fail
(
"Don't publish more messages"
)
if
published_messages_setp_1
==
published_messages_setp_2
wait_until_trash_is_empty
(
start
,
expected_time_for_clear
,
{
:check_stored_messages
=>
true
})
do
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status3
,
content3
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status3
,
content3
|
pub_4
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats?id='
+
channel
.
to_s
).
get
:head
=>
headers
pub_4
.
callback
do
pub_4
.
should
be_http_status
(
200
).
with_body
...
...
@@ -195,25 +172,19 @@ describe "Cleanup Memory" do
EventMachine
.
stop
end
end
})
end
end
end
end
})
end
end
end
end
end
})
end
end
end
end
it
"should cleanup memory used for create channels"
,
:cleanup
=>
true
do
channel
=
'ch_test_channel_cleanup_'
channel
=
'ch_test_channel_cleanup_
%d
'
body
=
'message to create a channel'
nginx_run_server
(
config
.
merge
(
:message_ttl
=>
'2s'
),
:timeout
=>
test_timeout
)
do
|
conf
|
...
...
@@ -223,11 +194,7 @@ describe "Cleanup Memory" do
expected_time_for_clear
=
45
EventMachine
.
run
do
i
=
0
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
+
i
.
to_s
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status
,
content
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status
,
content
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -237,11 +204,7 @@ describe "Cleanup Memory" do
execute_changes_on_environment
(
conf
)
do
wait_until_trash_is_empty
(
start
,
expected_time_for_clear
,
{
:check_stored_messages
=>
true
,
:check_channels
=>
true
})
do
j
=
0
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
+
j
.
to_s
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status2
,
content2
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status2
,
content2
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -249,11 +212,7 @@ describe "Cleanup Memory" do
fail
(
"Don't create more channel"
)
if
published_messages_setp_1
==
JSON
.
parse
(
pub_2
.
response
)[
"published_messages"
].
to_i
wait_until_trash_is_empty
(
start
,
expected_time_for_clear
,
{
:check_stored_messages
=>
true
,
:check_channels
=>
true
})
do
i
=
0
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
+
i
.
to_s
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status3
,
content3
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status3
,
content3
|
pub_4
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_4
.
callback
do
pub_4
.
should
be_http_status
(
200
).
with_body
...
...
@@ -263,22 +222,13 @@ describe "Cleanup Memory" do
EventMachine
.
stop
end
end
})
i
+=
1
end
end
end
end
})
j
+=
1
end
end
end
end
end
})
i
+=
1
end
end
end
end
...
...
@@ -296,10 +246,7 @@ describe "Cleanup Memory" do
# ensure channel will not be cleaned up
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status
,
content
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status
,
content
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats?id='
+
channel
.
to_s
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -312,10 +259,8 @@ describe "Cleanup Memory" do
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
wait_until_trash_is_empty
(
start
,
expected_time_for_clear
,
{
:check_stored_messages
=>
true
})
do
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status2
,
content2
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status2
,
content2
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats?id='
+
channel
.
to_s
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -324,10 +269,8 @@ describe "Cleanup Memory" do
published_messages_setp_2
.
should_not
eql
(
published_messages_setp_1
)
wait_until_trash_is_empty
(
start
,
expected_time_for_clear
,
{
:check_stored_messages
=>
true
})
do
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status3
,
content3
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status3
,
content3
|
pub_4
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats?id='
+
channel
.
to_s
).
get
:head
=>
headers
pub_4
.
callback
do
pub_4
.
should
be_http_status
(
200
).
with_body
...
...
@@ -336,25 +279,19 @@ describe "Cleanup Memory" do
EventMachine
.
stop
end
end
})
end
end
end
end
})
end
end
end
end
end
})
end
end
end
end
it
"should cleanup memory used for publish messages with store 'off' and without subscriber"
,
:cleanup
=>
true
do
channel
=
'ch_test_message_cleanup_with_store_off_without_subscriber'
channel
=
'ch_test_message_cleanup_with_store_off_without_subscriber
%d
'
body
=
'message to create a channel'
expected_time_for_clear
=
45
...
...
@@ -363,11 +300,8 @@ describe "Cleanup Memory" do
published_messages_setp_2
=
0
EventMachine
.
run
do
i
=
0
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
+
i
.
to_s
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status
,
content
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status
,
content
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -377,11 +311,7 @@ describe "Cleanup Memory" do
execute_changes_on_environment
(
conf
)
do
wait_until_trash_is_empty
(
start
,
expected_time_for_clear
,
{
:check_stored_messages
=>
true
,
:check_channels
=>
true
})
do
j
=
0
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
+
j
.
to_s
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status2
,
content2
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status2
,
content2
|
start
=
Time
.
now
pub_2
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_2
.
callback
do
...
...
@@ -390,10 +320,7 @@ describe "Cleanup Memory" do
fail
(
"Don't create more channel"
)
if
published_messages_setp_1
==
published_messages_setp_2
wait_until_trash_is_empty
(
start
,
expected_time_for_clear
,
{
:check_stored_messages
=>
true
,
:check_channels
=>
true
})
do
fill_memory_timer
=
EventMachine
::
PeriodicTimer
.
new
(
0.001
)
do
publish_message_inline_with_callbacks
(
channel
+
i
.
to_s
,
headers
,
body
,
{
:error
=>
Proc
.
new
do
|
status3
,
content3
|
fill_memory_timer
.
cancel
publish_messages_until_fill_the_memory
(
channel
,
body
)
do
|
status3
,
content3
|
pub_4
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats'
).
get
:head
=>
headers
pub_4
.
callback
do
pub_4
.
should
be_http_status
(
200
).
with_body
...
...
@@ -402,23 +329,14 @@ describe "Cleanup Memory" do
EventMachine
.
stop
end
end
})
i
+=
1
end
end
end
end
})
j
+=
1
end
end
end
end
end
})
i
+=
1
end
end
end
end
...
...
@@ -569,7 +487,8 @@ describe "Cleanup Memory" do
:daemon
=>
'on'
,
:shared_memory_size
=>
"129k"
,
:message_ttl
=>
'10s'
,
:max_messages_stored_per_channel
=>
nil
:max_messages_stored_per_channel
=>
nil
,
:keepalive_requests
=>
200
}
end
...
...
misc/spec/spec_helper.rb
View file @
cbfa6b69
...
...
@@ -61,14 +61,18 @@ def create_channel_by_subscribe(channel, headers, timeout=60, &block)
end
end
def
publish_message_inline_with_callbacks
(
channel
,
headers
,
body
,
callbacks
=
{})
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
post
:head
=>
headers
,
:body
=>
body
pub
.
callback
do
if
pub
.
response_header
.
status
==
200
callbacks
[
:success
].
call
(
pub
.
response_header
.
status
,
pub
.
response
)
unless
callbacks
[
:success
].
nil?
else
callbacks
[
:error
].
call
(
pub
.
response_header
.
status
,
pub
.
response
)
unless
callbacks
[
:error
].
nil?
end
def
publish_messages_until_fill_the_memory
(
channel
,
body
,
&
block
)
i
=
0
resp_headers
,
resp_body
=
nil
socket
=
open_socket
(
nginx_host
,
nginx_port
)
while
(
true
)
do
socket
.
print
(
"POST /pub?id=
#{
channel
.
to_s
%
(
i
)
}
HTTP/1.1
\r\n
Host: localhost
\r\n
Content-Length:
#{
body
.
size
}
\r\n\r\n
#{
body
}
"
)
resp_headers
,
resp_body
=
read_response_on_socket
(
socket
,
{
:wait_for
=>
"}
\r\n
"
})
break
unless
resp_headers
.
match
(
/200 OK/
)
i
+=
1
end
pub
socket
.
close
status
=
resp_headers
.
match
(
/HTTP[^ ]* ([^ ]*)/
)[
1
]
block
.
call
(
status
,
resp_body
)
unless
block
.
nil?
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