Skip to content

Commit 33f7bd9

Browse files
authored
Merge pull request #128 from tSQLt-org/TransactionFree20211219
Transaction free20211219
2 parents c2e1bc4 + 453e269 commit 33f7bd9

6 files changed

Lines changed: 46 additions & 10 deletions

Experiments/Debugging tSQLt.tdf

2.92 KB
Binary file not shown.

Experiments/Experiments.ssmssqlproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
<AssociatedConnUserName />
6767
<FullPath>LIKE4000.sql</FullPath>
6868
</FileNode>
69+
<FileNode Name="MSSQL Defect Try-Catch Invalidates Transaction.sql">
70+
<AssociatedConnectionMoniker />
71+
<AssociatedConnSrvName />
72+
<AssociatedConnUserName />
73+
<FullPath>MSSQL Defect Try-Catch Invalidates Transaction.sql</FullPath>
74+
</FileNode>
6975
<FileNode Name="NameResolutionResearch.sql">
7076
<AssociatedConnectionMoniker />
7177
<AssociatedConnSrvName />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
PRINT 'No TRY...CATCH:';
2+
EXEC ('BEGIN TRAN');
3+
SELECT XACT_STATE() AS [XACT_STATE()],@@TRANCOUNT AS [@@TRANCOUNT];
4+
GO
5+
IF(XACT_STATE()<>0)ROLLBACK;
6+
GO
7+
8+
9+
10+
GO
11+
PRINT 'In TRY...CATCH:';
12+
BEGIN TRY
13+
EXEC ('BEGIN TRAN');
14+
END TRY
15+
BEGIN CATCH
16+
END CATCH;
17+
SELECT XACT_STATE() AS [XACT_STATE()],@@TRANCOUNT AS [@@TRANCOUNT];
18+
GO
19+
IF(XACT_STATE()<>0)ROLLBACK;
20+
GO
File renamed without changes.

Source/Run_Methods.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ BEGIN
8181
BEGIN
8282
EXEC @SetUp;
8383
END;
84+
8485
EXEC (@TestExecutionCmd);
8586

8687
IF(EXISTS(SELECT 1 FROM #ExpectException WHERE ExpectException = 1))

Tests/Run_Methods_Tests.class.sql

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,33 +2441,42 @@ GO
24412441
/*-----------------------------------------------------------------------------------------------*/
24422442
GO
24432443

2444-
---[@tSQLt:SkipTest]('TODO: need to review handling of unexpected changes to the tSQLt transaction')
24452444
CREATE PROCEDURE Run_Methods_Tests.[test produces meaningful error when pre and post transactions counts don't match]
24462445
AS
24472446
BEGIN
2448-
EXEC tSQLt.NewTestClass 'MyInnerTests'
2447+
EXEC tSQLt.NewTestClass 'MyInnerTestsA'
2448+
EXEC('CREATE PROCEDURE MyInnerTestsA.[test should execute outside of transaction] AS BEGIN TRAN;');
2449+
2450+
EXEC tSQLt.ExpectException @ExpectedMessage = 'SOMETHING RATHER', @ExpectedSeverity = NULL, @ExpectedState = NULL;
2451+
EXEC tSQLt.Run 'MyInnerTestsA.[test should execute outside of transaction]';
2452+
2453+
END;
2454+
GO
2455+
/*-----------------------------------------------------------------------------------------------*/
2456+
GO
2457+
2458+
--[@tSQLt:SkipTest]('TODO: need to review handling of unexpected changes to the tSQLt transaction for NoTransaction tests')
2459+
CREATE PROCEDURE Run_Methods_Tests.[test produces meaningful error when pre and post transactions counts don't match in NoTransaction test]
2460+
AS
2461+
BEGIN
2462+
EXEC tSQLt.NewTestClass 'MyInnerTestsB'
24492463
EXEC('
24502464
--[@'+'tSQLt:NoTransaction](DEFAULT)
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]);
2465+
CREATE PROCEDURE MyInnerTestsB.[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]);
24522466
');
24532467

24542468
EXEC tSQLt.ExpectException @ExpectedMessage = 'SOMETHING RATHER', @ExpectedSeverity = NULL, @ExpectedState = NULL;
24552469

24562470
BEGIN TRY
2457-
EXEC tSQLt.Run 'MyInnerTests.[test should execute outside of transaction]';
2471+
EXEC tSQLt.Run 'MyInnerTestsB.[test should execute outside of transaction]';
24582472
END TRY
24592473
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]);
2474+
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]);
24612475
END CATCH;
2462-
2463-
24642476
END;
24652477
GO
24662478
/*-----------------------------------------------------------------------------------------------*/
24672479
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;
24712480
/*--
24722481
Transaction Tests
24732482

0 commit comments

Comments
 (0)