Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Added tests for EM::Connection#get_peer_cert, EM::Connection#ssl_hand…
Browse files Browse the repository at this point in the history
…shake_completed, and EM.connection_count

Signed-off-by: Aman Gupta <aman@tmm1.net>
  • Loading branch information
jakedouglas authored and tmm1 committed Mar 5, 2009
1 parent 15bcb96 commit 711313e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_connection_count.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
$:.unshift "../lib"
require 'eventmachine'
require 'test/unit'

class TestConnectionCount < Test::Unit::TestCase

def test_idle_connection_count
EM.run {
$count = EM.connection_count
EM.stop_event_loop
}

assert_equal(0, $count)
end

def test_with_some_connections
EM.run {
EM.start_server("127.0.0.1", 9999)
EM.connect("127.0.0.1", 9999)
$first_tick = EM.connection_count
EM.next_tick {
$second_tick = EM.connection_count
EM.next_tick {
$third_tick = EM.connection_count
EM.stop_event_loop
}
}
}

assert_equal(0, $first_tick)
assert_equal(2, $second_tick)
assert_equal(3, $third_tick)
end

end
50 changes: 50 additions & 0 deletions tests/test_ssl_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
$:.unshift "../lib"
require 'eventmachine'
require 'test/unit'

class TestSSLMethods < Test::Unit::TestCase

module ServerHandler

def post_init
start_tls
end

def ssl_handshake_completed
$server_called_back = true
$server_cert_value = get_peer_cert
end

end

module ClientHandler

def post_init
start_tls
end

def ssl_handshake_completed
$client_called_back = true
$client_cert_value = get_peer_cert
EM.stop_event_loop
end

end

def test_ssl_methods
$server_called_back, $client_called_back = false, false
$server_cert_value, $client_cert_value = nil, nil

EM.run {
EM.start_server("127.0.0.1", 9999, ServerHandler)
EM.connect("127.0.0.1", 9999, ClientHandler)
}

assert($server_called_back)
assert($client_called_back)

assert($server_cert_value.is_a?(NilClass))
assert($client_cert_value.is_a?(String))
end

end

0 comments on commit 711313e

Please sign in to comment.