Skip to content

Commit

Permalink
Convert tabs to spaces in tests/test_*
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Apr 5, 2009
1 parent e40aa64 commit a8f3960
Show file tree
Hide file tree
Showing 24 changed files with 1,382 additions and 1,456 deletions.
2 changes: 0 additions & 2 deletions tests/test_basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ def test_byte_range_send
$received = ''
$sent = (0..255).to_a.pack('C*')
EM::run {

EM::start_server TestHost, TestPort, BrsTestSrv

EM::connect TestHost, TestPort, BrsTestCli

EM::add_timer(0.5) { assert(false, 'test timed out'); EM.stop; Kernel.warn "test timed out!" }
Expand Down
222 changes: 111 additions & 111 deletions tests/test_epoll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,60 +34,60 @@

class TestEpoll < Test::Unit::TestCase

module TestEchoServer
def receive_data data
send_data data
close_connection_after_writing
end
end

module TestEchoClient
def connection_completed
send_data "ABCDE"
$max += 1
end
def receive_data data
raise "bad response" unless data == "ABCDE"
end
def unbind
$n -= 1
EM.stop if $n == 0
end
end


# We can set the rlimit/nofile of a process but we can only set it
# higher if we're running as root.
# On most systems, the default value is 1024.
# Java doesn't (currently) implement this.
def test_rlimit
unless RUBY_PLATFORM =~ /java/ or EM.set_descriptor_table_size >= 1024
a = EM.set_descriptor_table_size
assert( a <= 1024 )
a = EM.set_descriptor_table_size( 1024 )
assert( a == 1024 )
end
end

# Run a high-volume version of this test by kicking the number of connections
# up past 512. (Each connection uses two sockets, a client and a server.)
# (Will require running the test as root)
# This test exercises TCP clients and servers.
#
def test_descriptors
EM.epoll
s = EM.set_descriptor_table_size 60000
EM.run {
EM.start_server "127.0.0.1", 9800, TestEchoServer
$n = 0
$max = 0
100.times {
EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1}
}
}
assert_equal(0, $n)
assert_equal(100, $max)
end
module TestEchoServer
def receive_data data
send_data data
close_connection_after_writing
end
end

module TestEchoClient
def connection_completed
send_data "ABCDE"
$max += 1
end
def receive_data data
raise "bad response" unless data == "ABCDE"
end
def unbind
$n -= 1
EM.stop if $n == 0
end
end


# We can set the rlimit/nofile of a process but we can only set it
# higher if we're running as root.
# On most systems, the default value is 1024.
# Java doesn't (currently) implement this.
def test_rlimit
unless RUBY_PLATFORM =~ /java/ or EM.set_descriptor_table_size >= 1024
a = EM.set_descriptor_table_size
assert( a <= 1024 )
a = EM.set_descriptor_table_size( 1024 )
assert( a == 1024 )
end
end

# Run a high-volume version of this test by kicking the number of connections
# up past 512. (Each connection uses two sockets, a client and a server.)
# (Will require running the test as root)
# This test exercises TCP clients and servers.
#
def test_descriptors
EM.epoll
s = EM.set_descriptor_table_size 60000
EM.run {
EM.start_server "127.0.0.1", 9800, TestEchoServer
$n = 0
$max = 0
100.times {
EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1}
}
}
assert_equal(0, $n)
assert_equal(100, $max)
end

def test_defer
n = 0
Expand All @@ -101,63 +101,63 @@ def test_defer
end unless RUBY_VERSION >= '1.9.0'


module TestDatagramServer
def receive_data dgm
$in = dgm
send_data "abcdefghij"
end
end
module TestDatagramClient
def post_init
send_datagram "1234567890", "127.0.0.1", 9500
end
def receive_data dgm
$out = dgm
EM.stop
end
end

def test_datagrams
$in = $out = ""
EM.epoll
EM.run {
EM.open_datagram_socket "127.0.0.1", 9500, TestDatagramServer
EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
}
assert_equal( "1234567890", $in )
assert_equal( "abcdefghij", $out )
end




def test_unix_domain
fn = "/tmp/xxx.chain"
EM.epoll
s = EM.set_descriptor_table_size 60000
EM.run {
# The pure-Ruby version won't let us open the socket if the node already exists.
# Not sure, that actually may be correct and the compiled version is wrong.
# Pure Ruby also oddly won't let us make that many connections. This test used
# to run 100 times. Not sure where that lower connection-limit is coming from in
# pure Ruby.
# Let's not sweat the Unix-ness of the filename, since this test can't possibly
# work on Windows anyway.
#
File.unlink(fn) if File.exist?(fn)
EM.start_unix_domain_server fn, TestEchoServer
$n = 0
$max = 0
50.times {
EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
}
EM::add_timer(1) { $stderr.puts("test_unix_domain timed out!"); EM::stop }
}
assert_equal(0, $n)
assert_equal(50, $max)
ensure
File.unlink(fn) if File.exist?(fn)
end
module TestDatagramServer
def receive_data dgm
$in = dgm
send_data "abcdefghij"
end
end
module TestDatagramClient
def post_init
send_datagram "1234567890", "127.0.0.1", 9500
end
def receive_data dgm
$out = dgm
EM.stop
end
end

