Skip to content

Commit

Permalink
Tighten timeouts and so on for faster tests, 90s - 25s
Browse files Browse the repository at this point in the history
  • Loading branch information
raggi committed Feb 4, 2010
1 parent 1fd5584 commit 3008ae6
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 30 deletions.
2 changes: 1 addition & 1 deletion tests/test_attach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def notify_readable
def unbind
EM.next_tick do
$sock.write("def\n")
EM.add_timer(0.5){ EM.stop }
EM.add_timer(0.1){ EM.stop }
end
end
end
Expand Down
11 changes: 10 additions & 1 deletion tests/test_basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ def post_init
end
end

def setup_timeout(timeout = 4)
EM.schedule {
start_time = EM.current_time
EM.add_periodic_timer(0.01) {
raise "timeout" if EM.current_time - start_time >= timeout
}
}
end

# From ticket #50
def test_byte_range_send
$received = ''
Expand All @@ -160,7 +169,7 @@ def test_byte_range_send
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!" }
setup_timeout
}
assert_equal($sent, $received)
end
Expand Down
2 changes: 1 addition & 1 deletion tests/test_file_watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_events
File.open(file.path, 'w'){ |f| f.puts 'hi' }

# delete it
EM.add_timer(0.25){ file.close; file.delete }
EM.add_timer(0.01){ file.close; file.delete }
}

