summaryrefslogtreecommitdiff
path: root/service/test/reactor/concurrent_logins.rb
blob: a10d03949b41a6cdfc435eccbdaf43212f9e07a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# We use this script to simulate the login of multiple concurrent users, with
# one login per second.
#
# To use it, you need:
# -ruby
# -pre-created users
#
# This can be run with `ruby blocking_spawner <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


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"
end

ts = (1...(1+COUNT)).map do |ix|
  t = Thread.new do
    `#{curl_command(ix)}`
  end
  sleep 1
  t
end

ts.each(&:join)