Skip to content

Commit

Permalink
Merge pull request eventmachine#870 from MSP-Greg/fix-intermittent-tests
Browse files Browse the repository at this point in the history
Fix intermittent tests
  • Loading branch information
sodabrew authored Jan 18, 2019
2 parents 6505651 + 9cd39b6 commit f765aa7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
6 changes: 4 additions & 2 deletions tests/test_httpclient2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TestHttpClient2 < Test::Unit::TestCase
class TestServer < EM::Connection
end

TIMEOUT = (windows? ? 1.5 : 1)
TIMEOUT = (windows? ? 2.0 : 1)

def setup
@port = next_port
Expand Down Expand Up @@ -117,8 +117,10 @@ def test_authheader
def test_https_get
omit("No SSL") unless EM.ssl?
d = nil
# below is actually due to an issue with OpenSSL 1.0.2 and earlier with Windows
ci_windows_old = windows? and RUBY_VERSION < '2.5'
EM.run {
setup_timeout(windows? ? 6 : TIMEOUT)
setup_timeout(ci_windows_old ? 9 : TIMEOUT)
http = silent { EM::P::HttpClient2.connect :host => 'www.google.com', :port => 443, :tls => true }
d = http.get "/"
d.callback {EM.stop}
Expand Down
5 changes: 2 additions & 3 deletions tests/test_inactivity_timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ def test_for_real
c.comm_inactivity_timeout = 0.02
}
}
# busy Travis intermittently saw a bit over 0.09, but often the whole
# test only took a bit over 0.02
assert_in_delta(0.06, (finish - start), 0.04)
# Travis can vary from 0.02 to 0.17, Appveyor maybe as low as 0.01
assert_in_delta(0.09, (finish - start), 0.08)
end
else
warn "EM.comm_inactivity_timeout not implemented, skipping tests in #{__FILE__}"
Expand Down
10 changes: 7 additions & 3 deletions tests/test_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

class TestIterator < Test::Unit::TestCase

def setup
@time0 = nil
end

# By default, format the time with tenths-of-seconds.
# Some tests should ask for extra decimal places to ensure
# that delays between iterations will receive a changed time.
def get_time(n=1)
time = EM.current_time
time.strftime('%H:%M:%S.') + time.tv_usec.to_s[0, n]
def get_time(n = 1)
@time0 = EM.current_time unless @time0
sprintf "%07.#{n}f", EM.current_time - @time0
end

def test_default_concurrency
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 @@ -37,8 +37,8 @@ def test_for_real
c = EM.connect('192.0.2.0', 54321, timeout_handler)
c.pending_connect_timeout = 0.2
}

assert_in_delta(0.2, (finish - start), 0.1)
# Travis can vary from 0.10 to 0.40
assert_in_delta(0.25, (finish - start), 0.15)
end
else
warn "EM.pending_connect_timeout not implemented, skipping tests in #{__FILE__}"
Expand Down
28 changes: 25 additions & 3 deletions tests/test_resolver.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
require_relative 'em_test_helper'

class TestResolver < Test::Unit::TestCase

CI_WINDOWS = windows? and ENV['CI'].casecmp('true').zero?

def ci_windows_retries(err)
if CI_WINDOWS and err.is_a? String and err[/retries exceeded/]
EM.stop
notify 'Intermittent Appveyor DNS error: retries exceeded'
true
else
false
end
end

def test_nameserver
assert_kind_of(String, EM::DNS::Resolver.nameserver)
end
Expand All @@ -21,7 +34,10 @@ def test_a

EM.run {
d = EM::DNS::Resolver.resolve "example.com"
d.errback { assert false }
d.errback { |err|
return if ci_windows_retries err
assert false, "failed to resolve example.com: #{err}"
}
d.callback { |r|
assert r
EM.stop
Expand Down Expand Up @@ -51,7 +67,10 @@ def test_a_pair

EM.run {
d = EM::DNS::Resolver.resolve "yahoo.com"
d.errback { |err| assert false, "failed to resolve yahoo.com: #{err}" }
d.errback { |err|
return if ci_windows_retries err
assert false, "failed to resolve yahoo.com: #{err}"
}
d.callback { |r|
assert_kind_of(Array, r)
assert r.size > 1, "returned #{r.size} results: #{r.inspect}"
Expand Down Expand Up @@ -80,7 +99,10 @@ def test_timer_cleanup

EM.run {
d = EM::DNS::Resolver.resolve "example.com"
d.errback { |err| assert false, "failed to resolve example.com: #{err}" }
d.errback { |err|
return if ci_windows_retries err
assert false, "failed to resolve example.com: #{err}"
}
d.callback { |r|
# This isn't a great test, but it's hard to get more canonical
# confirmation that the timer is cancelled
Expand Down
9 changes: 7 additions & 2 deletions tests/test_threaded_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ def test_dispatch_completion
EM.run do
EM.add_timer(3) do
EM.stop
fail 'Resource dispatch timed out'
if ENV['CI'].casecmp('true').zero? and RUBY_PLATFORM[/darwin/]
notify "Intermittent Travis MacOS: Resource dispatch timed out"
return
else
assert false, 'Resource dispatch timed out'
end
end
completion = resource.dispatch do |o|
o[:foo] = :bar
Expand All @@ -31,7 +36,7 @@ def test_dispatch_completion
end
completion.errback do |error|
EM.stop
fail "Unexpected error: #{error.message}"
assert false, "Unexpected error: #{error.message}"
end
end
assert_equal :bar, object[:foo]
Expand Down

0 comments on commit f765aa7

Please sign in to comment.