assert_equal($path, $tmp_path)
Expand Down
21 changes: 15 additions & 6 deletions tests/test_httpclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def teardown
def test_http_client
ok = false
EventMachine.run {
c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
c = EventMachine::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80
c.callback {
ok = true
EventMachine.stop
Expand All @@ -59,7 +59,7 @@ def test_http_client
def test_http_client_1
ok = false
EventMachine.run {
c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
c = EventMachine::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80
c.callback {ok = true; EventMachine.stop}
c.errback {EventMachine.stop}
}
Expand All @@ -71,7 +71,7 @@ def test_http_client_1
def test_http_client_2
ok = false
EventMachine.run {
c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80
c = EventMachine::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80
c.callback {|result|
ok = true;
EventMachine.stop
Expand Down Expand Up @@ -154,14 +154,23 @@ def send_response
close_connection_after_writing
end
end

def setup_timeout(timeout = 4)
EM.schedule {
start_time = EM.current_time
EM.add_periodic_timer(0.01) {
raise "timeout" if EM.current_time - start_time >= timeout
}
}
end

# TODO, this is WRONG. The handler is asserting an HTTP 1.1 request, but the client
# is sending a 1.0 request. Gotta fix the client
def test_post
response = nil
EventMachine.run {
EventMachine.start_server Localhost, Localport, PostContent
EventMachine.add_timer(2) {raise "timed out"}
setup_timeout(2)
c = EventMachine::Protocols::HttpClient.request(
:host=>Localhost,
:port=>Localport,
Expand All @@ -186,7 +195,7 @@ def test_post
def test_cookie
ok = false
EM.run {
c = EM::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80, :cookie=>"aaa=bbb"
c = EM::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80, :cookie=>"aaa=bbb"
c.callback {|result|
ok = true;
EventMachine.stop
Expand All @@ -202,7 +211,7 @@ def test_version_1_0
ok = false
EM.run {
c = EM::P::HttpClient.request(
:host => "www.bayshorenetworks.com",
:host => "www.google.com",
:port => 80,
:version => "1.0"
)
Expand Down
18 changes: 13 additions & 5 deletions tests/test_ltp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,23 @@ def unbind
EM.add_timer(0.1) { EM.stop }
end
end


def setup_timeout(timeout = 4)
EM.schedule {
start_time = EM.current_time
EM.add_periodic_timer(0.01) {
raise "timeout" if EM.current_time - start_time >= timeout
}
}
end

def test_simple_lines
lines_received = []
EventMachine.run {
EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
conn.instance_eval "@line_buffer = lines_received"
end
EventMachine.add_timer(4) {assert(false, "test timed out")}
setup_timeout

EventMachine.connect TestHost, TestPort, StopClient do |c|
c.send_data "aaa\nbbb\r\nccc\n"
Expand All @@ -87,7 +95,7 @@ def test_overlength_lines
EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
conn.instance_eval "@error_message = lines_received"
end
EventMachine.add_timer(4) {assert(false, "test timed out")}
setup_timeout

EventMachine.connect TestHost, TestPort, StopClient do |c|
c.send_data "a" * (16*1024 + 1)
Expand Down Expand Up @@ -126,7 +134,7 @@ def test_lines_and_text
EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn|
conn.instance_eval "@lines = lines_received; @text = text_received"
end
EventMachine.add_timer(4) {assert(false, "test timed out")}
setup_timeout

EventMachine.connect TestHost, TestPort, StopClient do |c|
c.set_receive_data { |data| output << data }
Expand Down Expand Up @@ -166,7 +174,7 @@ def test_binary_text
EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn|
conn.instance_eval "@lines = lines_received; @text = text_received"
end
EventMachine.add_timer(4) {assert(false, "test timed out")}
setup_timeout

EventMachine.connect TestHost, TestPort, StopClient do |c|
c.set_receive_data { |data| output << data }
Expand Down
2 changes: 1 addition & 1 deletion tests/test_next_tick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_run_run
def test_pre_run_queue
x = false
EM.next_tick { EM.stop; x = true }
EM.run { EM.add_timer(0.2) { EM.stop } }
EM.run { EM.add_timer(0.01) { EM.stop } }
assert x
end

Expand Down
4 changes: 2 additions & 2 deletions tests/test_pending_connect_timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def test_for_real
EM.heartbeat_interval = 0.1
$start = Time.now
c = EM.connect("1.2.3.4", 54321, TimeoutHandler)
c.pending_connect_timeout = 5
c.pending_connect_timeout = 0.2
}

assert_in_delta(5, (Time.now - $start), 0.3)
assert_in_delta(0.2, (Time.now - $start), 0.1)
end

end
2 changes: 1 addition & 1 deletion tests/test_process_watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_events
child = EM.watch_process($fork_pid, ChildProcessWatcher)
$pid = child.pid

EM.add_timer(0.5){
EM.add_timer(0.2){
Process.kill('TERM', $fork_pid)
}
}
Expand Down
11 changes: 10 additions & 1 deletion tests/test_pure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,19 @@ def test_connaccepted
EM.run {
EM.start_server "0.0.0.0", 60002
EM.connect "0.0.0.0", 60002, TestConnaccepted
EM::Timer.new(1) {timeout = true; EM.stop}
setup_timeout(1)
}
assert_equal( false, timeout )
end

def setup_timeout(timeout = 4)
EM.schedule {
start_time = EM.current_time
EM.add_periodic_timer(0.01) {
raise "timeout" if EM.current_time - start_time >= timeout
}
}
end

def test_reactor_running
a = false
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sasl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_sasl

c = EM.connect( Host, Port, SaslClient )
d = c.validate?( TestUser, TestPsw )
d.timeout 2
d.timeout 1
d.callback {
resp = true
EM.stop
Expand Down
23 changes: 16 additions & 7 deletions tests/test_send_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ def teardown
File.unlink( TestFilename ) if File.exist?( TestFilename )
end

def setup_timeout(timeout = 4)
EM.schedule {
start_time = EM.current_time
EM.add_periodic_timer(0.01) {
raise "timeout" if EM.current_time - start_time >= timeout
}
}
end

def test_send_file
File.open( TestFilename, "w" ) {|f|
f << ("A" * 5000)
Expand All @@ -72,7 +81,7 @@ def test_send_file

EM.run {
EM.start_server TestHost, TestPort, TestModule
EM.add_timer(2) {EM.stop} # avoid hanging in case of error
setup_timeout

EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
Expand All @@ -95,7 +104,7 @@ def test_send_large_file
assert_raises( ex_class ) {
EM.run {
EM.start_server TestHost, TestPort, TestModule
EM.add_timer(2) {EM.stop} # avoid hanging in case of error
setup_timeout
EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
Expand Down Expand Up @@ -131,7 +140,7 @@ def test_stream_file_data

EM.run {
EM.start_server TestHost, TestPort, StreamTestModule
EM.add_timer(2) {EM.stop} # avoid hanging in case of error
setup_timeout
EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
Expand All @@ -151,7 +160,7 @@ def test_stream_chunked_file_data

EM.run {
EM.start_server TestHost, TestPort, ChunkStreamTestModule
EM.add_timer(2) {EM.stop} # avoid hanging in case of error
setup_timeout
EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
Expand All @@ -175,7 +184,7 @@ def test_stream_bad_file
data = ''
EM.run {
EM.start_server TestHost, TestPort, BadFileTestModule
EM.add_timer(2) {EM.stop} # avoid hanging in case of error
setup_timeout
EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
Expand All @@ -198,7 +207,7 @@ def test_stream_large_file_data

EM.run {
EM.start_server TestHost, TestPort, StreamTestModule
EM.add_timer(2) {EM.stop} # avoid hanging in case of error
setup_timeout
EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
Expand All @@ -223,7 +232,7 @@ def test_stream_large_chunked_file_data

EM.run {
EM.start_server TestHost, TestPort, ChunkStreamTestModule
EM.add_timer(2) {EM.stop} # avoid hanging in case of error
setup_timeout
EM.connect TestHost, TestPort, TestClient do |c|
c.data_to { |d| data << d }
end
Expand Down
2 changes: 1 addition & 1 deletion tests/test_servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_test_stop_server
assert(grep_netstat(LocalTcpRexp).grep(%r(#{Port})).size >= 1, "Server didn't start")
EM.stop_server sig
# Give the server some time to shutdown.
EM.add_timer(0.1) {
EM.add_timer(0.2) {
assert(grep_netstat(LocalTcpRexp).grep(%r(#{Port})).empty?, "Servers didn't stop")
EM.stop
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_timers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def test_periodic_timer_cancel
def test_add_periodic_timer_cancel
x = 0
EventMachine.run {
pt = EM.add_periodic_timer(0.25) { x += 1 }
pt = EM.add_periodic_timer(0.1) { x += 1 }
EM.cancel_timer(pt)
EM.add_timer(0.5) { EM.stop }
EM.add_timer(0.2) { EM.stop }
}
assert( x == 0 )
end
Expand Down

0 comments on commit 3008ae6

Please sign in to comment.