This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
forked from eventmachine/eventmachine
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for EM::Connection#get_peer_cert, EM::Connection#ssl_hand…
…shake_completed, and EM.connection_count Signed-off-by: Aman Gupta <aman@tmm1.net>
- Loading branch information
1 parent
15bcb96
commit 711313e
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |