Skip to content

Commit

Permalink
add test for connecting to presence channel
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmarat committed Aug 30, 2011
1 parent 7e26555 commit 1ac36cf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
26 changes: 26 additions & 0 deletions spec/performance/connectin_performance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'
require 'performance_helper'
require 'benchmark'

describe 'Connecting Performance' do

it "For x listeners" do
[1, 10, 100].each do |count|
results = []
5.times do
@application = Socky::Server::Application.new('test_application', 'test_secret')
@channel = "presence"
results << Benchmark.realtime {count.times { add_listener }}
clean_application
end
print_result count, results
end
end

end






1 change: 1 addition & 0 deletions spec/performance/send_many_messages_performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[1, 10, 100].each do |count|
results = []
5.times do
@channel = "private"
@application = application_with_listeners(1)
results << Benchmark.realtime {send_messages(count)}
clean_application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[1, 10, 100].each do |count|
results = []
5.times do
@channel = "private"
@application = application_with_listeners(count)
results << Benchmark.realtime {send_messages(1)}
clean_application
Expand Down
7 changes: 4 additions & 3 deletions spec/performance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def add_listener
websocket = mock_websocket(@application.name)
env = { 'PATH_INFO' => '/websocket/' + @application.name }
websocket.on_open(env)
data = {'event' => 'socky:subscribe', 'channel' => 'private-channel', 'auth' => 'test_auth'}
data = {'event' => 'socky:subscribe', 'channel' => "#{@channel}-channel", 'auth' => 'test_auth'}
websocket.on_message(env, data)
websocket
end
Expand All @@ -28,20 +28,21 @@ def add_writer
@writer_ws = mock_websocket(@application.name)
env = { 'PATH_INFO' => '/websocket/' + @application.name }
@writer_ws.on_open(env)
data = {'event' => 'socky:subscribe', 'channel' => 'private-channel', 'write' => 'true', 'auth' => 'test_auth'}
data = {'event' => 'socky:subscribe', 'channel' => "#{@channel}-channel", 'write' => 'true', 'auth' => 'test_auth'}
@writer_ws.on_message(env, data)
@writer_ws
end

def send_messages count
env = { 'PATH_INFO' => '/websocket/' + @application.name }
data = {'event' => 'send', 'channel' => 'private-channel', 'user_data' => "test_message"}
data = {'event' => 'send', 'channel' => "#{@channel}-channel", 'user_data' => "test_message"}
count.times { @writer_ws.on_message(env, data) }
end

def clean_application
@application.connections.values.each {|c| c.destroy}
Socky::Server::Channel::Private.list['test_application'] = Hash.new
Socky::Server::Channel::Private.list['test_application'] = Hash.new
Socky::Server::Application.list.delete('test_application')
end

Expand Down

0 comments on commit 1ac36cf

Please sign in to comment.