[otrs-cvs] otrs/scripts/test/GenericInterface/Event Handler.t, 1.9.2.1, 1.9.2.2

"CVS commits notifications of OTRS.org" <[email protected]>
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/otrs/scripts/test/GenericInterface/Event
In directory lancelot:/tmp/cvs-serv25504/scripts/test/GenericInterface/Event

Modified Files:
      Tag: rel-3_1
	Handler.t 
Log Message:
Added more stability to the test for systems with stopped but still registered scheduler process, and systems with high IO load.

Author: cr

Index: Handler.t
===================================================================
RCS file: /home/cvs/otrs/scripts/test/GenericInterface/Event/Handler.t,v
retrieving revision 1.9.2.1
retrieving revision 1.9.2.2
diff -2 -u -d -r1.9.2.1 -r1.9.2.2
--- Handler.t	12 Nov 2012 09:59:43 -0000	1.9.2.1
+++ Handler.t	9 Dec 2012 04:29:10 -0000	1.9.2.2
@@ -7,5 +7,5 @@
 # This software comes with ABSOLUTELY NO WARRANTY. For details, see
 # the enclosed file COPYING for license information (AGPL). If you
-# did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.
+# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
 # --
 
@@ -20,4 +20,5 @@
 use Kernel::System::GenericInterface::DebugLog;
 use Kernel::System::Ticket;
+use Kernel::System::Scheduler::TaskManager;
 use Kernel::System::UnitTest::Helper;
 
@@ -39,4 +40,8 @@
     ConfigObject => $ConfigObject,
 );
+my $TaskManagerObject = Kernel::System::Scheduler::TaskManager->new(
+    %{$Self},
+    ConfigObject => $ConfigObject,
+);
 
 my @Tests = (
@@ -264,10 +269,41 @@
 
 if ( $PreviousSchedulerStatus =~ /^not running/i ) {
-    my $Result = system("$Scheduler -a start -f 1");
+    if ( $PreviousSchedulerStatus =~ m{registered}i ) {
+
+        # force stop
+        `$Scheduler -a stop -f 1`;
+        $Self->True(
+            1,
+            "Force stoping due to bad status...",
+        );
+
+        # Wait for slow systems
+        my $SleepTime = 120;
+        print "Waiting at most $SleepTime s until scheduler stops\n";
+        ACTIVESLEEP:
+        for my $Seconds ( 1 .. $SleepTime ) {
+            my $SchedulerStatus = `$Scheduler -a status`;
+            if ( $SchedulerStatus !~ m{\A running }msxi ) {
+                last ACTIVESLEEP;
+            }
+            print "Sleeping for $Seconds seconds...\n";
+            sleep 1;
+        }
+    }
+
+    my $ResultMessage = `$Scheduler -a start 2>&1`;
     $Self->Is(
-        $Result,
+        $?,
         0,
         "Scheduler start call returned successfully.",
     );
+
+    # give some visibility if the test fail when it should not
+    if ($?) {
+        $Self->True(
+            0,
+            "Scheduler start DETECTED $ResultMessage",
+        );
+    }
 }
 else {
@@ -278,8 +314,21 @@
 }
 
+# Wait for slow systems
+my $SleepTime = 120;
+print "Waiting at most $SleepTime s until scheduler stops\n";
+ACTIVESLEEP:
+for my $Seconds ( 1 .. $SleepTime ) {
+    my $SchedulerStatus = `$Scheduler -a status`;
+    if ( $SchedulerStatus =~ m{\A running }msxi ) {
+        last ACTIVESLEEP;
+    }
+    print "Sleeping for $Seconds seconds...\n";
+    sleep 1;
+}
+
 my $CurrentSchedulerStatus = `$Scheduler -a status`;
 
 $Self->True(
-    $CurrentSchedulerStatus =~ /^running/i,
+    int $CurrentSchedulerStatus =~ /^running/i,
     "Scheduler is running",
 );
@@ -288,4 +337,5 @@
     die "Scheduler could not be started.";
 }
+
 for my $Test (@Tests) {
 
@@ -337,7 +387,33 @@
         $Self->True(
             1,
-            "Sleeping 15s to let the scheduler process the tasks...",
+            "Sleeping 2s to make sure that asynchronous tasks are registered...",
         );
-        sleep 15;
+        sleep 2;
+
+        my $TotalWaitToExecute = 120;
+
+        # wait for scheduler to execute tasks
+        WAITEXECUTE:
+        for my $Wait ( 1 .. $TotalWaitToExecute ) {
+            print "Waiting for Scheduler to execute tasks, $Wait seconds\n";
+            sleep 1;
+
+            my @List = $TaskManagerObject->TaskList();
+
+            if ( scalar @List eq 0 ) {
+                $Self->True(
+                    1,
+                    "$Test->{Name} - all tasks are dropped from task list",
+                );
+                last WAITEXECUTE;
+            }
+
+            next WAITEXECUTE if $Wait < $TotalWaitToExecute;
+
+            $Self->True(
+                0,
+                "$Test->{Name} - all tasks are not dropped from task list after $TotalWaitToExecute seconds!",
+            );
+        }
     }
 
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.