Skip to content

Commit f50ff87

Browse files
committed
Modernize code.
1 parent 4285829 commit f50ff87

23 files changed

+221
-128
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Documentation Coverage
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
CONSOLE_OUTPUT: XTerm
10+
COVERAGE: PartialSummary
11+
12+
jobs:
13+
validate:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: "3.3"
21+
bundler-cache: true
22+
23+
- name: Validate coverage
24+
timeout-minutes: 5
25+
run: bundle exec bake decode:index:coverage lib

.github/workflows/rubocop.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: RuboCop
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
CONSOLE_OUTPUT: XTerm
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: ruby
20+
bundler-cache: true
21+
22+
- name: Run RuboCop
23+
timeout-minutes: 10
24+
run: bundle exec rubocop

.github/workflows/coverage.yaml .github/workflows/test-coverage.yaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Coverage
1+
name: Test Coverage
22

33
on: [push, pull_request]
44

@@ -33,9 +33,11 @@ jobs:
3333
- name: Run tests
3434
timeout-minutes: 5
3535
run: bundle exec bake test
36-
37-
- uses: actions/upload-artifact@v3
36+
37+
- uses: actions/upload-artifact@v4
3838
with:
39+
include-hidden-files: true
40+
if-no-files-found: error
3941
name: coverage-${{matrix.os}}-${{matrix.ruby}}
4042
path: .covered.db
4143

@@ -50,7 +52,7 @@ jobs:
5052
ruby-version: "3.3"
5153
bundler-cache: true
5254

53-
- uses: actions/download-artifact@v3
55+
- uses: actions/download-artifact@v4
5456

5557
- name: Validate coverage
5658
timeout-minutes: 5

.rubocop.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
AllCops:
2+
DisabledByDefault: true
3+
4+
Layout/IndentationStyle:
5+
Enabled: true
6+
EnforcedStyle: tabs
7+
8+
Layout/InitialIndentation:
9+
Enabled: true
10+
11+
Layout/IndentationWidth:
12+
Enabled: true
13+
Width: 1
14+
15+
Layout/IndentationConsistency:
16+
Enabled: true
17+
EnforcedStyle: normal
18+
19+
Layout/BlockAlignment:
20+
Enabled: true
21+
22+
Layout/EndAlignment:
23+
Enabled: true
24+
EnforcedStyleAlignWith: start_of_line
25+
26+
Layout/BeginEndAlignment:
27+
Enabled: true
28+
EnforcedStyleAlignWith: start_of_line
29+
30+
Layout/ElseAlignment:
31+
Enabled: true
32+
33+
Layout/DefEndAlignment:
34+
Enabled: true
35+
36+
Layout/CaseIndentation:
37+
Enabled: true
38+
39+
Layout/CommentIndentation:
40+
Enabled: true
41+
42+
Layout/EmptyLinesAroundClassBody:
43+
Enabled: true
44+
45+
Layout/EmptyLinesAroundModuleBody:
46+
Enabled: true
47+
48+
Style/FrozenStringLiteralComment:
49+
Enabled: true
50+
51+
Style/StringLiterals:
52+
Enabled: true
53+
EnforcedStyle: double_quotes

benchmark-http.gemspec

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
1010
spec.authors = ["Samuel Williams", "Olle Jonsson"]
1111
spec.license = "MIT"
1212

13-
spec.cert_chain = ['release.cert']
14-
spec.signing_key = File.expand_path('~/.gem/release.pem')
13+
spec.cert_chain = ["release.cert"]
14+
spec.signing_key = File.expand_path("~/.gem/release.pem")
1515

1616
spec.homepage = "https://github.com/socketry/benchmark-http"
1717

@@ -20,15 +20,14 @@ Gem::Specification.new do |spec|
2020
"source_code_uri" => "https://github.com/socketry/benchmark-http.git",
2121
}
2222

