net-empty_port 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/lib/net/empty_port.rb +3 -1
- data/lib/net/empty_port/version.rb +1 -1
- data/spec/net/empty_port_spec.rb +28 -2
- metadata +3 -2
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
|
data/lib/net/empty_port.rb
CHANGED
data/spec/net/empty_port_spec.rb
CHANGED
@@ -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 "
|
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.
|
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
|
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:
|