From 237b5ae49a1aeb5ac7fb3b86e60a436209e0af6c Mon Sep 17 00:00:00 2001 From: wenjiefan Date: Thu, 25 Jun 2026 16:13:08 +0200 Subject: [PATCH] Fix NoOfSqlCallsAreLogged to tolerate first-run system-table SQL (Bug 618568) The very first database access in a session counts 2 extra SQL statements from system tables, so the total NoOfSQLStmts is either the number of iterations or that number + 2. Updated the assertion to accept both, matching the existing pattern in LogsAreGeneratedAfterTheExecution. --- .../Test/src/BCPTSetupCardTest.Codeunit.al | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Tools/Performance Toolkit/Test/src/BCPTSetupCardTest.Codeunit.al b/src/Tools/Performance Toolkit/Test/src/BCPTSetupCardTest.Codeunit.al index 37347dd11b..0b402417a3 100644 --- a/src/Tools/Performance Toolkit/Test/src/BCPTSetupCardTest.Codeunit.al +++ b/src/Tools/Performance Toolkit/Test/src/BCPTSetupCardTest.Codeunit.al @@ -129,6 +129,7 @@ codeunit 144741 "BCPT Setup Card Test" BCPTSetupCardTest: Codeunit "BCPT Setup Card Test"; BCPTStartTests: Codeunit "BCPT Start Tests"; BCPTSetupCard: TestPage "BCPT Setup Card"; + ActualNoOfIterations: Integer; UnexpectedNoOfSqlStmtsLbl: Label 'Unexpected value in %1. Expected %2, Actual %3', Locked = true; begin Initialize(); @@ -145,8 +146,13 @@ codeunit 144741 "BCPT Setup Card Test" BCPTSetupCard.OpenView(); BCPTSetupCard.GoToRecord(BCPTHeader); BCPTSetupCard.BCPTLines.Status.AssertEquals(BCPTLine.Status::Completed); - Assert.IsTrue(BCPTSetupCard.BCPTLines.NoOfIterations.AsInteger() >= NoOfIterationsToRun, StrSubstNo(UnexpectedNoOfSqlStmtsLbl, BCPTLogEntry.FieldCaption("No. of SQL Statements"), NoOfIterationsToRun, BCPTSetupCard.BCPTLines.NoOfIterations.AsInteger())); - BCPTSetupCard.BCPTLines.NoOfSQLStmts.AssertEquals(NoOfIterationsToRun); + ActualNoOfIterations := BCPTSetupCard.BCPTLines.NoOfIterations.AsInteger(); + Assert.IsTrue(ActualNoOfIterations >= NoOfIterationsToRun, StrSubstNo(UnexpectedNoOfSqlStmtsLbl, BCPTSetupCard.BCPTLines.NoOfIterations.Caption, NoOfIterationsToRun, ActualNoOfIterations)); + // The codeunit issues exactly 1 SQL statement per iteration, but the very first database access in the session also + // counts 2 extra SQL statements from system tables. Therefore the total is either ActualNoOfIterations or ActualNoOfIterations + 2. + Assert.IsTrue( + BCPTSetupCard.BCPTLines.NoOfSQLStmts.AsInteger() in [ActualNoOfIterations, ActualNoOfIterations + 2], + StrSubstNo(UnexpectedNoOfSqlStmtsLbl, BCPTLogEntry.FieldCaption("No. of SQL Statements"), StrSubstNo('%1 or %2', ActualNoOfIterations, ActualNoOfIterations + 2), BCPTSetupCard.BCPTLines.NoOfSQLStmts.AsInteger())); BCPTSetupCard.BCPTLines.AvgSQLStmts.AssertEquals(1); BCPTSetupCard.Close(); end;