Skip to content

Commit 2943eaf

Browse files
committed
Handle empty inputs correctly
1 parent 24ef5a3 commit 2943eaf

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

.github/workflows/benchmark.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ env:
7272
FORTIO_VERSION: "1.73.0"
7373
K6_VERSION: "1.3.0"
7474
VEGETA_VERSION: "12.13.0"
75-
# Benchmark parameters
75+
# Benchmark parameters (defaults in bench.rb unless overridden here for CI)
7676
ROUTES: ${{ github.event.inputs.routes }}
7777
RATE: ${{ github.event.inputs.rate || 'max' }}
78-
DURATION: ${{ github.event.inputs.duration || '30s' }}
79-
REQUEST_TIMEOUT: ${{ github.event.inputs.request_timeout || '60s' }}
80-
CONNECTIONS: ${{ github.event.inputs.connections || 10 }}
81-
MAX_CONNECTIONS: ${{ github.event.inputs.connections || 10 }}
78+
DURATION: ${{ github.event.inputs.duration }}
79+
REQUEST_TIMEOUT: ${{ github.event.inputs.request_timeout }}
80+
CONNECTIONS: ${{ github.event.inputs.connections }}
81+
MAX_CONNECTIONS: ${{ github.event.inputs.connections }}
8282
WEB_CONCURRENCY: ${{ github.event.inputs.web_concurrency || 4 }}
8383
RAILS_MAX_THREADS: ${{ github.event.inputs.rails_threads || 3 }}
8484
RAILS_MIN_THREADS: ${{ github.event.inputs.rails_threads || 3 }}
85-
TOOLS: ${{ github.event.inputs.tools || 'fortio,vegeta,k6' }}
85+
TOOLS: ${{ github.event.inputs.tools }}
8686

8787
jobs:
8888
benchmark:

spec/performance/bench.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,30 @@
77
require "net/http"
88
require "uri"
99

10+
# Helper to get env var with default,
11+
# treating empty string and "0" as unset since they can come from the benchmark workflow.
12+
def env_or_default(key, default)
13+
value = ENV[key].to_s
14+
value.empty? || value == "0" ? default : value
15+
end
16+
1017
# Benchmark parameters
1118
PRO = ENV.fetch("PRO", "false") == "true"
1219
APP_DIR = PRO ? "react_on_rails_pro/spec/dummy" : "spec/dummy"
13-
ROUTES = ENV.fetch("ROUTES", nil)
14-
BASE_URL = ENV.fetch("BASE_URL", "localhost:3001")
20+
ROUTES = env_or_default("ROUTES", nil)
21+
BASE_URL = env_or_default("BASE_URL", "localhost:3001")
1522
# requests per second; if "max" will get maximum number of queries instead of a fixed rate
16-
RATE = ENV.fetch("RATE", "50")
23+
RATE = env_or_default("RATE", "50")
1724
# concurrent connections/virtual users
18-
CONNECTIONS = ENV.fetch("CONNECTIONS", "10").to_i
25+
CONNECTIONS = env_or_default("CONNECTIONS", 10).to_i
1926
# maximum connections/virtual users
20-
MAX_CONNECTIONS = ENV.fetch("MAX_CONNECTIONS", CONNECTIONS).to_i
27+
MAX_CONNECTIONS = env_or_default("MAX_CONNECTIONS", CONNECTIONS).to_i
2128
# benchmark duration (duration string like "30s", "1m", "90s")
22-
DURATION = ENV.fetch("DURATION", "30s")
29+
DURATION = env_or_default("DURATION", "30s")
2330
# request timeout (duration string as above)
24-
REQUEST_TIMEOUT = ENV.fetch("REQUEST_TIMEOUT", "60s")
31+
REQUEST_TIMEOUT = env_or_default("REQUEST_TIMEOUT", "60s")
2532
# Tools to run (comma-separated)
26-
TOOLS = ENV.fetch("TOOLS", "fortio,vegeta,k6").split(",")
33+
TOOLS = env_or_default("TOOLS", "fortio,vegeta,k6").split(",")
2734

2835
OUTDIR = "bench_results"
2936
SUMMARY_TXT = "#{OUTDIR}/summary.txt".freeze
@@ -93,11 +100,13 @@ def get_benchmark_routes(app_dir)
93100
# Get all routes to benchmark
94101
routes =
95102
if ROUTES
96-
ROUTES.split(",").map(&:strip)
103+
ROUTES.split(",").map(&:strip).reject(&:empty?)
97104
else
98105
get_benchmark_routes(APP_DIR)
99106
end
100107

108+
raise "No routes to benchmark" if routes.empty?
109+
101110
validate_rate(RATE)
102111
validate_positive_integer(CONNECTIONS, "CONNECTIONS")
103112
validate_positive_integer(MAX_CONNECTIONS, "MAX_CONNECTIONS")

0 commit comments

Comments
 (0)