From 69cbc6713bb156a845e9a616b35927cfce8cf70c Mon Sep 17 00:00:00 2001 From: Bruno Wagner Date: Fri, 9 Sep 2016 18:52:59 -0300 Subject: Adapted the concurrent_logins.rb to measure the loading page It now requests using the same session that it logs in until the user arrives at the inbox (denoted by the compose-trigger showing up on the html in this case) --- service/test/reactor/concurrent_logins.rb | 63 ++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 13 deletions(-) (limited to 'service/test/reactor') diff --git a/service/test/reactor/concurrent_logins.rb b/service/test/reactor/concurrent_logins.rb index 0af2c5b7..38bdac5f 100644 --- a/service/test/reactor/concurrent_logins.rb +++ b/service/test/reactor/concurrent_logins.rb @@ -5,31 +5,68 @@ # -ruby # -pre-created users # -# This can be run with `ruby blocking_spawner ` +# This can be run with `ruby concurrent_logins.rb ` # where x is the number of users you want to login. # # It was created to measure login times internally on the application with # varying number of users +require 'pry' USER_PATTERN = "loadtest%d" PASSWORD_PATTERN = "password_%d" COUNT = ARGV[0].to_i -def curl_command(index) - username = USER_PATTERN % [index] - password = PASSWORD_PATTERN % [index] - "curl --silent -X POST --data 'username=#{username}&password=#{password}' --cookie 'XSRF-TOKEN: blablabla' --header 'X-Requested-With: XMLHttpRequest' --header 'X-XSRF-TOKEN: blablabla' http://localhost:3333/login" +def header_options + "--header 'X-Requested-With: XMLHttpRequest' --header 'X-XSRF-TOKEN: blablabla'" end -ts = (1...(1+COUNT)).map do |ix| - t = Thread.new do - time = Time.now() - `#{curl_command(ix)}` - puts "Request time: #{Time.now() - time}" +def cookies + "--cookie 'XSRF-TOKEN: blablabla'" +end + +def curl_command + "curl --silent" +end + +def login_command(user_index, username, password) + FileUtils.rm "/tmp/user#{user_index}.cookie", force: true + "#{curl_command} -X POST --data 'username=#{username}&password=#{password}' --cookie-jar /tmp/user#{user_index}.cookie -w '%{http_code}|%{time_total}' --output '/dev/null' #{cookies} #{header_options} http://localhost:3333/login" +end + +def check_inbox(user_index) + "#{curl_command} --cookie /tmp/user#{user_index}.cookie http://localhost:3333" +end + +def complete_login(user_index, user, password) + start = Time.now + login_response = `#{login_command(user_index, user, password)}` + status_code, total_time = login_response.split("|") + puts "Login request #{total_time}" + if status_code.to_i == 200 + interstitial = Time.now + begin + inbox = `#{check_inbox(user_index)}` + end until /compose-trigger/.match(inbox) + puts "Login loading #{sprintf('%.3f',Time.now - interstitial)}" + puts "Login total #{sprintf('%.3f',Time.now - start)}" + else + puts "Login failed with #{status_code} #{sprintf('%.3f',Time.now - start)}" + end +end + +def multi_login + ts = (1...(1+COUNT)).map do |user_index| + t = Thread.new do + username = USER_PATTERN % [user_index] + password = PASSWORD_PATTERN % [user_index] + complete_login(user_index, username, password) + end + sleep 1 + t end - sleep 1 - t + + ts.each(&:join) end -ts.each(&:join) +multi_login -- cgit v1.2.3