complete error timeout handling for all tests
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test.pm
index 7cd0a18..0bf89bd 100644 (file)
@@ -1,4 +1,3 @@
-# $Id: Test.pm,v 1.6 2006-10-13 10:08:57 sondberg Exp $
 
 package ZOOM::IRSpy::Test;
 
@@ -6,8 +5,10 @@ use 5.008;
 use strict;
 use warnings;
 
+use Scalar::Util;
+
 use Exporter 'import';
-our @EXPORT = qw(isodate);
+our @EXPORT = qw(zoom_error_timeout_update zoom_error_timeout_check); 
 
 =head1 NAME
 
@@ -23,8 +24,11 @@ I<## To follow>
 
 =cut
 
+
 sub subtests { () }
 
+sub timeout { undef }
+
 sub start {
     my $class = shift();
     my($conn) = @_;
@@ -33,16 +37,28 @@ sub start {
 }
 
 
+our $max_timeout_errors = $ZOOM::IRSpy::max_timeout_errors;
 
-# Utility function, really nothing to do with IRSpy
-sub isodate {
-    my($time) = @_;
+sub zoom_error_timeout_update {
+    my ($conn, $exception) = @_;
 
-    my($sec, $min, $hour, $mday, $mon, $year) = localtime($time);
-    return sprintf("%04d-%02d-%02dT%02d:%02d:%02d",
-                  $year+1900, $mon+1, $mday, $hour, $min, $sec);
+    if ($exception =~ /Timeout/i) {
+        $conn->record->zoom_error->{TIMEOUT}++;
+        $conn->log("irspy_test", "Increase timeout error counter to: " .
+                $conn->record->zoom_error->{TIMEOUT});
+    }
 }
 
+sub zoom_error_timeout_check {
+    my $conn = shift;
+
+    if ($conn->record->zoom_error->{TIMEOUT} >= $max_timeout_errors) {
+        $conn->log("irspy_test", "Got $max_timeout_errors or more timeouts, give up...");
+        return  1;
+    }
+
+    return 0;
+}
 
 =head1 SEE ALSO