add ?flakey=pct param to make the app return 500 errors intermittently
	
		
			
	
		
	
	
				
					
				
			This commit is contained in:
		
							
								
								
									
										19
									
								
								app.rb
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								app.rb
									
									
									
									
									
								
							@@ -23,6 +23,7 @@ require "config"
 | 
				
			|||||||
CHUNK_SIZE = 1024**2
 | 
					CHUNK_SIZE = 1024**2
 | 
				
			||||||
SESSION_SECRET_HEX_LENGTH = 64
 | 
					SESSION_SECRET_HEX_LENGTH = 64
 | 
				
			||||||
JWT_SECRET_HEX_LENGTH = 64
 | 
					JWT_SECRET_HEX_LENGTH = 64
 | 
				
			||||||
 | 
					DEFAULT_FLAKEY = 50
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENV_PREFIX = "KUBERNAUT"
 | 
					ENV_PREFIX = "KUBERNAUT"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -207,6 +208,13 @@ Health.instance.up
 | 
				
			|||||||
Ready.instance.up
 | 
					Ready.instance.up
 | 
				
			||||||
Sleep.instance.wake
 | 
					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
 | 
					enable :sessions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
configure do
 | 
					configure do
 | 
				
			||||||
@@ -218,6 +226,17 @@ before do
 | 
				
			|||||||
  sleep(1) while Sleep.instance.asleep? && request.path_info != "/livez/sleep"
 | 
					  sleep(1) while Sleep.instance.asleep? && request.path_info != "/livez/sleep"
 | 
				
			||||||
  content_type :text if request.path_info.start_with? "/_cat"
 | 
					  content_type :text if request.path_info.start_with? "/_cat"
 | 
				
			||||||
  request.session_options[:skip] = !request.path_info.start_with?("/session")
 | 
					  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
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
helpers do
 | 
					helpers do
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user