add ?flakey=pct param to make the app return 500 errors intermittently
All checks were successful
Gitea Actions Demo / lint (push) Successful in 28s
Gitea Actions Demo / test (push) Successful in 16s
Gitea Actions Demo / release-image (push) Has been skipped

This commit is contained in:
Ryan Cavicchioni 2025-03-14 19:14:56 -05:00
parent e1f29b555c
commit 8b094d64b1
Signed by: ryanc
SSH Key Fingerprint: SHA256:KbXiwUnZnHFwFtt3Bytd+F3FN9pPHn1Z1cxMIE1TPbg

19
app.rb
View File

@ -23,6 +23,7 @@ require "config"
CHUNK_SIZE = 1024**2
SESSION_SECRET_HEX_LENGTH = 64
JWT_SECRET_HEX_LENGTH = 64
DEFAULT_FLAKEY = 50
ENV_PREFIX = "KUBERNAUT"
@ -207,6 +208,13 @@ Health.instance.up
Ready.instance.up
Sleep.instance.wake
def flaky(pct = DEFAULT_FLAKEY)
r = Random.rand(0..100)
unless r < (100 - pct)
halt 500, "so unreliable"
end
end
enable :sessions
configure do
@ -218,6 +226,17 @@ before do
sleep(1) while Sleep.instance.asleep? && request.path_info != "/livez/sleep"
content_type :text if request.path_info.start_with? "/_cat"
request.session_options[:skip] = !request.path_info.start_with?("/session")
if params.has_key? :flaky
begin
pct = Integer(params[:flaky])
pct = pct.clamp(0, 100)
rescue => e
logger.warn "#{e.message}: falling back to default flaky percentage of #{DEFAULT_FLAKEY}"
pct = DEFAULT_FLAKEY
end
flaky(pct)
end
end
helpers do