Skip to content

Commit

Permalink
Warning cleanups for rake test
Browse files Browse the repository at this point in the history
Library changes;
 * add parentheses for ambiguous syntax
 * use Kernel.warn instead of STDERR.puts

Updated tests as well to suppress warnings while running.
  • Loading branch information
Hiroshi Nakamura committed Aug 7, 2011
1 parent eeb7f12 commit 918a901
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 46 deletions.
6 changes: 3 additions & 3 deletions lib/em/completion.rb
Expand Up @@ -248,7 +248,7 @@ def completion_states
def timeout(time, *args)
cancel_timeout
@timeout_timer = EM::Timer.new(time) do
fail *args unless completed?
fail(*args) unless completed?
end
end

Expand Down Expand Up @@ -287,7 +287,7 @@ def execute_callbacks
# Iterate all callbacks for a given state, and remove then call them.
def execute_state_callbacks(state)
while callback = @callbacks[state].shift
callback.call *value
callback.call(*value)
end
end

Expand All @@ -300,4 +300,4 @@ def clear_dead_callbacks
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/em/protocols/httpclient.rb
Expand Up @@ -64,7 +64,7 @@ class HttpClient < Connection
MaxPostContentLength = 20 * 1024 * 1024

def initialize
STDERR.puts "HttpClient is deprecated and will be removed. EM-Http-Request should be used instead."
warn "HttpClient is deprecated and will be removed. EM-Http-Request should be used instead."
end

# @param args [Hash] The request arguments
Expand Down Expand Up @@ -276,4 +276,4 @@ def unbind
end

end
end
end
2 changes: 1 addition & 1 deletion lib/em/protocols/httpclient2.rb
Expand Up @@ -44,7 +44,7 @@ class HttpClient2 < Connection
include LineText2

def initialize
STDERR.puts "HttpClient2 is deprecated and will be removed. EM-Http-Request should be used instead."
warn "HttpClient2 is deprecated and will be removed. EM-Http-Request should be used instead."

@authorization = nil
@closed = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/em/protocols/smtpserver.rb
Expand Up @@ -357,7 +357,7 @@ def process_auth str

def process_auth_line(line)
plain = line.unpack("m").first
discard,user,psw = plain.split("\000")
_,user,psw = plain.split("\000")
if receive_plain_auth user,psw
send_data "235 authentication ok\r\n"
@state << :auth
Expand Down
2 changes: 1 addition & 1 deletion lib/em/pure_ruby.rb
Expand Up @@ -448,7 +448,7 @@ def initialize io
s = Socket.for_fd(@io.fileno)
s.fcntl( Fcntl::F_SETFL, Fcntl::O_NONBLOCK )
rescue Errno::EINVAL, Errno::EBADF
STDERR.puts "Serious error: unable to set descriptor non-blocking"
warn "Serious error: unable to set descriptor non-blocking"
end
end
# TODO, should set CLOEXEC on Unix?
Expand Down
13 changes: 11 additions & 2 deletions tests/em_test_helper.rb
Expand Up @@ -3,7 +3,7 @@
require 'rbconfig'
require 'socket'

Test::Unit::TestCase.class_eval do
class Test::Unit::TestCase
class EMTestTimeout < StandardError ; end

def setup_timeout(timeout = TIMEOUT_INTERVAL)
Expand Down Expand Up @@ -38,7 +38,7 @@ def exception_class
module PlatformHelper
# http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-platform-in-ruby/
def windows?
Config::CONFIG['host_os'] =~ /mswin|mingw/
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
end

# http://stackoverflow.com/questions/1342535/how-can-i-tell-if-im-running-from-jruby-vs-ruby/1685970#1685970
Expand All @@ -52,4 +52,13 @@ def jruby?

# Tests run significantly slower on windows. YMMV
TIMEOUT_INTERVAL = windows? ? 1 : 0.25