23-
spec.files = Dir.glob(['{bin,lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)
23+
spec.files = Dir.glob(["{bin,lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)
2424

2525
spec.executables = ["benchmark-http"]
2626

2727
spec.required_ruby_version = ">= 3.1"
2828

2929
spec.add_dependency "async-await"
30-
spec.add_dependency "async-http", "~> 0.54"
31-
spec.add_dependency "async-io", "~> 1.5"
30+
spec.add_dependency "async-http", "~> 0.83"
3231
spec.add_dependency "console"
3332
spec.add_dependency "samovar", "~> 2.0"
3433
spec.add_dependency "xrb-sanitize"

bin/benchmark-http

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
23

34
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
45
#
@@ -20,7 +21,7 @@
2021
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2122
# THE SOFTWARE.
2223

23-
require_relative '../lib/benchmark/http'
24+
require_relative "../lib/benchmark/http"
2425

2526
begin
2627
Benchmark::HTTP::Command.call

config/sus.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2022, by Samuel Williams.
4+
# Copyright, 2022-2024, by Samuel Williams.
55

6-
require 'covered/sus'
6+
require "covered/sus"
77
include Covered::Sus

fixtures/disable_console_context.rb

-17
This file was deleted.

gems.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2018-2022, by Samuel Williams.
4+
# Copyright, 2018-2024, by Samuel Williams.
55

6-
source 'https://rubygems.org'
6+
source "https://rubygems.org"
77

88
gemspec
99

@@ -17,6 +17,10 @@
1717
group :test do
1818
gem "sus"
1919
gem "covered"
20+
gem "decode"
21+
gem "rubocop"
22+
23+
gem "sus-fixtures-console"
2024

2125
gem "bake-test"
2226
gem "bake-test-external"

lib/benchmark/http/command.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2018-2022, by Samuel Williams.
4+
# Copyright, 2018-2024, by Samuel Williams.
55

6-
require_relative 'command/latency'
7-
require_relative 'command/concurrency'
8-
require_relative 'command/spider'
9-
require_relative 'command/hammer'
10-
require_relative 'command/wait'
6+
require_relative "command/latency"
7+
require_relative "command/concurrency"
8+
require_relative "command/spider"
9+
require_relative "command/hammer"
10+
require_relative "command/wait"
1111

12-
require_relative 'version'
13-
require 'samovar'
14-
require 'console'
12+
require_relative "version"
13+
require "samovar"
14+
require "console"
1515

1616
module Benchmark
1717
module HTTP
@@ -24,17 +24,17 @@ class Top < Samovar::Command
2424
self.description = "An asynchronous HTTP server benchmark."
2525

2626
options do
27-
option '--verbose | --quiet', "Verbosity of output for debugging.", key: :logging
28-
option '-h/--help', "Print out help information."
29-
option '-v/--version', "Print out the application version."
27+
option "--verbose | --quiet", "Verbosity of output for debugging.", key: :logging
28+
option "-h/--help", "Print out help information."
29+
option "-v/--version", "Print out the application version."
3030
end
3131

3232
nested :command, {
33-
'latency' => Latency,
34-
'concurrency' => Concurrency,
35-
'spider' => Spider,
36-
'hammer' => Hammer,
37-
'wait' => Wait,
33+
"latency" => Latency,
34+
"concurrency" => Concurrency,
35+
"spider" => Spider,
36+
"hammer" => Hammer,
37+
"wait" => Wait,
3838
}
3939

4040
def verbose?

lib/benchmark/http/command/concurrency.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2018-2022, by Samuel Williams.
4+
# Copyright, 2018-2024, by Samuel Williams.
55

6-
require_relative '../seconds'
7-
require_relative '../statistics'
6+
require_relative "../seconds"
7+
require_relative "../statistics"
88

9-
require 'async'
10-
require 'async/http/client'
11-
require 'async/http/endpoint'
9+
require "async"
10+
require "async/http/client"
11+
require "async/http/endpoint"
1212

13-
require 'samovar'
13+
require "samovar"
1414

1515
module Benchmark
1616
module HTTP
@@ -19,9 +19,9 @@ class Concurrency < Samovar::Command
1919
self.description = "Determine the optimal level of concurrency."
2020

2121
options do
22-
option '-t/--threshold <factor>', "The acceptable latency penalty when making concurrent requests", default: 1.2, type: Float
23-
option '-c/--confidence <factor>', "The confidence required when computing latency (lower is less reliable but faster)", default: 0.99, type: Float
24-
option '-m/--minimum <count>', "The minimum number of connections to make", default: 1, type: Integer
22+
option "-t/--threshold <factor>", "The acceptable latency penalty when making concurrent requests", default: 1.2, type: Float
23+
option "-c/--confidence <factor>", "The confidence required when computing latency (lower is less reliable but faster)", default: 0.99, type: Float
24+
option "-m/--minimum <count>", "The minimum number of connections to make", default: 1, type: Integer
2525
end
2626

2727
many :hosts, "One or more hosts to benchmark"

lib/benchmark/http/command/hammer.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2020-2022, by Samuel Williams.
4+
# Copyright, 2020-2024, by Samuel Williams.
55

6-
require_relative '../seconds'
7-
require_relative '../statistics'
6+
require_relative "../seconds"
7+
require_relative "../statistics"
88

9-
require 'async'
10-
require 'async/http/client'
11-
require 'async/http/endpoint'
9+
require "async"
10+
require "async/http/client"
11+
require "async/http/endpoint"
1212

13-
require 'samovar'
13+
require "samovar"
1414

1515
module Benchmark
1616
module HTTP
@@ -20,10 +20,10 @@ class Hammer < Samovar::Command
2020

2121
options do
2222
option "-k/--concurrency <count>", "The number of simultaneous connections to make.", default: 1, type: Integer
23-
option '-c/--count <integer>', "The number of requests to make per connection.", default: 10_000, type: Integer
23+
option "-c/--count <integer>", "The number of requests to make per connection.", default: 10_000, type: Integer
2424

25-
option '-i/--interval <integer>', "The time to wait between measurements.", default: nil, type: Integer
26-
option '--alpn-protocols <name,name>', "Force specific ALPN protocols during connection negotiation.", default: nil, type: String
25+
option "-i/--interval <integer>", "The time to wait between measurements.", default: nil, type: Integer
26+
option "--alpn-protocols <name,name>", "Force specific ALPN protocols during connection negotiation.", default: nil, type: String
2727
end
2828

2929
many :urls, "The urls to hammer."
@@ -70,7 +70,7 @@ def measure_performance(concurrency, count, endpoint, request_path)
7070
end
7171

7272
def alpn_protocols
73-
@options[:alpn_protocols]&.split(',')
73+
@options[:alpn_protocols]&.split(",")
7474
end
7575

7676
def run(url)

lib/benchmark/http/command/latency.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2019-2022, by Samuel Williams.
4+
# Copyright, 2019-2024, by Samuel Williams.
55

6-
require_relative '../seconds'
7-
require_relative '../statistics'
6+
require_relative "../seconds"
7+
require_relative "../statistics"
88

9-
require 'async'
10-
require 'async/http/client'
11-
require 'async/http/endpoint'
9+
require "async"
10+
require "async/http/client"
11+
require "async/http/endpoint"
1212

13-
require 'samovar'
13+
require "samovar"
1414

1515
module Benchmark
1616
module HTTP
@@ -20,7 +20,7 @@ class Latency < Samovar::Command
2020

2121
options do
2222
option "-k/--concurrency <count>", "The number of simultaneous connections to make.", default: 1, type: Integer
23-
option '-c/--confidence <factor>', "The confidence required when computing latency (lower is less reliable but faster)", default: 0.99, type: Float
23+
option "-c/--confidence <factor>", "The confidence required when computing latency (lower is less reliable but faster)", default: 0.99, type: Float
2424
end
2525

2626
many :hosts, "One or more hosts to benchmark"

0 commit comments

Comments
 (0)