diff options
author | Bruno Wagner <bwagner@riseup.net> | 2016-09-09 18:52:59 -0300 |
---|---|---|
committer | Bruno Wagner <bwagner@riseup.net> | 2016-09-09 18:55:04 -0300 |
commit | 69cbc6713bb156a845e9a616b35927cfce8cf70c (patch) | |
tree | b35003f8b4569e7309ec5323de4229af3923cb6b | |
parent | 08a2febbe4d85f607356af7c073c3531a1722eca (diff) |
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)
-rw-r--r-- | service/test/reactor/concurrent_logins.rb | 63 |
1 files changed, 50 insertions, 13 deletions
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 <x>` +# This can be run with `ruby concurrent_logins.rb <x>` # 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 |