TestRoots /
watchdog
| 1 | #!/usr/bin/env ruby |
||
| 2 | |||
| 3 | #require 'parallel' |
||
| 4 | require 'rest_client' |
||
| 5 | require 'json' |
||
| 6 | |||
| 7 | View Code Duplication | def test_user |
|
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
| 8 | user = Hash.new |
||
| 9 | user['email'] = '[email protected]' |
||
| 10 | user['name'] = 'Foo Bar' |
||
| 11 | user['org'] = 'Baz B.V.' |
||
| 12 | user['org_website'] = 'http://baz.nl' |
||
| 13 | user['prize'] = false |
||
| 14 | user |
||
| 15 | end |
||
| 16 | |||
| 17 | View Code Duplication | def test_project(user_id) |
|
|
0 ignored issues
–
show
|
|||
| 18 | project = Hash.new |
||
| 19 | project['name'] = 'Foo Bar Proj' |
||
| 20 | project['role'] = 'Foo Barer' |
||
| 21 | project['belongToASingleSofware'] = true |
||
| 22 | project['usesJunit'] = true |
||
| 23 | project['usesOtherFrameworks'] = false |
||
| 24 | project['productionPercentage'] = 50 |
||
| 25 | project['useJunitOnlyForUnitTesting'] = false |
||
| 26 | project['followTestDrivenDesign'] = false |
||
| 27 | project['userId'] = user_id |
||
| 28 | project |
||
| 29 | end |
||
| 30 | |||
| 31 | def interval |
||
| 32 | |||
| 33 | int = rand(1..2**32 - 50) |
||
| 34 | |||
| 35 | [{ |
||
| 36 | :doc => { |
||
| 37 | "pn" => "foobar", |
||
| 38 | "fn" => "debug.rel", |
||
| 39 | "sloc" => rand(1 .. 50), |
||
| 40 | "dt" => "un" |
||
| 41 | }, |
||
| 42 | |||
| 43 | :it => "re", |
||
| 44 | :ts => int, |
||
| 45 | :te => int + rand(1..50), |
||
| 46 | :ss => rand(1..2**32 - 1), |
||
| 47 | :wdv => "1.0-SNAPSHOT" |
||
| 48 | }] |
||
| 49 | end |
||
| 50 | |||
| 51 | # Configuration params |
||
| 52 | username = "watchdogplugin" |
||
| 53 | passwd = "hnspqsznpq" |
||
| 54 | urlbase = "http://#{username}:#{passwd}@watchdog.testroots.org" |
||
| 55 | num_intervals = 10000 |
||
| 56 | |||
| 57 | #create test user |
||
| 58 | @user_id = RestClient.post(urlbase + '/user', test_user.to_json) |
||
| 59 | puts "user_id=#{@user_id}" |
||
| 60 | |||
| 61 | #create test project |
||
| 62 | @pid = RestClient.post(urlbase + '/project', test_project(@user_id).to_json) |
||
| 63 | puts "pid=#{@pid}" |
||
| 64 | |||
| 65 | loader = Proc.new do |req_id| |
||
| 66 | resp = RestClient.post(urlbase + "/user/#{@user_id}/#{@pid}/intervals", |
||
| 67 | interval.to_json) |
||
| 68 | puts "Req id: #{req_id}, resp: #{resp}" |
||
| 69 | end |
||
| 70 | |||
| 71 | start = Time.now.to_i |
||
| 72 | |||
| 73 | #Parallel.map((1..num_intervals), :in_threads => 30) do |req| |
||
| 74 | # loader.call(req) |
||
| 75 | #end |
||
| 76 | |||
| 77 | delta = Time.now.to_i - start |
||
| 78 | #puts "#{num_intervals} intervals in #{delta} secs #{(num_intervals/delta).to_f} intervals per sec" |
||
| 79 | |||
| 80 | # Test how many intervals can se send at once |
||
| 81 | many_intervals = (1..20000).map do |x| |
||
| 82 | interval()[0] |
||
| 83 | end |
||
| 84 | |||
| 85 | RestClient.post(urlbase + "/user/#{@user_id}/#{@pid}/intervals", many_intervals.to_json) |
||
| 86 |