random-port 0.5.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.0pdd.yml +20 -0
- data/.github/workflows/actionlint.yml +41 -0
- data/.github/workflows/codecov.yml +38 -0
- data/.github/workflows/copyrights.yml +30 -0
- data/.github/workflows/markdown-lint.yml +38 -0
- data/.github/workflows/pdd.yml +34 -0
- data/.github/workflows/rake.yml +43 -0
- data/.github/workflows/xcop.yml +30 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +26 -0
- data/.rultor.yml +26 -8
- data/Gemfile +9 -1
- data/LICENSE.txt +1 -1
- data/README.md +11 -8
- data/Rakefile +9 -3
- data/lib/random-port/module.rb +31 -0
- data/lib/random-port/pool.rb +100 -98
- data/lib/random-port.rb +3 -2
- data/random-port.gemspec +4 -14
- data/renovate.json +6 -0
- data/test/test__helper.rb +2 -7
- data/test/test_pool.rb +82 -60
- metadata +17 -94
- data/.travis.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b71762c94a8e91f18c8ad99635fccc5a1d970933383788e33ce5c7e727309bb5
|
4
|
+
data.tar.gz: 6615e680ca4ff3307658e32bc259068ec0d18b8855233f7f2f0e4f9677de59dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d682b677cbc3cd75ea175905f7329606deb6bf791e78d7bdad3b011c9c0c2ef2b020cbda389cd83ae6677d57d42cf5dfa3884f78a6e22fd2961abd1c808c04f
|
7
|
+
data.tar.gz: 273fd54dcd45d2acad27ec446eea6cb8570e79318cf92e20144f7dad46000a534a1ff958be7b347e0a20a9c1c8156b2a63e233013a5e064be0e5fa12ad576905
|
data/.0pdd.yml
CHANGED
@@ -1,3 +1,23 @@
|
|
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
|
+
---
|
1
21
|
errors:
|
2
22
|
- yegor256@gmail.com
|
3
23
|
# alerts:
|
@@ -0,0 +1,41 @@
|
|
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-22.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
|
@@ -0,0 +1,38 @@
|
|
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-20.04
|
29
|
+
steps:
|
30
|
+
- uses: actions/checkout@v4
|
31
|
+
- uses: ruby/setup-ruby@v1
|
32
|
+
with:
|
33
|
+
ruby-version: 2.7
|
34
|
+
- run: bundle update
|
35
|
+
- run: bundle exec rake
|
36
|
+
- uses: codecov/codecov-action@v3
|
37
|
+
with:
|
38
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
@@ -0,0 +1,30 @@
|
|
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
|
+
pull_request:
|
25
|
+
jobs:
|
26
|
+
copyrights:
|
27
|
+
runs-on: ubuntu-22.04
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@v4
|
30
|
+
- uses: yegor256/copyrights-action@0.0.4
|
@@ -0,0 +1,38 @@
|
|
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-22.04
|
36
|
+
steps:
|
37
|
+
- uses: actions/checkout@v4
|
38
|
+
- uses: articulate/actions-markdownlint@v1
|
@@ -0,0 +1,34 @@
|
|
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-22.04
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@v4
|
34
|
+
- uses: volodya-lombrozo/pdd-action@master
|
@@ -0,0 +1,43 @@
|
|
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-20.04, macos-12]
|
35
|
+
ruby: [2.7, 3.2]
|
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
|
@@ -0,0 +1,30 @@
|
|
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
|
+
pull_request:
|
25
|
+
jobs:
|
26
|
+
xcop:
|
27
|
+
runs-on: ubuntu-20.04
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@v4
|
30
|
+
- uses: g4s8/xcop-action@master
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,7 +1,33 @@
|
|
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
|
+
---
|
1
21
|
AllCops:
|
2
22
|
DisplayCopNames: true
|
3
23
|
TargetRubyVersion: 2.3.3
|
24
|
+
NewCops: enable
|
25
|
+
SuggestExtensions: false
|
4
26
|
|
27
|
+
Layout/EmptyLineAfterGuardClause:
|
28
|
+
Enabled: false
|
29
|
+
Style/ClassAndModuleChildren:
|
30
|
+
Enabled: false
|
5
31
|
Naming/FileName:
|
6
32
|
Enabled: false
|
7
33
|
Metrics/MethodLength:
|
data/.rultor.yml
CHANGED
@@ -1,10 +1,32 @@
|
|
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-image:1.23.1
|
1
23
|
assets:
|
2
|
-
rubygems.yml:
|
24
|
+
rubygems.yml: yegor256/home#assets/rubygems.yml
|
3
25
|
install: |-
|
4
|
-
|
5
|
-
|
6
|
-
bundle install --no-color
|
26
|
+
pdd -f /dev/null
|
27
|
+
sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
|
7
28
|
release:
|
29
|
+
pre: false
|
8
30
|
script: |-
|
9
31
|
bundle exec rake
|
10
32
|
rm -rf *.gem
|
@@ -17,7 +39,3 @@ release:
|
|
17
39
|
merge:
|
18
40
|
script: |-
|
19
41
|
bundle exec rake
|
20
|
-
deploy:
|
21
|
-
script: |-
|
22
|
-
echo Nothing to deploy
|
23
|
-
exit -1
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2018-2024 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -22,3 +22,11 @@
|
|
22
22
|
|
23
23
|
source 'https://rubygems.org'
|
24
24
|
gemspec
|
25
|
+
|
26
|
+
gem 'minitest', '5.24.1', require: false
|
27
|
+
gem 'rake', '13.2.1', require: false
|
28
|
+
gem 'rubocop', '1.64.1', require: false
|
29
|
+
gem 'rubocop-rspec', '3.0.2', require: false
|
30
|
+
gem 'simplecov', '0.22.0', require: false
|
31
|
+
gem 'threads', '0.3.0', require: false
|
32
|
+
gem 'yard', '0.9.36', require: false
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
# Random TCP Port Generator for Ruby
|
2
|
+
|
1
3
|
[![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/random-port)](http://www.rultor.com/p/yegor256/random-port)
|
2
4
|
[![We recommend RubyMine](http://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
|
3
5
|
|
4
|
-
[![
|
6
|
+
[![rake](https://github.com/yegor256/random-port/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/random-port/actions/workflows/rake.yml)
|
5
7
|
[![Gem Version](https://badge.fury.io/rb/random-port.svg)](http://badge.fury.io/rb/random-port)
|
6
8
|
[![Maintainability](https://api.codeclimate.com/v1/badges/349b8c31884d3b34d926/maintainability)](https://codeclimate.com/github/yegor256/random-port/maintainability)
|
7
9
|
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/random-port/master/frames)
|
8
10
|
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/random-port/blob/master/LICENSE.txt)
|
9
|
-
|
10
11
|
[![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/random-port.svg)](https://codecov.io/github/yegor256/random-port?branch=master)
|
11
12
|
[![Hits-of-Code](https://hitsofcode.com/github/yegor256/random-port)](https://hitsofcode.com/view/github/random-port/mailanes)
|
12
13
|
|
@@ -15,7 +16,7 @@ It's a simple Ruby gem to get a random TCP port.
|
|
15
16
|
First, install it:
|
16
17
|
|
17
18
|
```bash
|
18
|
-
|
19
|
+
gem install random-port
|
19
20
|
```
|
20
21
|
|
21
22
|
Then, use it like this, to reserve a random TCP port:
|
@@ -57,14 +58,16 @@ not-thread-safe, using optional `sync` argument of the constructor.
|
|
57
58
|
|
58
59
|
## How to contribute
|
59
60
|
|
60
|
-
Read
|
61
|
+
Read
|
62
|
+
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
61
63
|
Make sure you build is green before you contribute
|
62
|
-
your pull request. You will need to have
|
64
|
+
your pull request. You will need to have
|
65
|
+
[Ruby](https://www.ruby-lang.org/en/) 2.3+ and
|
63
66
|
[Bundler](https://bundler.io/) installed. Then:
|
64
67
|
|
65
|
-
```
|
66
|
-
|
67
|
-
|
68
|
+
```bash
|
69
|
+
bundle update
|
70
|
+
bundle exec rake
|
68
71
|
```
|
69
72
|
|
70
73
|
If it's clean and you don't see any error messages, submit your pull request.
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2018-2024 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -24,7 +24,7 @@ require 'rubygems'
|
|
24
24
|
require 'rake'
|
25
25
|
require 'rake/clean'
|
26
26
|
|
27
|
-
CLEAN
|
27
|
+
CLEAN << 'coverage'
|
28
28
|
|
29
29
|
def name
|
30
30
|
@name ||= File.basename(Dir['*.gemspec'].first, '.*')
|
@@ -34,7 +34,7 @@ def version
|
|
34
34
|
Gem::Specification.load(Dir['*.gemspec'].first).version
|
35
35
|
end
|
36
36
|
|
37
|
-
task default: %i[clean test rubocop]
|
37
|
+
task default: %i[clean test yard rubocop]
|
38
38
|
|
39
39
|
require 'rake/testtask'
|
40
40
|
desc 'Run all unit tests'
|
@@ -50,3 +50,9 @@ RuboCop::RakeTask.new(:rubocop) do |task|
|
|
50
50
|
task.fail_on_error = true
|
51
51
|
task.requires << 'rubocop-rspec'
|
52
52
|
end
|
53
|
+
|
54
|
+
require 'yard'
|
55
|
+
desc 'Build Yard documentation'
|
56
|
+
YARD::Rake::YardocTask.new do |t|
|
57
|
+
t.files = ['lib/**/*.rb']
|
58
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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
|
+
# The module for all classes.
|
26
|
+
#
|
27
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
28
|
+
# Copyright:: Copyright (c) 2018-2024 Yegor Bugayenko
|
29
|
+
# License:: MIT
|
30
|
+
module RandomPort
|
31
|
+
end
|
data/lib/random-port/pool.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2018 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2018-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -24,121 +24,123 @@
|
|
24
24
|
|
25
25
|
require 'socket'
|
26
26
|
require 'monitor'
|
27
|
+
require_relative 'module'
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
29
|
+
# Pool of TPC ports.
|
30
|
+
#
|
31
|
+
# Use it like this:
|
32
|
+
#
|
33
|
+
# RandomPort::Pool.new.acquire do |port|
|
34
|
+
# # Use the TCP port. It will be returned back
|
35
|
+
# # to the pool afterwards.
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# You can specify the maximum amount of ports to acquire, using +limit+.
|
39
|
+
# If more acquiring requests will arrive, an exception will be raised.
|
40
|
+
#
|
41
|
+
# The class is thread-safe, by default. You can configure it to be
|
42
|
+
# not-thread-safe, using optional +sync+ argument of the constructor,
|
43
|
+
# passing <tt>FALSE</tt>.
|
44
|
+
#
|
45
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
46
|
+
# Copyright:: Copyright (c) 2018-2024 Yegor Bugayenko
|
47
|
+
# License:: MIT
|
48
|
+
class RandomPort::Pool
|
49
|
+
# If can't acquire by time out.
|
50
|
+
class Timeout < StandardError; end
|
50
51
|
|
51
|
-
|
52
|
+
attr_reader :limit
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
# Ctor.
|
55
|
+
# @param [bool] Set it to FALSE if you want this pool to be NOT thread-safe
|
56
|
+
# @param [int] Set the maximum number of ports in the pool
|
57
|
+
def initialize(sync: true, limit: 65_536)
|
58
|
+
@ports = []
|
59
|
+
@sync = sync
|
60
|
+
@monitor = Monitor.new
|
61
|
+
@limit = limit
|
62
|
+
end
|
60
63
|
|
61
|
-
|
62
|
-
|
64
|
+
# Application wide pool of ports
|
65
|
+
SINGLETON = RandomPort::Pool.new
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
# How many ports acquired now?
|
68
|
+
def count
|
69
|
+
@ports.count
|
70
|
+
end
|
71
|
+
alias size count
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
# Is it empty?
|
74
|
+
def empty?
|
75
|
+
@ports.empty?
|
76
|
+
end
|
74
77
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
78
|
+
# Acquire a new random TCP port.
|
79
|
+
#
|
80
|
+
# You can specify the number of ports to acquire. If it's more than one,
|
81
|
+
# an array will be returned.
|
82
|
+
#
|
83
|
+
# You can specify the amount of seconds to wait until a new port
|
84
|
+
# is available.
|
85
|
+
def acquire(total = 1, timeout: 4)
|
86
|
+
start = Time.now
|
87
|
+
loop do
|
88
|
+
if Time.now > start + timeout
|
89
|
+
raise Timeout, "Can't find a place in the pool of #{@limit} ports \
|
87
90
|
for #{total} port(s), in #{format('%.02f', Time.now - start)}s"
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
begin
|
93
|
-
(0..(total - 1)).each do |i|
|
94
|
-
opts[i] = i.zero? ? take : take(opts[i - 1] + 1)
|
95
|
-
end
|
96
|
-
rescue Errno::EADDRINUSE, SocketError
|
97
|
-
next
|
98
|
-
end
|
99
|
-
next if opts.any? { |p| @ports.include?(p) }
|
100
|
-
d = total * (total - 1) / 2
|
101
|
-
next unless opts.inject(&:+) - total * opts.min == d
|
102
|
-
@ports += opts
|
103
|
-
opts
|
104
|
-
end
|
105
|
-
next if opts.nil?
|
106
|
-
opts = opts[0] if total == 1
|
107
|
-
return opts unless block_given?
|
91
|
+
end
|
92
|
+
opts = safe do
|
93
|
+
next if @ports.count + total > @limit
|
94
|
+
opts = Array.new(0, total)
|
108
95
|
begin
|
109
|
-
|
110
|
-
|
111
|
-
|
96
|
+
(0..(total - 1)).each do |i|
|
97
|
+
opts[i] = i.zero? ? take : take(opts[i - 1] + 1)
|
98
|
+
end
|
99
|
+
rescue Errno::EADDRINUSE, SocketError
|
100
|
+
next
|
112
101
|
end
|
102
|
+
next if opts.any? { |p| @ports.include?(p) }
|
103
|
+
d = total * (total - 1) / 2
|
104
|
+
next unless opts.inject(&:+) - (total * opts.min) == d
|
105
|
+
@ports += opts
|
106
|
+
opts
|
107
|
+
end
|
108
|
+
next if opts.nil?
|
109
|
+
opts = opts[0] if total == 1
|
110
|
+
return opts unless block_given?
|
111
|
+
begin
|
112
|
+
return yield opts
|
113
|
+
ensure
|
114
|
+
release(opts)
|
113
115
|
end
|
114
116
|
end
|
117
|
+
end
|
115
118
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
119
|
+
# Return it/them back to the pool.
|
120
|
+
def release(port)
|
121
|
+
safe do
|
122
|
+
if port.is_a?(Array)
|
123
|
+
port.each { |p| @ports.delete(p) }
|
124
|
+
else
|
125
|
+
@ports.delete(port)
|
124
126
|
end
|
125
127
|
end
|
128
|
+
end
|
126
129
|
|
127
|
-
|
130
|
+
private
|
128
131
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
def take(opt = 0)
|
133
|
+
server = TCPServer.new('127.0.0.1', opt)
|
134
|
+
p = server.addr[1]
|
135
|
+
server.close
|
136
|
+
p
|
137
|
+
end
|
135
138
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
139
|
+
def safe(&block)
|
140
|
+
if @sync
|
141
|
+
@monitor.synchronize(&block)
|
142
|
+
else
|
143
|
+
yield
|
142
144
|
end
|
143
145
|
end
|
144
146
|
end
|
data/lib/random-port.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2018 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2018-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -22,4 +22,5 @@
|
|
22
22
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
23
|
# SOFTWARE.
|
24
24
|
|
25
|
-
|
25
|
+
require_relative 'random-port/module'
|
26
|
+
require_relative 'random-port/pool'
|
data/random-port.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2018 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2018-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -24,14 +24,10 @@
|
|
24
24
|
|
25
25
|
require 'English'
|
26
26
|
Gem::Specification.new do |s|
|
27
|
-
s.
|
28
|
-
if s.respond_to? :required_rubygems_version=
|
29
|
-
s.required_rubygems_version = Gem::Requirement.new('>= 0')
|
30
|
-
end
|
31
|
-
s.rubygems_version = '2.3.3'
|
27
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
32
28
|
s.required_ruby_version = '>=2.3'
|
33
29
|
s.name = 'random-port'
|
34
|
-
s.version = '0.
|
30
|
+
s.version = '0.7.0'
|
35
31
|
s.license = 'MIT'
|
36
32
|
s.summary = 'Random TCP port'
|
37
33
|
s.description = 'Reserves a random TCP port'
|
@@ -39,13 +35,7 @@ Gem::Specification.new do |s|
|
|
39
35
|
s.email = 'yegor256@gmail.com'
|
40
36
|
s.homepage = 'http://github.com/yegor256/random-port'
|
41
37
|
s.files = `git ls-files`.split($RS)
|
42
|
-
s.test_files = s.files.grep(%r{^(test)/})
|
43
38
|
s.rdoc_options = ['--charset=UTF-8']
|
44
39
|
s.extra_rdoc_files = ['README.md']
|
45
|
-
s.
|
46
|
-
s.add_development_dependency 'minitest', '5.11.3'
|
47
|
-
s.add_development_dependency 'rake', '12.3.1'
|
48
|
-
s.add_development_dependency 'rdoc', '4.3.0'
|
49
|
-
s.add_development_dependency 'rubocop', '0.58.1'
|
50
|
-
s.add_development_dependency 'rubocop-rspec', '1.27.0'
|
40
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
51
41
|
end
|
data/renovate.json
ADDED
data/test/test__helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -20,13 +20,8 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
|
-
|
23
|
+
$stdout.sync = true
|
24
24
|
|
25
25
|
require 'simplecov'
|
26
26
|
SimpleCov.start
|
27
|
-
if ENV['CI'] == 'true'
|
28
|
-
require 'codecov'
|
29
|
-
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
30
|
-
end
|
31
|
-
|
32
27
|
require 'minitest/autorun'
|
data/test/test_pool.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2018 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2018-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -23,88 +23,110 @@
|
|
23
23
|
# SOFTWARE.
|
24
24
|
|
25
25
|
require 'minitest/autorun'
|
26
|
+
require 'threads'
|
27
|
+
require 'socket'
|
26
28
|
require_relative '../lib/random-port/pool'
|
27
29
|
|
28
30
|
# Pool test.
|
29
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
32
|
+
# Copyright:: Copyright (c) 2018-2024 Yegor Bugayenko
|
31
33
|
# License:: MIT
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
assert_equal(0, pool.size)
|
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
|
50
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
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
59
69
|
end
|
60
|
-
assert_equal(0, pool.size)
|
61
70
|
end
|
71
|
+
assert_equal(0, pool.size)
|
72
|
+
end
|
62
73
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
assert_equal(123, result)
|
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
|
70
79
|
end
|
80
|
+
assert_equal(123, result)
|
81
|
+
end
|
71
82
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
77
90
|
end
|
78
91
|
end
|
79
|
-
assert(pool.count.zero?)
|
80
92
|
end
|
93
|
+
end
|
81
94
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
95
|
+
def test_acquires_and_releases_safely
|
96
|
+
pool = RandomPort::Pool.new
|
97
|
+
assert_raises do
|
98
|
+
pool.acquire do
|
99
|
+
raise 'Itended'
|
86
100
|
end
|
87
101
|
end
|
102
|
+
assert(pool.count.zero?)
|
103
|
+
end
|
88
104
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
105
|
+
def test_acquires_and_releases_from_singleton
|
106
|
+
RandomPort::Pool::SINGLETON.acquire do |port|
|
107
|
+
assert(!port.nil?)
|
108
|
+
assert(port.positive?)
|
93
109
|
end
|
110
|
+
end
|
94
111
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
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
|
102
117
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
118
|
+
def test_raises_when_too_many
|
119
|
+
pool = RandomPort::Pool.new(limit: 1)
|
120
|
+
pool.acquire
|
121
|
+
assert_raises RandomPort::Pool::Timeout do
|
122
|
+
pool.acquire(timeout: 0.1)
|
108
123
|
end
|
109
124
|
end
|
125
|
+
|
126
|
+
def test_acquires_unique_numbers_in_no_sync_mode
|
127
|
+
total = 25
|
128
|
+
pool = RandomPort::Pool.new(sync: false)
|
129
|
+
numbers = (0..total - 1).map { pool.acquire }
|
130
|
+
assert_equal(total, numbers.uniq.count)
|
131
|
+
end
|
110
132
|
end
|
metadata
CHANGED
@@ -1,99 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: random-port
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: codecov
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.10
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.10
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 5.11.3
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 5.11.3
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 12.3.1
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 12.3.1
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rdoc
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 4.3.0
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 4.3.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.58.1
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.58.1
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 1.27.0
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 1.27.0
|
11
|
+
date: 2024-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
97
13
|
description: Reserves a random TCP port
|
98
14
|
email: yegor256@gmail.com
|
99
15
|
executables: []
|
@@ -102,24 +18,33 @@ extra_rdoc_files:
|
|
102
18
|
- README.md
|
103
19
|
files:
|
104
20
|
- ".0pdd.yml"
|
21
|
+
- ".github/workflows/actionlint.yml"
|
22
|
+
- ".github/workflows/codecov.yml"
|
23
|
+
- ".github/workflows/copyrights.yml"
|
24
|
+
- ".github/workflows/markdown-lint.yml"
|
25
|
+
- ".github/workflows/pdd.yml"
|
26
|
+
- ".github/workflows/rake.yml"
|
27
|
+
- ".github/workflows/xcop.yml"
|
105
28
|
- ".gitignore"
|
106
29
|
- ".pdd"
|
107
30
|
- ".rubocop.yml"
|
108
31
|
- ".rultor.yml"
|
109
|
-
- ".travis.yml"
|
110
32
|
- Gemfile
|
111
33
|
- LICENSE.txt
|
112
34
|
- README.md
|
113
35
|
- Rakefile
|
114
36
|
- lib/random-port.rb
|
37
|
+
- lib/random-port/module.rb
|
115
38
|
- lib/random-port/pool.rb
|
116
39
|
- random-port.gemspec
|
40
|
+
- renovate.json
|
117
41
|
- test/test__helper.rb
|
118
42
|
- test/test_pool.rb
|
119
43
|
homepage: http://github.com/yegor256/random-port
|
120
44
|
licenses:
|
121
45
|
- MIT
|
122
|
-
metadata:
|
46
|
+
metadata:
|
47
|
+
rubygems_mfa_required: 'true'
|
123
48
|
post_install_message:
|
124
49
|
rdoc_options:
|
125
50
|
- "--charset=UTF-8"
|
@@ -136,10 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
61
|
- !ruby/object:Gem::Version
|
137
62
|
version: '0'
|
138
63
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
64
|
+
rubygems_version: 3.4.10
|
140
65
|
signing_key:
|
141
|
-
specification_version:
|
66
|
+
specification_version: 4
|
142
67
|
summary: Random TCP port
|
143
|
-
test_files:
|
144
|
-
- test/test__helper.rb
|
145
|
-
- test/test_pool.rb
|
68
|
+
test_files: []
|