TEST: test service and program to invoke MultiSession deadlock
authorGalen Charlton <gmc@esilibrary.com>
Sun, 17 Mar 2013 04:53:57 +0000 (21:53 -0700)
committerGalen Charlton <gmc@esilibrary.com>
Sun, 17 Mar 2013 04:53:57 +0000 (21:53 -0700)
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>
exercise_multi_infinite.pl [new file with mode: 0755]
src/perl/lib/OpenSRF/Application/Test.pm [new file with mode: 0644]

diff --git a/exercise_multi_infinite.pl b/exercise_multi_infinite.pl
new file mode 100755 (executable)
index 0000000..6b62416
--- /dev/null
@@ -0,0 +1,39 @@
+#!/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;
diff --git a/src/perl/lib/OpenSRF/Application/Test.pm b/src/perl/lib/OpenSRF/Application/Test.pm
new file mode 100644 (file)
index 0000000..aedd678
--- /dev/null
@@ -0,0 +1,34 @@
+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;
+}