def test_datagrams
$in = $out = ""
EM.epoll
EM.run {
EM.open_datagram_socket "127.0.0.1", 9500, TestDatagramServer
EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
}
assert_equal( "1234567890", $in )
assert_equal( "abcdefghij", $out )
end




def test_unix_domain
fn = "/tmp/xxx.chain"
EM.epoll
s = EM.set_descriptor_table_size 60000
EM.run {
# The pure-Ruby version won't let us open the socket if the node already exists.
# Not sure, that actually may be correct and the compiled version is wrong.
# Pure Ruby also oddly won't let us make that many connections. This test used
# to run 100 times. Not sure where that lower connection-limit is coming from in
# pure Ruby.
# Let's not sweat the Unix-ness of the filename, since this test can't possibly
# work on Windows anyway.
#
File.unlink(fn) if File.exist?(fn)
EM.start_unix_domain_server fn, TestEchoServer
$n = 0
$max = 0
50.times {
EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
}
EM::add_timer(1) { $stderr.puts("test_unix_domain timed out!"); EM::stop }
}
assert_equal(0, $n)
assert_equal(50, $max)
ensure
File.unlink(fn) if File.exist?(fn)
end

end

72 changes: 36 additions & 36 deletions tests/test_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,47 @@

class TestErrors < Test::Unit::TestCase

Localhost = "127.0.0.1"
Localport = 9801
Localhost = "127.0.0.1"
Localport = 9801

def setup
end
def setup
end

def obsolete_teardown
# Calling #set_runtime_error_hook with no block restores the
# default handling of runtime_errors.
#
EM.set_runtime_error_hook
end
def obsolete_teardown
# Calling #set_runtime_error_hook with no block restores the
# default handling of runtime_errors.
#
EM.set_runtime_error_hook
end

def test_no_tests_stub
end
def test_no_tests_stub
end

# EM has a default handler for RuntimeErrors that are emitted from
# user written code. You can override the handler if you wish, but it's
# easier to call #set_runtime_error_hook.
# Ordinarily, an error in user code invoked by the reactor aborts the
# run.
#
def obsolete_test_unhandled_error
assert_raises( RuntimeError ) {
EM.run {
EM.add_timer(0) {raise "AAA"}
}
}
# EM has a default handler for RuntimeErrors that are emitted from
# user written code. You can override the handler if you wish, but it's
# easier to call #set_runtime_error_hook.
# Ordinarily, an error in user code invoked by the reactor aborts the
# run.
#
def obsolete_test_unhandled_error
assert_raises( RuntimeError ) {
EM.run {
EM.add_timer(0) {raise "AAA"}
}
}

end
end

def obsolete_test_handled_error
err = nil
EM.run {
EM.set_runtime_error_hook {
err = true
EM.stop
}
EM.add_timer(0) {raise "AAA"}
}
assert err
end
def obsolete_test_handled_error
err = nil
EM.run {
EM.set_runtime_error_hook {
err = true
EM.stop
}
EM.add_timer(0) {raise "AAA"}
}
assert err
end
end

47 changes: 22 additions & 25 deletions tests/test_exc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,27 @@

class TestSomeExceptions < Test::Unit::TestCase


# Read the commentary in EventMachine#run.
# This test exercises the ensure block in #run that makes sure
# EventMachine#release_machine gets called even if an exception is
# thrown within the user code. Without the ensured call to release_machine,
# the second call to EventMachine#run will fail with a C++ exception
# because the machine wasn't cleaned up properly.

def test_a
assert_raises(RuntimeError) {
EventMachine.run {
raise "some exception"
}
}
end

def test_b
assert_raises(RuntimeError) {
EventMachine.run {
raise "some exception"
}
}
end

# Read the commentary in EventMachine#run.
# This test exercises the ensure block in #run that makes sure
# EventMachine#release_machine gets called even if an exception is
# thrown within the user code. Without the ensured call to release_machine,
# the second call to EventMachine#run will fail with a C++ exception
# because the machine wasn't cleaned up properly.

def test_a
assert_raises(RuntimeError) {
EventMachine.run {
raise "some exception"
}
}
end

def test_b
assert_raises(RuntimeError) {
EventMachine.run {
raise "some exception"
}
}
end

end

2 changes: 1 addition & 1 deletion tests/test_file_watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ def test_events
assert($deleted)
assert($unbind)
end
end
end
Loading

0 comments on commit a8f3960

Please sign in to comment.