The opensrf.test.random_delay_echo takes two arguments, a string
and a value for the maximum delay, measured in milliseconds. It
returns a string after a random delay bounded by the specified
maximum.
The test program is invoked like this:
exercise_multi_infinite.pl /path/to/opensrf_core.xml numparallel numdelay numechos.
E.g.,
./exercise_multi_infinite.pl /openils/conf/opensrf_core.xml 7 1 10
It uses MultiSession to call the opensrf.test.random_delay_echo service
with the specified delay, number of parallel sessions, and total number
of echo calls to make, then repeats that until cancelled. If the
deadlock is encountered, it stops emitting output.
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use OpenSRF::Utils::JSON;
+use OpenSRF::System;
+use OpenSRF::Utils::SettingsClient;
+use OpenSRF::MultiSession;
+
+my $config = shift || die "bootstrap config required\n";
+OpenSRF::System->bootstrap_client( config_file => $config );
+
+my $parallel = shift;
+my $max_delay = shift;
+my $calls = shift;
+
+$| = 0;
+
+my $multi = OpenSRF::MultiSession->new(
+ app => 'opensrf.test',
+ cap => $parallel,
+ api_level => 1,
+ success_handler => sub {
+ my($self, $req) = @_;
+ my $data = $req->{response}->[0]->content;
+ print "Got back $data\n";
+ },
+);
+
+my $j = 0;
+while (1) {
+ $j++;
+ print "Run $j\n";
+ for my $i (1..$calls) {
+ $multi->request( 'opensrf.test.random_delay_echo', $i, $max_delay);
+ }
+ $multi->session_wait(1);
+}
+$multi->disconnect;
--- /dev/null
+package OpenSRF::Application::Test;
+
+use strict;
+use warnings;
+
+use base qw/OpenSRF::Application/;
+use OpenSRF::Application;
+use OpenSRF::Utils::SettingsClient;
+use OpenSRF::Utils::Logger;
+use Time::HiRes qw/usleep/;
+
+sub initialize {
+ __PACKAGE__->register_method(
+ api_name => 'opensrf.test.random_delay_echo',
+ method => 'do_random_delay_echo',
+ argc => 2,
+ );
+}
+
+sub do_random_delay_echo {
+ my $self = shift;
+ my $client = shift;
+
+ my $str = shift;
+ my $max_delay = shift;
+ $max_delay = 0 unless defined $max_delay and $max_delay =~ /^\d+$/;
+ # we're expecting the maximum delay to be specified in milliseconds
+ $max_delay *= 1000;
+
+ if ($max_delay > 0) {
+ usleep(int(rand($max_delay)));
+ }
+ return $str;
+}