random-port 0.8.0 → 0.8.1
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +6 -4
- data/README.md +1 -2
- data/Rakefile +14 -1
- data/lib/random-port/module.rb +2 -0
- data/lib/random-port/pool.rb +8 -9
- data/random-port.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2c6250d7a7a9a68ca737b299b7cef6b4816e35a6fe9452b78633c2df1132bd41
|
|
4
|
+
data.tar.gz: 9ec96d9ae9ce5e2f58c4bd3821f24877cfbc7a88913005d21a32c90d8f465b77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da1f7e7b9daeaf7a60fd935cbc8b0c578a352c558683a85f7c6d66c4a7ef391586a02b389107516c270d2a38215979aa8f4f6cdba5b70f7f128515cc21058a8c
|
|
7
|
+
data.tar.gz: bf6db1f8503993e5388b4cb48909f2684a0618eb26e4f5bc5677fe92b248c67a22e11f9ad8e9f5405223718d7f7287dc51ea50ffe47def18b6b8561ea3dab582
|
data/Gemfile
CHANGED
|
@@ -9,6 +9,7 @@ gemspec
|
|
|
9
9
|
gem 'minitest', '~>6.0', require: false
|
|
10
10
|
gem 'minitest-mock', '~>5.27', require: false
|
|
11
11
|
gem 'minitest-reporters', '~>1.7', require: false
|
|
12
|
+
gem 'os', '~> 1.1', require: false
|
|
12
13
|
gem 'qbash', '~>0.2', require: false
|
|
13
14
|
gem 'rake', '~>13.2', require: false
|
|
14
15
|
gem 'rubocop', '~>1.75', require: false
|
data/Gemfile.lock
CHANGED
|
@@ -13,15 +13,15 @@ GEM
|
|
|
13
13
|
builder (3.3.0)
|
|
14
14
|
concurrent-ruby (1.3.6)
|
|
15
15
|
docile (1.4.1)
|
|
16
|
-
elapsed (0.
|
|
16
|
+
elapsed (0.3.1)
|
|
17
17
|
loog (~> 0.6)
|
|
18
18
|
tago (~> 0.1)
|
|
19
19
|
ellipsized (0.3.0)
|
|
20
|
-
json (2.18.
|
|
20
|
+
json (2.18.1)
|
|
21
21
|
language_server-protocol (3.17.0.5)
|
|
22
22
|
lint_roller (1.1.0)
|
|
23
23
|
logger (1.7.0)
|
|
24
|
-
loog (0.
|
|
24
|
+
loog (0.8.0)
|
|
25
25
|
ellipsized
|
|
26
26
|
logger (~> 1.0)
|
|
27
27
|
minitest (6.0.1)
|
|
@@ -32,11 +32,12 @@ GEM
|
|
|
32
32
|
builder
|
|
33
33
|
minitest (>= 5.0)
|
|
34
34
|
ruby-progressbar
|
|
35
|
+
os (1.1.4)
|
|
35
36
|
parallel (1.27.0)
|
|
36
37
|
parser (3.3.10.1)
|
|
37
38
|
ast (~> 2.4.1)
|
|
38
39
|
racc
|
|
39
|
-
prism (1.
|
|
40
|
+
prism (1.9.0)
|
|
40
41
|
qbash (0.7.2)
|
|
41
42
|
backtrace (> 0)
|
|
42
43
|
elapsed (> 0)
|
|
@@ -105,6 +106,7 @@ DEPENDENCIES
|
|
|
105
106
|
minitest (~> 6.0)
|
|
106
107
|
minitest-mock (~> 5.27)
|
|
107
108
|
minitest-reporters (~> 1.7)
|
|
109
|
+
os (~> 1.1)
|
|
108
110
|
qbash (~> 0.2)
|
|
109
111
|
rake (~> 13.2)
|
|
110
112
|
random-port!
|
data/README.md
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
[](https://github.com/yegor256/random-port/actions/workflows/rake.yml)
|
|
7
7
|
[](https://badge.fury.io/rb/random-port)
|
|
8
|
-
[](https://codeclimate.com/github/yegor256/random-port/maintainability)
|
|
9
8
|
[](https://rubydoc.info/github/yegor256/random-port/master/frames)
|
|
10
9
|
[](https://github.com/yegor256/random-port/blob/master/LICENSE.txt)
|
|
11
10
|
[](https://codecov.io/github/yegor256/random-port?branch=master)
|
|
@@ -71,7 +70,7 @@ Read
|
|
|
71
70
|
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
|
72
71
|
Make sure your build is green before you contribute
|
|
73
72
|
your pull request. You will need to have
|
|
74
|
-
[Ruby](https://www.ruby-lang.org/en/)
|
|
73
|
+
[Ruby](https://www.ruby-lang.org/en/) 3.3+ and
|
|
75
74
|
[Bundler](https://bundler.io/) installed. Then:
|
|
76
75
|
|
|
77
76
|
```bash
|
data/Rakefile
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2018-2026 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
+
require 'os'
|
|
7
|
+
require 'qbash'
|
|
6
8
|
require 'rubygems'
|
|
7
9
|
require 'rake'
|
|
8
10
|
require 'rake/clean'
|
|
11
|
+
require 'shellwords'
|
|
9
12
|
|
|
10
13
|
CLEAN << 'coverage'
|
|
11
14
|
|
|
@@ -17,7 +20,7 @@ def version
|
|
|
17
20
|
Gem::Specification.load(Dir['*.gemspec'].first).version
|
|
18
21
|
end
|
|
19
22
|
|
|
20
|
-
task default: %i[clean test yard rubocop]
|
|
23
|
+
task default: %i[clean test picks yard rubocop]
|
|
21
24
|
|
|
22
25
|
require 'rake/testtask'
|
|
23
26
|
desc 'Run all unit tests'
|
|
@@ -27,6 +30,16 @@ Rake::TestTask.new(:test) do |test|
|
|
|
27
30
|
test.verbose = false
|
|
28
31
|
end
|
|
29
32
|
|
|
33
|
+
desc 'Run them via Ruby, one by one'
|
|
34
|
+
task :picks do
|
|
35
|
+
next if OS.windows?
|
|
36
|
+
%w[test lib].each do |d|
|
|
37
|
+
Dir["#{d}/**/*.rb"].each do |f|
|
|
38
|
+
qbash("bundle exec ruby #{Shellwords.escape(f)}", stdout: $stdout, env: { 'PICKS' => 'yes' })
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
30
43
|
require 'rubocop/rake_task'
|
|
31
44
|
desc 'Run RuboCop on all directories'
|
|
32
45
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
data/lib/random-port/module.rb
CHANGED
data/lib/random-port/pool.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2018-2026 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
+
require 'minitest/mock'
|
|
6
7
|
require 'monitor'
|
|
7
8
|
require 'socket'
|
|
8
9
|
require 'tago'
|
|
@@ -134,7 +135,7 @@ class RandomPort::Pool
|
|
|
134
135
|
end
|
|
135
136
|
return nil if opts.any? { |p| @ports.include?(p) }
|
|
136
137
|
d = total * (total - 1) / 2
|
|
137
|
-
return nil unless opts.
|
|
138
|
+
return nil unless opts.sum - (total * opts.min) == d
|
|
138
139
|
@ports += opts
|
|
139
140
|
opts
|
|
140
141
|
end
|
|
@@ -150,21 +151,19 @@ class RandomPort::Pool
|
|
|
150
151
|
# @raise [SocketError] If there's a socket-related error
|
|
151
152
|
def take(port)
|
|
152
153
|
['127.0.0.1', '::1', '0.0.0.0', 'localhost'].each do |host|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
next
|
|
157
|
-
end
|
|
154
|
+
TCPServer.new(host, port).close
|
|
155
|
+
rescue Errno::EADDRNOTAVAIL
|
|
156
|
+
next
|
|
158
157
|
end
|
|
159
158
|
port
|
|
160
159
|
end
|
|
161
160
|
|
|
162
161
|
# Executes a block of code with or without thread synchronization.
|
|
163
|
-
# @
|
|
162
|
+
# @yield The block of code to execute
|
|
164
163
|
# @return The result of the block execution
|
|
165
|
-
def safe(&
|
|
164
|
+
def safe(&)
|
|
166
165
|
if @sync
|
|
167
|
-
@monitor.synchronize(&
|
|
166
|
+
@monitor.synchronize(&)
|
|
168
167
|
else
|
|
169
168
|
yield
|
|
170
169
|
end
|
data/random-port.gemspec
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
require 'English'
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
|
9
|
-
s.required_ruby_version = '>=
|
|
9
|
+
s.required_ruby_version = '>=3.3'
|
|
10
10
|
s.name = 'random-port'
|
|
11
|
-
s.version = '0.8.
|
|
11
|
+
s.version = '0.8.1'
|
|
12
12
|
s.license = 'MIT'
|
|
13
13
|
s.summary = 'Random TCP port'
|
|
14
14
|
s.description = 'Reserves a random TCP port'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: random-port
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
@@ -54,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
54
54
|
requirements:
|
|
55
55
|
- - ">="
|
|
56
56
|
- !ruby/object:Gem::Version
|
|
57
|
-
version: '
|
|
57
|
+
version: '3.3'
|
|
58
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
|
60
60
|
- - ">="
|