def silent
backup, $VERBOSE = $VERBOSE, nil
begin
yield
ensure
$VERBOSE = backup
end
end
end
4 changes: 2 additions & 2 deletions tests/test_completion.rb
Expand Up @@ -158,7 +158,7 @@ def test_timeout
args = [1, 2, 3]
EM.run do
completion.timeout(0.0001, *args)
completion.errback { |*args| results << args }
completion.errback { |*errargs| results << errargs }
completion.completion { EM.stop }
EM.add_timer(0.1) { flunk 'test timed out' }
end
Expand All @@ -174,4 +174,4 @@ def test_timeout_gets_cancelled
end
assert_equal [], results
end
end
end
4 changes: 2 additions & 2 deletions tests/test_epoll.rb
Expand Up @@ -49,7 +49,7 @@ def test_rlimit
# XXX this test causes all sort of weird issues on OSX (when run as part of the suite)
def _test_descriptors
EM.epoll
s = EM.set_descriptor_table_size 60000
EM.set_descriptor_table_size 60000
EM.run {
EM.start_server "127.0.0.1", 9800, TestEchoServer
$n = 0
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_datagrams
def _test_unix_domain
fn = "/tmp/xxx.chain"
EM.epoll
s = EM.set_descriptor_table_size 60000
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.
Expand Down
18 changes: 9 additions & 9 deletions tests/test_httpclient.rb
Expand Up @@ -16,7 +16,7 @@ def teardown
def test_http_client
ok = false
EM.run {
c = EM::P::HttpClient.send :request, :host => "www.google.com", :port => 80
c = silent { EM::P::HttpClient.send :request, :host => "www.google.com", :port => 80 }
c.callback {
ok = true
EM.stop
Expand All @@ -31,7 +31,7 @@ def test_http_client
def test_http_client_1
ok = false
EM.run {
c = EM::P::HttpClient.send :request, :host => "www.google.com", :port => 80
c = silent { EM::P::HttpClient.send :request, :host => "www.google.com", :port => 80 }
c.callback {ok = true; EM.stop}
c.errback {EM.stop}
}
Expand All @@ -43,7 +43,7 @@ def test_http_client_1
def test_http_client_2
ok = false
EM.run {
c = EM::P::HttpClient.send :request, :host => "www.google.com", :port => 80
c = silent { EM::P::HttpClient.send :request, :host => "www.google.com", :port => 80 }
c.callback {|result|
ok = true;
EM.stop
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_http_empty_content
ok = false
EM.run {
EM.start_server "127.0.0.1", 9701, EmptyContent
c = EM::P::HttpClient.send :request, :host => "127.0.0.1", :port => 9701
c = silent { EM::P::HttpClient.send :request, :host => "127.0.0.1", :port => 9701 }
c.callback {|result|
ok = true
EM.stop
Expand Down Expand Up @@ -134,14 +134,14 @@ def test_post
EM.run {
EM.start_server Localhost, Localport, PostContent
setup_timeout(2)
c = EM::P::HttpClient.request(
c = silent { EM::P::HttpClient.request(
:host=>Localhost,
:port=>Localport,
:method=>:post,
:request=>"/aaa",
:content=>"XYZ",
:content_type=>"text/plain"
)
)}
c.callback {|r|
response = r
EM.stop
Expand All @@ -158,7 +158,7 @@ def test_post
def test_cookie
ok = false
EM.run {
c = EM::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80, :cookie=>"aaa=bbb"
c = silent { EM::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80, :cookie=>"aaa=bbb" }
c.callback {|result|
ok = true;
EM.stop
Expand All @@ -173,11 +173,11 @@ def test_cookie
def test_version_1_0
ok = false
EM.run {
c = EM::P::HttpClient.request(
c = silent { EM::P::HttpClient.request(
:host => "www.google.com",
:port => 80,
:version => "1.0"
)
)}
c.callback {|result|
ok = true;
EM.stop
Expand Down
20 changes: 11 additions & 9 deletions tests/test_httpclient2.rb
Expand Up @@ -22,8 +22,10 @@ class TestServer < EM::Connection
def test_connect
EM.run {
EM.start_server Localhost, Localport, TestServer
http1 = EM::P::HttpClient2.connect Localhost, Localport
http2 = EM::P::HttpClient2.connect( :host=>Localhost, :port=>Localport )
silent do
EM::P::HttpClient2.connect Localhost, Localport
EM::P::HttpClient2.connect( :host=>Localhost, :port=>Localport )
end
EM.stop
}
end
Expand All @@ -33,7 +35,7 @@ def test_bad_port
EM.run {
EM.start_server Localhost, Localport, TestServer
assert_raises( ArgumentError ) {
EM::P::HttpClient2.connect Localhost, "xxx"
silent { EM::P::HttpClient2.connect Localhost, "xxx" }
}
EM.stop
}
Expand All @@ -42,7 +44,7 @@ def test_bad_port
def test_bad_server
err = nil
EM.run {
http = EM::P::HttpClient2.connect Localhost, 9999
http = silent { EM::P::HttpClient2.connect Localhost, 9999 }
d = http.get "/"
d.errback { err = true; d.internal_error; EM.stop }
}
Expand All @@ -52,7 +54,7 @@ def test_bad_server
def test_get
content = nil
EM.run {
http = EM::P::HttpClient2.connect "google.com", 80
http = silent { EM::P::HttpClient2.connect "google.com", 80 }
d = http.get "/"
d.callback {
content = d.content
Expand All @@ -68,7 +70,7 @@ def test_get
def _test_get_multiple
content = nil
EM.run {
http = EM::P::HttpClient2.connect "google.com", 80
http = silent { EM::P::HttpClient2.connect "google.com", 80 }
d = http.get "/"
d.callback {
e = http.get "/"
Expand All @@ -84,7 +86,7 @@ def _test_get_multiple
def test_get_pipeline
headers, headers2 = nil, nil
EM.run {
http = EM::P::HttpClient2.connect "google.com", 80
http = silent { EM::P::HttpClient2.connect "google.com", 80 }
d = http.get("/")
d.callback {
headers = d.headers
Expand All @@ -104,7 +106,7 @@ def test_get_pipeline
def test_authheader
EM.run {
EM.start_server Localhost, Localport, TestServer
http = EM::P::HttpClient2.connect Localhost, 18842
http = silent { EM::P::HttpClient2.connect Localhost, 18842 }
d = http.get :url=>"/", :authorization=>"Basic xxx"
d.callback {EM.stop}
d.errback {EM.stop}
Expand All @@ -114,7 +116,7 @@ def test_authheader
def test_https_get
d = nil
EM.run {
http = EM::P::HttpClient2.connect :host => 'www.apple.com', :port => 443, :ssl => true
http = silent { EM::P::HttpClient2.connect :host => 'www.apple.com', :port => 443, :ssl => true }
d = http.get "/"
d.callback {
EM.stop
Expand Down
12 changes: 2 additions & 10 deletions tests/test_ltp.rb
Expand Up @@ -87,12 +87,8 @@ def receive_binary_data text

def test_lines_and_text
output = ''
lines_received = []
text_received = []
EM.run {
EM.start_server( "127.0.0.1", @port, LineAndTextTest ) do |conn|
conn.instance_eval "@lines = lines_received; @text = text_received"
end
EM.start_server( "127.0.0.1", @port, LineAndTextTest )
setup_timeout

EM.connect "127.0.0.1", @port, StopClient do |c|
Expand Down Expand Up @@ -125,12 +121,8 @@ def receive_binary_data text

def test_binary_text
output = ''
lines_received = []
text_received = []
EM.run {
EM.start_server( "127.0.0.1", @port, BinaryTextTest ) do |conn|
conn.instance_eval "@lines = lines_received; @text = text_received"
end
EM.start_server( "127.0.0.1", @port, BinaryTextTest )
setup_timeout

EM.connect "127.0.0.1", @port, StopClient do |c|
Expand Down
4 changes: 2 additions & 2 deletions tests/test_processes.rb
Expand Up @@ -78,15 +78,15 @@ def test_em_system_with_two_procs

def test_em_system_cmd_arguments
EM.run{
EM.system('sh', '--version', proc{ |process|
EM.system('echo', '1', '2', 'version', proc{ |process|
}, proc{ |out,status|
$out = out
$status = status
EM.stop
})
}

assert_match(/version/i, $out)
assert_match(/1 2 version/i, $out)
end

def test_em_system_spaced_arguments
Expand Down
4 changes: 2 additions & 2 deletions tests/test_threaded_resource.rb
Expand Up @@ -42,12 +42,12 @@ def test_dispatch_threading
resource.dispatch do |o|
o[:dispatch_thread] = Thread.current
end
assert_not_equal Thread.current, object[:dispatch_thread]
assert_not_equal main, object[:dispatch_thread]
end

def test_shutdown
# This test should get improved sometime. The method returning thread is
# NOT an api that will be maintained.
assert !resource.shutdown.alive?
end
end
end

0 comments on commit 918a901

Please sign in to comment.