random-port 0.7.4 → 0.7.6
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 +13 -26
- data/Gemfile.lock +104 -0
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +5 -5
- data/REUSE.toml +35 -0
- data/Rakefile +2 -20
- data/lib/random-port/module.rb +3 -22
- data/lib/random-port/pool.rb +25 -36
- data/lib/random-port.rb +2 -21
- data/random-port.gemspec +6 -25
- metadata +11 -26
- data/.0pdd.yml +0 -29
- data/.github/workflows/actionlint.yml +0 -41
- data/.github/workflows/codecov.yml +0 -38
- data/.github/workflows/copyrights.yml +0 -34
- data/.github/workflows/markdown-lint.yml +0 -38
- data/.github/workflows/pdd.yml +0 -34
- data/.github/workflows/rake.yml +0 -43
- data/.github/workflows/xcop.yml +0 -34
- data/.gitignore +0 -8
- data/.pdd +0 -5
- data/.rubocop.yml +0 -46
- data/.rultor.yml +0 -41
- data/renovate.json +0 -6
- data/test/test__helper.rb +0 -27
- data/test/test_pool.rb +0 -142
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19a3b6d51277760ad0638f741ef63bf1fbc8a4b77663b41569da4c34e251353a
|
4
|
+
data.tar.gz: 96e0c4061b43248cbf091e318b9e6645371a7fd11189a43cd1cadccf23b9704d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ac6711969efbcd97a534391cff9b3bb3e4244a5fe0a4518d7cbb3644a6b849507db8025af1491fac615c1aa9f3edf4db7d7bd9e42faf5619304191c1265afa0
|
7
|
+
data.tar.gz: f01a9a30993fcc100fd5946290a8f8b60d94cb8a19db6ab8b918527ca48086f92cff89723391d99302f79fc264ed9f4d76a2225bfdfa24819e3af51ec8971396
|
data/Gemfile
CHANGED
@@ -1,32 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
source 'https://rubygems.org'
|
24
7
|
gemspec
|
25
8
|
|
26
|
-
gem 'minitest', '5.25
|
27
|
-
gem '
|
28
|
-
gem '
|
29
|
-
gem 'rubocop
|
30
|
-
gem '
|
31
|
-
gem '
|
32
|
-
gem '
|
9
|
+
gem 'minitest', '~>5.25', require: false
|
10
|
+
gem 'qbash', '~>0.2', require: false
|
11
|
+
gem 'rake', '~>13.2', require: false
|
12
|
+
gem 'rubocop', '~>1.75', require: false
|
13
|
+
gem 'rubocop-minitest', '~>0.38', require: false
|
14
|
+
gem 'rubocop-performance', '~>1.25', require: false
|
15
|
+
gem 'rubocop-rake', '~>0.7', require: false
|
16
|
+
gem 'rubocop-rspec', '~> 3.7', require: false
|
17
|
+
gem 'simplecov', '~>0.22', require: false
|
18
|
+
gem 'threads', '~>0.4', require: false
|
19
|
+
gem 'yard', '~>0.9', require: false
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
random-port (0.0.0)
|
5
|
+
tago (~> 0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.3)
|
11
|
+
backtrace (0.4.1)
|
12
|
+
concurrent-ruby (1.3.5)
|
13
|
+
docile (1.4.1)
|
14
|
+
elapsed (0.2.0)
|
15
|
+
loog (~> 0.6)
|
16
|
+
tago (~> 0.1)
|
17
|
+
json (2.15.0)
|
18
|
+
language_server-protocol (3.17.0.5)
|
19
|
+
lint_roller (1.1.0)
|
20
|
+
logger (1.7.0)
|
21
|
+
loog (0.6.1)
|
22
|
+
logger (~> 1.0)
|
23
|
+
minitest (5.25.5)
|
24
|
+
parallel (1.27.0)
|
25
|
+
parser (3.3.9.0)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
racc
|
28
|
+
prism (1.5.1)
|
29
|
+
qbash (0.4.5)
|
30
|
+
backtrace (> 0)
|
31
|
+
elapsed (> 0)
|
32
|
+
loog (> 0)
|
33
|
+
tago (> 0)
|
34
|
+
racc (1.8.1)
|
35
|
+
rainbow (3.1.1)
|
36
|
+
rake (13.3.0)
|
37
|
+
regexp_parser (2.11.3)
|
38
|
+
rubocop (1.80.2)
|
39
|
+
json (~> 2.3)
|
40
|
+
language_server-protocol (~> 3.17.0.2)
|
41
|
+
lint_roller (~> 1.1.0)
|
42
|
+
parallel (~> 1.10)
|
43
|
+
parser (>= 3.3.0.2)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
46
|
+
rubocop-ast (>= 1.46.0, < 2.0)
|
47
|
+
ruby-progressbar (~> 1.7)
|
48
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
49
|
+
rubocop-ast (1.47.1)
|
50
|
+
parser (>= 3.3.7.2)
|
51
|
+
prism (~> 1.4)
|
52
|
+
rubocop-minitest (0.38.2)
|
53
|
+
lint_roller (~> 1.1)
|
54
|
+
rubocop (>= 1.75.0, < 2.0)
|
55
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
56
|
+
rubocop-performance (1.26.0)
|
57
|
+
lint_roller (~> 1.1)
|
58
|
+
rubocop (>= 1.75.0, < 2.0)
|
59
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
60
|
+
rubocop-rake (0.7.1)
|
61
|
+
lint_roller (~> 1.1)
|
62
|
+
rubocop (>= 1.72.1)
|
63
|
+
rubocop-rspec (3.7.0)
|
64
|
+
lint_roller (~> 1.1)
|
65
|
+
rubocop (~> 1.72, >= 1.72.1)
|
66
|
+
ruby-progressbar (1.13.0)
|
67
|
+
simplecov (0.22.0)
|
68
|
+
docile (~> 1.1)
|
69
|
+
simplecov-html (~> 0.11)
|
70
|
+
simplecov_json_formatter (~> 0.1)
|
71
|
+
simplecov-html (0.13.2)
|
72
|
+
simplecov_json_formatter (0.1.4)
|
73
|
+
tago (0.2.0)
|
74
|
+
threads (0.4.1)
|
75
|
+
backtrace (~> 0)
|
76
|
+
concurrent-ruby (~> 1.0)
|
77
|
+
unicode-display_width (3.2.0)
|
78
|
+
unicode-emoji (~> 4.1)
|
79
|
+
unicode-emoji (4.1.0)
|
80
|
+
yard (0.9.37)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
arm64-darwin-22
|
84
|
+
arm64-darwin-23
|
85
|
+
arm64-darwin-24
|
86
|
+
x64-mingw-ucrt
|
87
|
+
x86_64-linux
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
minitest (~> 5.25)
|
91
|
+
qbash (~> 0.2)
|
92
|
+
rake (~> 13.2)
|
93
|
+
random-port!
|
94
|
+
rubocop (~> 1.75)
|
95
|
+
rubocop-minitest (~> 0.38)
|
96
|
+
rubocop-performance (~> 1.25)
|
97
|
+
rubocop-rake (~> 0.7)
|
98
|
+
rubocop-rspec (~> 3.7)
|
99
|
+
simplecov (~> 0.22)
|
100
|
+
threads (~> 0.4)
|
101
|
+
yard (~> 0.9)
|
102
|
+
|
103
|
+
BUNDLED WITH
|
104
|
+
2.5.16
|
data/LICENSE.txt
CHANGED
data/LICENSES/MIT.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2018-2025 Yegor Bugayenko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Random TCP Port Generator for Ruby
|
2
2
|
|
3
|
-
[](https://www.rultor.com/p/yegor256/random-port)
|
4
|
+
[](https://www.jetbrains.com/ruby/)
|
5
5
|
|
6
6
|
[](https://github.com/yegor256/random-port/actions/workflows/rake.yml)
|
7
|
-
[](
|
7
|
+
[](https://badge.fury.io/rb/random-port)
|
8
8
|
[](https://codeclimate.com/github/yegor256/random-port/maintainability)
|
9
|
-
[](https://rubydoc.info/github/yegor256/random-port/master/frames)
|
10
10
|
[](https://github.com/yegor256/random-port/blob/master/LICENSE.txt)
|
11
11
|
[](https://codecov.io/github/yegor256/random-port?branch=master)
|
12
12
|
[](https://hitsofcode.com/view/github/random-port/mailanes)
|
@@ -60,7 +60,7 @@ not-thread-safe, using optional `sync` argument of the constructor.
|
|
60
60
|
|
61
61
|
Read
|
62
62
|
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
63
|
-
Make sure
|
63
|
+
Make sure your build is green before you contribute
|
64
64
|
your pull request. You will need to have
|
65
65
|
[Ruby](https://www.ruby-lang.org/en/) 2.3+ and
|
66
66
|
[Bundler](https://bundler.io/) installed. Then:
|
data/REUSE.toml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
|
2
|
+
# SPDX-License-Identifier: MIT
|
3
|
+
|
4
|
+
version = 1
|
5
|
+
[[annotations]]
|
6
|
+
path = [
|
7
|
+
".DS_Store",
|
8
|
+
".gitattributes",
|
9
|
+
".gitignore",
|
10
|
+
".pdd",
|
11
|
+
"**.json",
|
12
|
+
"**.md",
|
13
|
+
"**.png",
|
14
|
+
"**.txt",
|
15
|
+
"**/.DS_Store",
|
16
|
+
"**/.gitignore",
|
17
|
+
"**/.pdd",
|
18
|
+
"**/*.csv",
|
19
|
+
"**/*.jpg",
|
20
|
+
"**/*.json",
|
21
|
+
"**/*.md",
|
22
|
+
"**/*.pdf",
|
23
|
+
"**/*.png",
|
24
|
+
"**/*.svg",
|
25
|
+
"**/*.txt",
|
26
|
+
"**/*.vm",
|
27
|
+
"**/CNAME",
|
28
|
+
"**/Gemfile.lock",
|
29
|
+
"Gemfile.lock",
|
30
|
+
"README.md",
|
31
|
+
"renovate.json",
|
32
|
+
]
|
33
|
+
precedence = "override"
|
34
|
+
SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
|
35
|
+
SPDX-License-Identifier = "MIT"
|
data/Rakefile
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'rubygems'
|
24
7
|
require 'rake'
|
@@ -48,7 +31,6 @@ require 'rubocop/rake_task'
|
|
48
31
|
desc 'Run RuboCop on all directories'
|
49
32
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
50
33
|
task.fail_on_error = true
|
51
|
-
task.requires << 'rubocop-rspec'
|
52
34
|
end
|
53
35
|
|
54
36
|
require 'yard'
|
data/lib/random-port/module.rb
CHANGED
@@ -1,31 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# (
|
4
|
-
#
|
5
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
-
# in the Software without restriction, including without limitation the rights
|
10
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
# copies of the Software, and to permit persons to whom the Software is
|
12
|
-
# furnished to do so, subject to the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be included in all
|
15
|
-
# copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
24
5
|
|
25
6
|
# The module for all classes.
|
26
7
|
#
|
27
8
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
28
|
-
# Copyright:: Copyright (c) 2018-
|
9
|
+
# Copyright:: Copyright (c) 2018-2025 Yegor Bugayenko
|
29
10
|
# License:: MIT
|
30
11
|
module RandomPort
|
31
12
|
end
|
data/lib/random-port/pool.rb
CHANGED
@@ -1,26 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# (
|
4
|
-
#
|
5
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
-
# in the Software without restriction, including without limitation the rights
|
10
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
# copies of the Software, and to permit persons to whom the Software is
|
12
|
-
# furnished to do so, subject to the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be included in all
|
15
|
-
# copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
24
5
|
|
25
6
|
require 'monitor'
|
26
7
|
require 'socket'
|
@@ -44,7 +25,7 @@ require_relative 'module'
|
|
44
25
|
# passing <tt>FALSE</tt>.
|
45
26
|
#
|
46
27
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
47
|
-
# Copyright:: Copyright (c) 2018-
|
28
|
+
# Copyright:: Copyright (c) 2018-2025 Yegor Bugayenko
|
48
29
|
# License:: MIT
|
49
30
|
class RandomPort::Pool
|
50
31
|
# If can't acquire by time out.
|
@@ -55,12 +36,13 @@ class RandomPort::Pool
|
|
55
36
|
# Ctor.
|
56
37
|
# @param [Boolean] sync Set it to FALSE if you want this pool to be NOT thread-safe
|
57
38
|
# @param [Integer] limit Set the maximum number of ports in the pool
|
58
|
-
|
39
|
+
# @param [Integer] start The next port to try
|
40
|
+
def initialize(sync: true, limit: 65_536, start: 1025)
|
59
41
|
@ports = []
|
60
42
|
@sync = sync
|
61
43
|
@monitor = Monitor.new
|
62
44
|
@limit = limit
|
63
|
-
@next =
|
45
|
+
@next = start
|
64
46
|
end
|
65
47
|
|
66
48
|
# Application wide pool of ports
|
@@ -133,7 +115,7 @@ class RandomPort::Pool
|
|
133
115
|
# @param [Integer] total How many ports to take
|
134
116
|
# @return [Array<Integer>|nil] Ports found or NIL if impossible now
|
135
117
|
def group(total)
|
136
|
-
return if @ports.count + total > @limit
|
118
|
+
return nil if @ports.count + total > @limit
|
137
119
|
opts = Array.new(0, total)
|
138
120
|
begin
|
139
121
|
(0..(total - 1)).each do |i|
|
@@ -141,23 +123,30 @@ class RandomPort::Pool
|
|
141
123
|
opts[i] = take(port)
|
142
124
|
end
|
143
125
|
rescue Errno::EADDRINUSE, SocketError
|
144
|
-
return
|
126
|
+
return nil
|
145
127
|
end
|
146
|
-
return if opts.any? { |p| @ports.include?(p) }
|
128
|
+
return nil if opts.any? { |p| @ports.include?(p) }
|
147
129
|
d = total * (total - 1) / 2
|
148
|
-
return unless opts.inject(&:+) - (total * opts.min) == d
|
130
|
+
return nil unless opts.inject(&:+) - (total * opts.min) == d
|
149
131
|
@ports += opts
|
150
132
|
opts
|
151
133
|
end
|
152
134
|
|
153
|
-
# Find one possible TCP port.
|
154
|
-
#
|
155
|
-
#
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
135
|
+
# Find one possible TCP port or raise exception if this port can't be used.
|
136
|
+
#
|
137
|
+
# If port is occupied, this method raises an error (+Errno::EADDRINUSE+).
|
138
|
+
#
|
139
|
+
# @param [Integer] port Suggested port number
|
140
|
+
# @return [Integer] The same port number
|
141
|
+
def take(port)
|
142
|
+
['127.0.0.1', '::1', '0.0.0.0', 'localhost'].each do |host|
|
143
|
+
begin
|
144
|
+
TCPServer.new(host, port).close
|
145
|
+
rescue Errno::EADDRNOTAVAIL
|
146
|
+
next
|
147
|
+
end
|
148
|
+
end
|
149
|
+
port
|
161
150
|
end
|
162
151
|
|
163
152
|
def safe(&block)
|
data/lib/random-port.rb
CHANGED
@@ -1,26 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# (
|
4
|
-
#
|
5
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
-
# in the Software without restriction, including without limitation the rights
|
10
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
# copies of the Software, and to permit persons to whom the Software is
|
12
|
-
# furnished to do so, subject to the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be included in all
|
15
|
-
# copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
24
5
|
|
25
6
|
require_relative 'random-port/module'
|
26
7
|
require_relative 'random-port/pool'
|
data/random-port.gemspec
CHANGED
@@ -1,42 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# (
|
4
|
-
#
|
5
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
-
# in the Software without restriction, including without limitation the rights
|
10
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
# copies of the Software, and to permit persons to whom the Software is
|
12
|
-
# furnished to do so, subject to the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be included in all
|
15
|
-
# copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
24
5
|
|
25
6
|
require 'English'
|
26
7
|
Gem::Specification.new do |s|
|
27
8
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
28
9
|
s.required_ruby_version = '>=2.3'
|
29
10
|
s.name = 'random-port'
|
30
|
-
s.version = '0.7.
|
11
|
+
s.version = '0.7.6'
|
31
12
|
s.license = 'MIT'
|
32
13
|
s.summary = 'Random TCP port'
|
33
14
|
s.description = 'Reserves a random TCP port'
|
34
15
|
s.authors = ['Yegor Bugayenko']
|
35
16
|
s.email = 'yegor256@gmail.com'
|
36
|
-
s.homepage = '
|
37
|
-
s.files = `git ls-files`.split($RS)
|
17
|
+
s.homepage = 'https://github.com/yegor256/random-port'
|
18
|
+
s.files = `git ls-files | grep -v -E '^(test/|\\.|renovate)'`.split($RS)
|
38
19
|
s.rdoc_options = ['--charset=UTF-8']
|
39
20
|
s.extra_rdoc_files = ['README.md']
|
40
|
-
s.add_dependency 'tago', '
|
21
|
+
s.add_dependency 'tago', '~>0.0'
|
41
22
|
s.metadata['rubygems_mfa_required'] = 'true'
|
42
23
|
end
|
metadata
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: random-port
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: tago
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- - "
|
16
|
+
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
18
|
+
version: '0.0'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- - "
|
23
|
+
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
25
|
+
version: '0.0'
|
27
26
|
description: Reserves a random TCP port
|
28
27
|
email: yegor256@gmail.com
|
29
28
|
executables: []
|
@@ -31,35 +30,22 @@ extensions: []
|
|
31
30
|
extra_rdoc_files:
|
32
31
|
- README.md
|
33
32
|
files:
|
34
|
-
- ".0pdd.yml"
|
35
|
-
- ".github/workflows/actionlint.yml"
|
36
|
-
- ".github/workflows/codecov.yml"
|
37
|
-
- ".github/workflows/copyrights.yml"
|
38
|
-
- ".github/workflows/markdown-lint.yml"
|
39
|
-
- ".github/workflows/pdd.yml"
|
40
|
-
- ".github/workflows/rake.yml"
|
41
|
-
- ".github/workflows/xcop.yml"
|
42
|
-
- ".gitignore"
|
43
|
-
- ".pdd"
|
44
|
-
- ".rubocop.yml"
|
45
|
-
- ".rultor.yml"
|
46
33
|
- Gemfile
|
34
|
+
- Gemfile.lock
|
47
35
|
- LICENSE.txt
|
36
|
+
- LICENSES/MIT.txt
|
48
37
|
- README.md
|
38
|
+
- REUSE.toml
|
49
39
|
- Rakefile
|
50
40
|
- lib/random-port.rb
|
51
41
|
- lib/random-port/module.rb
|
52
42
|
- lib/random-port/pool.rb
|
53
43
|
- random-port.gemspec
|
54
|
-
|
55
|
-
- test/test__helper.rb
|
56
|
-
- test/test_pool.rb
|
57
|
-
homepage: http://github.com/yegor256/random-port
|
44
|
+
homepage: https://github.com/yegor256/random-port
|
58
45
|
licenses:
|
59
46
|
- MIT
|
60
47
|
metadata:
|
61
48
|
rubygems_mfa_required: 'true'
|
62
|
-
post_install_message:
|
63
49
|
rdoc_options:
|
64
50
|
- "--charset=UTF-8"
|
65
51
|
require_paths:
|
@@ -75,8 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
61
|
- !ruby/object:Gem::Version
|
76
62
|
version: '0'
|
77
63
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
-
signing_key:
|
64
|
+
rubygems_version: 3.6.9
|
80
65
|
specification_version: 4
|
81
66
|
summary: Random TCP port
|
82
67
|
test_files: []
|
data/.0pdd.yml
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
errors:
|
22
|
-
- yegor256@gmail.com
|
23
|
-
# alerts:
|
24
|
-
# github:
|
25
|
-
# - yegor256
|
26
|
-
|
27
|
-
tags:
|
28
|
-
- pdd
|
29
|
-
- bug
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
name: actionlint
|
22
|
-
'on':
|
23
|
-
push:
|
24
|
-
branches:
|
25
|
-
- master
|
26
|
-
pull_request:
|
27
|
-
branches:
|
28
|
-
- master
|
29
|
-
jobs:
|
30
|
-
actionlint:
|
31
|
-
runs-on: ubuntu-24.04
|
32
|
-
steps:
|
33
|
-
- uses: actions/checkout@v4
|
34
|
-
- name: Download actionlint
|
35
|
-
id: get_actionlint
|
36
|
-
# yamllint disable-line rule:line-length
|
37
|
-
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
|
38
|
-
shell: bash
|
39
|
-
- name: Check workflow files
|
40
|
-
run: ${{ steps.get_actionlint.outputs.executable }} -color
|
41
|
-
shell: bash
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
name: codecov
|
22
|
-
on:
|
23
|
-
push:
|
24
|
-
branches:
|
25
|
-
- master
|
26
|
-
jobs:
|
27
|
-
codecov:
|
28
|
-
runs-on: ubuntu-24.04
|
29
|
-
steps:
|
30
|
-
- uses: actions/checkout@v4
|
31
|
-
- uses: ruby/setup-ruby@v1
|
32
|
-
with:
|
33
|
-
ruby-version: 3.3
|
34
|
-
- run: bundle update
|
35
|
-
- run: bundle exec rake
|
36
|
-
- uses: codecov/codecov-action@v5
|
37
|
-
with:
|
38
|
-
token: ${{ secrets.CODECOV_TOKEN }}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
name: copyrights
|
22
|
-
'on':
|
23
|
-
push:
|
24
|
-
branches:
|
25
|
-
- master
|
26
|
-
pull_request:
|
27
|
-
branches:
|
28
|
-
- master
|
29
|
-
jobs:
|
30
|
-
copyrights:
|
31
|
-
runs-on: ubuntu-24.04
|
32
|
-
steps:
|
33
|
-
- uses: actions/checkout@v4
|
34
|
-
- uses: yegor256/copyrights-action@0.0.8
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
name: markdown-lint
|
22
|
-
'on':
|
23
|
-
push:
|
24
|
-
branches:
|
25
|
-
- master
|
26
|
-
pull_request:
|
27
|
-
branches:
|
28
|
-
- master
|
29
|
-
paths-ignore: ['paper/**', 'sandbox/**']
|
30
|
-
concurrency:
|
31
|
-
group: markdown-lint-${{ github.ref }}
|
32
|
-
cancel-in-progress: true
|
33
|
-
jobs:
|
34
|
-
markdown-lint:
|
35
|
-
runs-on: ubuntu-24.04
|
36
|
-
steps:
|
37
|
-
- uses: actions/checkout@v4
|
38
|
-
- uses: articulate/actions-markdownlint@v1
|
data/.github/workflows/pdd.yml
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
name: pdd
|
22
|
-
on:
|
23
|
-
push:
|
24
|
-
branches:
|
25
|
-
- master
|
26
|
-
pull_request:
|
27
|
-
branches:
|
28
|
-
- master
|
29
|
-
jobs:
|
30
|
-
pdd:
|
31
|
-
runs-on: ubuntu-24.04
|
32
|
-
steps:
|
33
|
-
- uses: actions/checkout@v4
|
34
|
-
- uses: volodya-lombrozo/pdd-action@master
|
data/.github/workflows/rake.yml
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
name: rake
|
22
|
-
on:
|
23
|
-
push:
|
24
|
-
branches:
|
25
|
-
- master
|
26
|
-
pull_request:
|
27
|
-
branches:
|
28
|
-
- master
|
29
|
-
jobs:
|
30
|
-
test:
|
31
|
-
name: test
|
32
|
-
strategy:
|
33
|
-
matrix:
|
34
|
-
os: [ubuntu-24.04, macos-15, windows-2022]
|
35
|
-
ruby: [3.3]
|
36
|
-
runs-on: ${{ matrix.os }}
|
37
|
-
steps:
|
38
|
-
- uses: actions/checkout@v4
|
39
|
-
- uses: ruby/setup-ruby@v1
|
40
|
-
with:
|
41
|
-
ruby-version: ${{ matrix.ruby }}
|
42
|
-
- run: bundle update
|
43
|
-
- run: bundle exec rake
|
data/.github/workflows/xcop.yml
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
name: xcop
|
22
|
-
'on':
|
23
|
-
push:
|
24
|
-
branches:
|
25
|
-
- master
|
26
|
-
pull_request:
|
27
|
-
branches:
|
28
|
-
- master
|
29
|
-
jobs:
|
30
|
-
xcop:
|
31
|
-
runs-on: ubuntu-24.04
|
32
|
-
steps:
|
33
|
-
- uses: actions/checkout@v4
|
34
|
-
- uses: g4s8/xcop-action@master
|
data/.gitignore
DELETED
data/.pdd
DELETED
data/.rubocop.yml
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
AllCops:
|
22
|
-
DisplayCopNames: true
|
23
|
-
TargetRubyVersion: 2.3.3
|
24
|
-
NewCops: enable
|
25
|
-
SuggestExtensions: false
|
26
|
-
|
27
|
-
Layout/EmptyLineAfterGuardClause:
|
28
|
-
Enabled: false
|
29
|
-
Style/ClassAndModuleChildren:
|
30
|
-
Enabled: false
|
31
|
-
Naming/FileName:
|
32
|
-
Enabled: false
|
33
|
-
Metrics/MethodLength:
|
34
|
-
Max: 50
|
35
|
-
Metrics/BlockLength:
|
36
|
-
Max: 50
|
37
|
-
Style/ConditionalAssignment:
|
38
|
-
Enabled: false
|
39
|
-
Style/ClassVars:
|
40
|
-
Enabled: false
|
41
|
-
Metrics/PerceivedComplexity:
|
42
|
-
Max: 20
|
43
|
-
Metrics/CyclomaticComplexity:
|
44
|
-
Max: 20
|
45
|
-
Metrics/AbcSize:
|
46
|
-
Max: 60
|
data/.rultor.yml
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
docker:
|
22
|
-
image: yegor256/rultor-ruby
|
23
|
-
assets:
|
24
|
-
rubygems.yml: yegor256/home#assets/rubygems.yml
|
25
|
-
install: |-
|
26
|
-
pdd -f /dev/null
|
27
|
-
sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
|
28
|
-
release:
|
29
|
-
pre: false
|
30
|
-
script: |-
|
31
|
-
bundle exec rake
|
32
|
-
rm -rf *.gem
|
33
|
-
sed -i "s/0\.0\.0/${tag}/g" random-port.gemspec
|
34
|
-
git add random-port.gemspec
|
35
|
-
git commit -m "Version set to ${tag}"
|
36
|
-
gem build random-port.gemspec
|
37
|
-
chmod 0600 ../rubygems.yml
|
38
|
-
gem push *.gem --config-file ../rubygems.yml
|
39
|
-
merge:
|
40
|
-
script: |-
|
41
|
-
bundle exec rake
|
data/renovate.json
DELETED
data/test/test__helper.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
22
|
-
|
23
|
-
$stdout.sync = true
|
24
|
-
|
25
|
-
require 'simplecov'
|
26
|
-
SimpleCov.start
|
27
|
-
require 'minitest/autorun'
|
data/test/test_pool.rb
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# (The MIT License)
|
4
|
-
#
|
5
|
-
# Copyright (c) 2018-2024 Yegor Bugayenko
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
-
# in the Software without restriction, including without limitation the rights
|
10
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
# copies of the Software, and to permit persons to whom the Software is
|
12
|
-
# furnished to do so, subject to the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be included in all
|
15
|
-
# copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
-
# SOFTWARE.
|
24
|
-
|
25
|
-
require 'minitest/autorun'
|
26
|
-
require 'threads'
|
27
|
-
require 'socket'
|
28
|
-
require_relative '../lib/random-port/pool'
|
29
|
-
|
30
|
-
# Pool test.
|
31
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
-
# Copyright:: Copyright (c) 2018-2024 Yegor Bugayenko
|
33
|
-
# License:: MIT
|
34
|
-
class RandomPort::TestPool < Minitest::Test
|
35
|
-
def test_acquires_and_releases
|
36
|
-
pool = RandomPort::Pool.new
|
37
|
-
port = pool.acquire
|
38
|
-
server = TCPServer.new('localhost', port)
|
39
|
-
server.close
|
40
|
-
assert(!port.nil?)
|
41
|
-
assert(port.positive?)
|
42
|
-
pool.release(port)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_acquires_and_releases_three_ports
|
46
|
-
pool = RandomPort::Pool.new(limit: 3)
|
47
|
-
assert_equal(0, pool.size)
|
48
|
-
ports = pool.acquire(3, timeout: 16)
|
49
|
-
ports.each do |p|
|
50
|
-
server = TCPServer.new('localhost', p)
|
51
|
-
server.close
|
52
|
-
end
|
53
|
-
assert_equal(3, pool.size)
|
54
|
-
assert_equal(3, ports.count)
|
55
|
-
pool.release(ports)
|
56
|
-
assert_equal(0, pool.size)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_acquires_and_releases_three_ports_in_block
|
60
|
-
pool = RandomPort::Pool.new(limit: 3)
|
61
|
-
assert_equal(0, pool.size)
|
62
|
-
pool.acquire(3, timeout: 16) do |ports|
|
63
|
-
assert(ports.is_a?(Array))
|
64
|
-
assert_equal(3, ports.count)
|
65
|
-
assert_equal(3, pool.size)
|
66
|
-
ports.each do |p|
|
67
|
-
server = TCPServer.new('localhost', p)
|
68
|
-
server.close
|
69
|
-
end
|
70
|
-
end
|
71
|
-
assert_equal(0, pool.size)
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_acquires_and_releases_in_block
|
75
|
-
result = RandomPort::Pool.new.acquire do |port|
|
76
|
-
assert(!port.nil?)
|
77
|
-
assert(port.positive?)
|
78
|
-
123
|
79
|
-
end
|
80
|
-
assert_equal(123, result)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_acquires_and_releases_in_threads
|
84
|
-
pool = RandomPort::Pool.new
|
85
|
-
Threads.new(100).assert do
|
86
|
-
pool.acquire(5) do |ports|
|
87
|
-
ports.each do |p|
|
88
|
-
server = TCPServer.new('localhost', p)
|
89
|
-
server.close
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_acquires_and_releases_safely
|
96
|
-
pool = RandomPort::Pool.new
|
97
|
-
assert_raises do
|
98
|
-
pool.acquire do
|
99
|
-
raise 'Itended'
|
100
|
-
end
|
101
|
-
end
|
102
|
-
assert(pool.count.zero?)
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_acquires_and_releases_from_singleton
|
106
|
-
RandomPort::Pool::SINGLETON.acquire do |port|
|
107
|
-
assert(!port.nil?)
|
108
|
-
assert(port.positive?)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_acquires_unique_numbers
|
113
|
-
total = 25
|
114
|
-
numbers = (0..total - 1).map { RandomPort::Pool::SINGLETON.acquire }
|
115
|
-
assert_equal(total, numbers.uniq.count)
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_acquires_unique_numbers_in_block
|
119
|
-
total = 25
|
120
|
-
numbers = (0..total - 1).map do
|
121
|
-
RandomPort::Pool::SINGLETON.acquire do |port|
|
122
|
-
port
|
123
|
-
end
|
124
|
-
end
|
125
|
-
assert_equal(total, numbers.uniq.count)
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_raises_when_too_many
|
129
|
-
pool = RandomPort::Pool.new(limit: 1)
|
130
|
-
pool.acquire
|
131
|
-
assert_raises RandomPort::Pool::Timeout do
|
132
|
-
pool.acquire(timeout: 0.1)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_acquires_unique_numbers_in_no_sync_mode
|
137
|
-
total = 25
|
138
|
-
pool = RandomPort::Pool.new(sync: false)
|
139
|
-
numbers = (0..total - 1).map { pool.acquire }
|
140
|
-
assert_equal(total, numbers.uniq.count)
|
141
|
-
end
|
142
|
-
end
|