net-empty_port 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -27,6 +27,19 @@ Or install it yourself as:
27
27
 
28
28
  Net::EmptyPort.wait(port, 3)
29
29
 
30
+ ## Thanks
31
+
32
+ This module is originally in a perl module [`Test::TCP`](https://github.com/tokuhirom/Test-TCP) written by tokuhirom. Thanks a lot.
33
+
34
+ ## See also
35
+
36
+ ### [glint](https://github.com/kentaro/glint)
37
+ This module is similar, but only for starting a server process.
38
+
39
+ ## TODO
40
+
41
+ - more test
42
+
30
43
  ## Contributing
31
44
 
32
45
  1. Fork it
@@ -59,7 +59,9 @@ module Net
59
59
  end
60
60
 
61
61
  def udp_used?(port)
62
- UDPSocket.new().bind('127.0.0.1', port)
62
+ s = UDPSocket.new()
63
+ s.bind('127.0.0.1', port)
64
+ s.close
63
65
  false
64
66
  rescue Errno::EADDRINUSE, Errno::EACCES
65
67
  true
@@ -1,5 +1,5 @@
1
1
  module Net
2
2
  module EmptyPort
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -4,7 +4,7 @@ describe Net::EmptyPort do
4
4
  it { should be_a String }
5
5
  end
6
6
 
7
- describe "empty_port" do
7
+ describe "empty_port TCP" do
8
8
  context "random" do
9
9
  let!(:port) { Net::EmptyPort.empty_port }
10
10
  it "is between 49152 and 65535" do
@@ -14,9 +14,20 @@ describe Net::EmptyPort do
14
14
  end
15
15
  end
16
16
 
17
- describe "wait" do
17
+ describe "empty_port UDP" do
18
+ context "random" do
19
+ let!(:port) { Net::EmptyPort.empty_port(0, :udp) }
20
+ it "is between 49152 and 65535" do
21
+ expect(port).to be >= 49152
22
+ expect(port).to be <= 65535
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "wait TCP" do
18
28
  let!(:port) { Net::EmptyPort.empty_port }
19
29
  it "wait until the empty_port is ready" do
30
+ expect(Net::EmptyPort.used?(port)).to be(false)
20
31
  s = TCPServer.new('127.0.0.1', port)
21
32
  expect(Net::EmptyPort.wait(port, 2)).to be(true)
22
33
  s.close
@@ -26,4 +37,19 @@ describe Net::EmptyPort do
26
37
  expect(Net::EmptyPort.wait(port, 0.1)).to be(false)
27
38
  end
28
39
  end
40
+
41
+ describe "wait UDP" do
42
+ let!(:port) { Net::EmptyPort.empty_port(0, :udp) }
43
+ it "wait until the empty_port is ready" do
44
+ expect(Net::EmptyPort.used?(port, :udp)).to be(false)
45
+ s = UDPSocket.new
46
+ s.bind('127.0.0.1', port)
47
+ expect(Net::EmptyPort.wait(port, 2, :udp)).to be(true)
48
+ s.close
49
+ end
50
+
51
+ it "fails because port is not read while the max_wait" do
52
+ expect(Net::EmptyPort.wait(port, 0.1, :udp)).to be(false)
53
+ end
54
+ end
29
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-empty_port
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-13 00:00:00.000000000 Z
12
+ date: 2013-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -105,3 +105,4 @@ summary: This module can find, check and wait an empty TCP/UDP port.
105
105
  test_files:
106
106
  - spec/net/empty_port_spec.rb
107
107
  - spec/spec_helper.rb
108
+ has_rdoc: