Skip to content
This repository has been archived by the owner on Feb 18, 2018. It is now read-only.

Fixed timeouts in Net::Ping::External #32

Merged
merged 2 commits into from Mar 27, 2014
Merged

Conversation

bcandrea
Copy link
Contributor

Using Timeout.timeout with Open3 is not an option with Ruby > 1.9.3
(see https://bugs.ruby-lang.org/issues/5487). Implemented a workaround
based on the code at https://gist.github.com/lpar/1032297

Using Timeout.timeout with Open3 is not an option with Ruby > 1.9.3
(see https://bugs.ruby-lang.org/issues/5487). Implemented a workaround
based on the code at https://gist.github.com/lpar/1032297
This update should trigger a Travis CI build on different Rubies.
@bcandrea
Copy link
Contributor Author

Yes, Travis looks reasonably happy. I also ran this simple test on my local Rubies (2.0.0, 2.1.0, 2.1.1 and JRuby 1.7.9):

#!/usr/bin/env ruby
# net-ping/test.rb
$LOAD_PATH.unshift 'lib'
require 'net/ping'
require 'benchmark'

p = Net::Ping::External.new '10.0.0.0'
p.timeout = 1
Benchmark.bm do |x|
  x.report { p.ping }
end

The results for JRuby are:

$ rbenv shell jruby-1.7.9 
$ ruby -v
jruby 1.7.9 (1.9.3p392) 2013-12-06 87b108a on OpenJDK 64-Bit Server VM 1.7.0_51-b00 [linux-amd64]
aleph@eve:~/projects/net-ping$ ./test_ping.rb 
       user     system      total        real
   0.830000   0.620000   1.450000 (  1.017000)

djberg96 added a commit that referenced this pull request Mar 27, 2014
Fixed timeouts in Net::Ping::External
@djberg96 djberg96 merged commit 61cd0a4 into djberg96:master Mar 27, 2014
@djberg96
Copy link
Owner

Hm, it seems Windows is very unhappy. This is why Travis CI really needs cross platform support. I'll see if I can fix it, but I may have to undo this.

@djberg96
Copy link
Owner

It looks like Windows doesn't like read_nonblock. Replacing it with a standard read worked. At least, the tests all passed.

@bcandrea
Copy link
Contributor Author

Sorry, my fault (I don't have access to a full-featured Windows test machine unfortunately). The select call on pipes is indeed unsupported on Windows. However, are you sure that the standard read does the job? I tried it quickly and it seems to wait until the ping subprocess exits... and additionally my Process.kill("TERM", pid) fails with Errno::EINVAL on Windows, so I had to switch to Process.kill("KILL", pid), which looks a bit more drastic.

Disclaimer: as I said, my win32 test platform is quite limited (MRI 2.0.0 only). I can spend some more time on this later maybe.

@djberg96
Copy link
Owner

I ran rake test:external and all tests passed with both mingw (32 and 64 bit versions) and a version built using Visual Studio.

@djberg96
Copy link
Owner

That's on Windows 7, btw. Are the tests failing for you?

@ianheggie
Copy link
Contributor

Pik might be of use for multiple ruby versions under windows. Now just need a os/x test machine ... ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants