Bug 32612: (QA follow-up) Add missing interface for Logger
[koha-ffzg.git] / misc / load_testing / benchmark_webservices.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 #Usage:
5 # perl testKohaWS.pl http://eowyn.metavore.com:8001/cgi-bin/koha/svc cfc cfc 0.5 5 records/xml/xml-recs.xml
6 #
7 # POSTs to baseurl x number of times with y secs of delay between POSTs
8 #
9 # args:
10 # http://eowyn.metavore.com:8001/cgi-bin/koha/svc = baseurl
11 # 1st cfc = userid
12 # 2nd cfc = pw
13 # 0.5 = sleep(0.5) between POSTs
14 # 5 = number of times to poast
15 # records/xml/xml-recs.xml = file of 1 marcxml record to post
16 #
17 # Requires LWP::UserAgent, File::Slurp.
18 use LWP::UserAgent;
19 use File::Slurp qw( slurp );
20 my $ua = LWP::UserAgent->new();
21 $ua->cookie_jar({ file =>"cookies.txt" });
22 my $baseurl = shift;
23 my $userid = shift;
24 my $password = shift;
25 my $timeout = shift;
26 my $timestopost = shift;
27 my $xmlfile = shift;
28
29 my $xmldoc = slurp($xmlfile) or die $!;
30 # auth
31 my $resp = $ua->post( $baseurl . '/authentication' , {userid =>$userid, password => $password} );
32 if( $resp->is_success ) {
33         print "Auth:\n";
34         print $resp->content;
35 }
36 else {
37         die $resp->status_line;
38 }
39
40 for( my $i = 0; $i < $timestopost; $i++) {
41         warn "posting a bib number $i\n";
42         #warn "xmldoc to post: $xmldoc\n";
43         my $resp = $ua->post( $baseurl . '/new_bib' , 'Content-type' => 'text/xml', Content => $xmldoc );
44         if( $resp->is_success ) {
45                 print "post to new_bib response:\n";
46                 print $resp->content;
47         }
48         else {
49                 die $resp->status_line;
50         }
51         sleep($timeout);
52 }
53
54