Browse Source

* Add is_new boolean arg to AddTestResult, to e able to know
if the call really added a new result.

git-svn-id: trunk@14807 -

pierre 15 years ago
parent
commit
2646db8036
2 changed files with 40 additions and 11 deletions
  1. 8 3
      tests/utils/dbdigest.pp
  2. 32 8
      tests/utils/dbtests.pp

+ 8 - 3
tests/utils/dbdigest.pp

@@ -404,10 +404,12 @@ var
   TS,PrevTS : TTestStatus;
   ID,PrevID : integer;
   Testlog : string;
+  is_new : boolean;
 begin
   Assign(logfile,FN);
   PrevId:=-1;
   PrevLine:='';
+  is_new:=false;
   PrevTS:=low(TTestStatus);
 {$i-}
   reset(logfile);
@@ -429,7 +431,7 @@ begin
               is not followed by any other line about the same test }
             TestLog:='';
             AddTestResult(PrevID,TestRunId,ord(PrevTS),
-              TestOK[PrevTS],TestSkipped[PrevTS],TestLog);
+              TestOK[PrevTS],TestSkipped[PrevTS],TestLog,is_new);
             Verbose(V_Warning,'Orphaned test: "'+prevline+'"');
           end;
         PrevID:=-1;
@@ -446,9 +448,12 @@ begin
           { AddTestResult can fail for test that contain %recompile 
             as the same }
           if AddTestResult(ID,TestRunID,Ord(TS),TestOK[TS],
-               TestSkipped[TS],TestLog) <> -1 then
+               TestSkipped[TS],TestLog,is_new) <> -1 then
             begin
-              Inc(StatusCount[TS]);
+              if is_new then
+                Inc(StatusCount[TS])
+              else
+                Verbose(V_Debug,'Test: "'+line+'" was updated');
             end
           else
             begin

+ 32 - 8
tests/utils/dbtests.pp

@@ -28,7 +28,7 @@ Function AddTest(Name : String; AddSource : Boolean) : Integer;
 Function UpdateTest(ID : Integer; Info : TConfig; Source : String) : Boolean;
 Function AddTestResult(TestID,RunID,TestRes : Integer;
                        OK, Skipped : Boolean;
-                       Log : String) : Integer;
+                       Log : String;var is_new : boolean) : Integer;
 Function RequireTestID(Name : String): Integer;
 Function CleanTestRun(ID : Integer) : Boolean;
 
@@ -121,6 +121,19 @@ begin
     Res:=Mysql_store_result(@connection);
 end;
 
+{ No warning if it fails }
+Function RunSilentQuery (Qry : String; Var res : TQueryResult) : Boolean ;
+
+begin
+  Verbose(V_DEBUG,'Running silent query:'+Qry);
+  Result:=mysql_query(@Connection,PChar(qry))=0;
+  If Not Result then
+    Verbose(V_DEBUG,'Silent query : '+Qry+'Failed : '+Strpas(mysql_error(@connection)))
+  else
+    Res:=Mysql_store_result(@connection);
+end;
+
+
 Function GetResultField (Res : TQueryResult; Id : Integer) : String;
 
 Var
@@ -410,34 +423,45 @@ end;
 
 Function AddTestResult(TestID,RunID,TestRes : Integer;
                        OK, Skipped : Boolean;
-                       Log : String) : Integer;
+                       Log : String;var is_new : boolean) : Integer;
 
 Const
   SInsertRes='Insert into TESTRESULTS '+
              '(TR_TEST_FK,TR_TESTRUN_FK,TR_OK,TR_SKIP,TR_RESULT) '+
              ' VALUES '+
              '(%d,%d,"%s","%s",%d) ';
-  SInsertLog='Update TESTRESULTS SET TR_LOG="%s" WHERE (TR_ID=%d)';
+  SSelectId='SELECT TR_ID FROM TESTRESULTS WHERE (TR_TEST_FK=%d) '+
+            ' AND (TR_TESTRUN_FK=%d)';
+  SInsertLog='Update TESTRESULTS SET TR_LOG="%s"'+
+             ',TR_OK="%s",TR_SKIP="%s",TR_RESULT=%d WHERE (TR_ID=%d)';
 Var
   Qry : String;
   Res : TQueryResult;
-
+  updateValues : boolean;
 begin
+  updateValues:=false;
   Result:=-1;
   Qry:=Format(SInsertRes,
               [TestID,RunID,B[OK],B[Skipped],TestRes,EscapeSQL(Log)]);
-  If RunQuery(Qry,Res) then
+  If RunSilentQuery(Qry,Res) then
     Result:=mysql_insert_id(@connection)
   else
-    Verbose(V_Warning,'AddTestResult failed');
-  if (Result<>-1) and (Log<>'') then
     begin
-      Qry:=format(SInsertLog,[EscapeSQL(Log),Result]);
+      Qry:=format(SSelectId,[TestId,RunId]);
+      Result:=IDQuery(Qry);
+      if Result<>-1 then
+        updateValues:=true;
+    end;
+  if (Result<>-1) and ((Log<>'') or updateValues) then
+    begin
+      Qry:=format(SInsertLog,[EscapeSQL(Log),B[OK],B[Skipped],TestRes,Result]);
       if not RunQuery(Qry,Res) then
         begin
           Verbose(V_Warning,'Insert Log failed');
         end;
     end;
+  { If test already existed, return false for is_new to avoid double counting }
+  is_new:=not updateValues;
 end;
 
 Function RequireTestID(Name : String): Integer;