LP#1729610: Add a service useful for testing behavior in slow response conditions
authorMike Rylander <mrylander@gmail.com>
Wed, 1 Nov 2017 15:11:08 +0000 (11:11 -0400)
committerMike Rylander <mrylander@gmail.com>
Fri, 4 Jan 2019 19:06:37 +0000 (14:06 -0500)
This service, opensrf.slooooooow, offers a opensrf.slooooooow.wait method
that waits for the number of seconds specified in its sole parameter.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
examples/opensrf.xml.example
src/perl/lib/OpenSRF/Application/Slooooooow.pm [new file with mode: 0644]

index 7e1dccb..2e52c7a 100644 (file)
@@ -183,6 +183,24 @@ vim:et:ts=2:sw=2:
         </unix_config>
       </opensrf.settings>
 
+      <opensrf.slooooooow>
+        <keepalive>1</keepalive>
+        <stateless>1</stateless>
+        <language>perl</language>
+        <implementation>OpenSRF::Application::Slooooooow</implementation>
+        <max_requests>100</max_requests>
+        <unix_config>
+          <unix_sock>opensrf.slooooooow_unix.sock</unix_sock>
+          <unix_pid>opensrf.slooooooow_unix.pid</unix_pid>
+          <max_requests>1000</max_requests>
+          <unix_log>opensrf.slooooooow_unix.log</unix_log>
+          <min_children>2</min_children>
+          <max_children>5</max_children>
+          <min_spare_children>1</min_spare_children>
+          <max_spare_children>2</max_spare_children>
+        </unix_config>
+      </opensrf.slooooooow>
+
       <opensrf.validator>
         <keepalive>1</keepalive>
         <stateless>1</stateless>
@@ -242,6 +260,7 @@ vim:et:ts=2:sw=2:
         <appname>opensrf.math</appname>
         <appname>opensrf.dbmath</appname>
         <appname>opensrf.validator</appname>
+        <appname>opensrf.slooooooow</appname>
       </activeapps>
 
       <apps>
diff --git a/src/perl/lib/OpenSRF/Application/Slooooooow.pm b/src/perl/lib/OpenSRF/Application/Slooooooow.pm
new file mode 100644 (file)
index 0000000..bf218ce
--- /dev/null
@@ -0,0 +1,48 @@
+package OpenSRF::Application::Slooooooow;
+use base qw/OpenSRF::Application/;
+use OpenSRF::Application;
+
+use OpenSRF::Utils::SettingsClient;
+use OpenSRF::EX qw/:try/;
+use OpenSRF::Utils qw/:common/;
+use OpenSRF::Utils::Logger;
+
+my $log;
+
+sub initialize {
+    $log = 'OpenSRF::Utils::Logger';
+}
+
+sub child_init {}
+
+sub wait_for_it {
+    my $self = shift;
+    my $client = shift;
+    my $pause = shift;
+
+    $pause =~ s/\D//g if (defined $pause);
+    $pause //= 1;
+
+    $log->info("Holding for $pause seconds...");
+    sleep($pause);
+    $log->info("Done waiting, time to return.");
+    return [$pause, @_]
+}
+__PACKAGE__->register_method(
+    api_name        => 'opensrf.slooooooow.wait',
+    method          => 'wait_for_it',
+    argc            => 1,
+    signature       => {
+        params => [
+            {name => "pause", type => "number", desc => "Seconds to sleep, can be fractional"},
+            {name => "extra", type => "string", desc => "Extra optional parameter used to inflate the payload size"}
+        ],
+        return => {
+            desc => "Array of passed parameters",
+            type => "array"
+        }
+    }
+
+);
+
+1;