Skip to content

Commit c2e1bc4

Browse files
committed
Trying to debug an issue with transactions when we open a transaction within an inner no-transaction test <-- we have no issues when the inner test is not a no-transaction test and we should include this test in the test class.
1 parent 52261a5 commit c2e1bc4

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

Source/Run_Methods.sql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ BEGIN
209209
SET @Result = 'Error';
210210
END;
211211
END CATCH;
212-
213212
IF (@NoTransactionFlag = 1)
214213
BEGIN
215214
SET @CleanUpProcedureExecutionCmd = (
@@ -241,7 +240,6 @@ BEGIN
241240
@TestResult = @Result OUT,
242241
@TestMsg = @Msg OUT
243242
END;
244-
245243
IF(@TransactionStartedFlag = 1)
246244
BEGIN
247245
COMMIT;
@@ -326,7 +324,8 @@ BEGIN
326324
@TranName,
327325
@Result OUT,
328326
@Msg OUT,
329-
@TestEndTime OUT
327+
@TestEndTime OUT;
328+
330329
END;
331330
ELSE
332331
BEGIN
@@ -351,7 +350,6 @@ BEGIN
351350
SET @Msg2 = @TestName + ' failed: (' + @Result + ') ' + @Msg;
352351
EXEC tSQLt.Private_Print @Message = @Msg2, @Severity = 0;
353352
END;
354-
355353
IF EXISTS(SELECT 1 FROM tSQLt.TestResult WHERE Id = @TestResultId)
356354
BEGIN
357355
UPDATE tSQLt.TestResult SET
@@ -370,8 +368,6 @@ BEGIN
370368
'TestResult entry is missing; Original outcome: ' + @Result + ', ' + @Msg;
371369
END;
372370

373-
374-
375371
IF(@Verbose = 1)
376372
BEGIN
377373
SET @VerboseMsg = 'tSQLt.Run '''+@TestName+'''; --Finished';

Tests/Run_Methods_Tests.class.sql

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,13 +2448,26 @@ BEGIN
24482448
EXEC tSQLt.NewTestClass 'MyInnerTests'
24492449
EXEC('
24502450
--[@'+'tSQLt:NoTransaction](DEFAULT)
2451-
CREATE PROCEDURE MyInnerTests.[test should execute outside of transaction] AS BEGIN TRAN;
2451+
CREATE PROCEDURE MyInnerTests.[test should execute outside of transaction] AS BEGIN TRAN;SELECT * FROM fn_dblog(NULL,NULL) WHERE [Transaction ID] = (SELECT LL.[Transaction ID] FROM fn_dblog(NULL,NULL) LL JOIN sys.dm_tran_current_transaction AS DTCT ON DTCT.transaction_id = LL.[Xact ID]);
24522452
');
24532453

24542454
EXEC tSQLt.ExpectException @ExpectedMessage = 'SOMETHING RATHER', @ExpectedSeverity = NULL, @ExpectedState = NULL;
24552455

2456+
BEGIN TRY
24562457
EXEC tSQLt.Run 'MyInnerTests.[test should execute outside of transaction]';
2458+
END TRY
2459+
BEGIN CATCH
2460+
SELECT * FROM fn_dblog(NULL,NULL) WHERE [Transaction ID] = (SELECT LL.[Transaction ID] FROM fn_dblog(NULL,NULL) LL JOIN sys.dm_tran_current_transaction AS DTCT ON DTCT.transaction_id = LL.[Xact ID]);
2461+
END CATCH;
24572462

2463+
2464+
END;
2465+
GO
2466+
/*-----------------------------------------------------------------------------------------------*/
2467+
GO
2468+
EXEC tSQLt.Run 'Run_Methods_Tests.[test produces meaningful error when pre and post transactions counts don''t match]';
2469+
GO
2470+
SELECT * FROM tSQLt.TestResult;
24582471
/*--
24592472
Transaction Tests
24602473
@@ -2464,11 +2477,6 @@ CREATE PROCEDURE MyInnerTests.[test should execute outside of transaction] AS BE
24642477
- what should we do if the original transaction was rolled back and a new one was created?
24652478
- what should we do if the original transaction was committed and a new one was created?
24662479
- we still need to save the TranName as something somewhere.
2467-
- review existing tests for transactions
2480+
- do existing tests already cover some of the scenarios described above?
24682481
24692482
--*/
2470-
2471-
END;
2472-
GO
2473-
/*-----------------------------------------------------------------------------------------------*/
2474-
GO

0 commit comments

Comments
 (0)