Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Experiments/Debugging tSQLt.tdf
Binary file not shown.
6 changes: 6 additions & 0 deletions Experiments/Experiments.ssmssqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<AssociatedConnUserName />
<FullPath>LIKE4000.sql</FullPath>
</FileNode>
<FileNode Name="MSSQL Defect Try-Catch Invalidates Transaction.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
<AssociatedConnUserName />
<FullPath>MSSQL Defect Try-Catch Invalidates Transaction.sql</FullPath>
</FileNode>
<FileNode Name="NameResolutionResearch.sql">
<AssociatedConnectionMoniker />
<AssociatedConnSrvName />
Expand Down
20 changes: 20 additions & 0 deletions Experiments/MSSQL Defect Try-Catch Invalidates Transaction.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PRINT 'No TRY...CATCH:';
EXEC ('BEGIN TRAN');
SELECT XACT_STATE() AS [XACT_STATE()],@@TRANCOUNT AS [@@TRANCOUNT];
GO
IF(XACT_STATE()<>0)ROLLBACK;
GO



GO
PRINT 'In TRY...CATCH:';
BEGIN TRY
EXEC ('BEGIN TRAN');
END TRY
BEGIN CATCH
END CATCH;
SELECT XACT_STATE() AS [XACT_STATE()],@@TRANCOUNT AS [@@TRANCOUNT];
GO
IF(XACT_STATE()<>0)ROLLBACK;
GO
File renamed without changes.
1 change: 1 addition & 0 deletions Source/Run_Methods.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ BEGIN
BEGIN
EXEC @SetUp;
END;

EXEC (@TestExecutionCmd);

IF(EXISTS(SELECT 1 FROM #ExpectException WHERE ExpectException = 1))
Expand Down
29 changes: 19 additions & 10 deletions Tests/Run_Methods_Tests.class.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2441,33 +2441,42 @@ GO
/*-----------------------------------------------------------------------------------------------*/
GO

---[@tSQLt:SkipTest]('TODO: need to review handling of unexpected changes to the tSQLt transaction')
CREATE PROCEDURE Run_Methods_Tests.[test produces meaningful error when pre and post transactions counts don't match]
AS
BEGIN
EXEC tSQLt.NewTestClass 'MyInnerTests'
EXEC tSQLt.NewTestClass 'MyInnerTestsA'
EXEC('CREATE PROCEDURE MyInnerTestsA.[test should execute outside of transaction] AS BEGIN TRAN;');

EXEC tSQLt.ExpectException @ExpectedMessage = 'SOMETHING RATHER', @ExpectedSeverity = NULL, @ExpectedState = NULL;
EXEC tSQLt.Run 'MyInnerTestsA.[test should execute outside of transaction]';

END;
GO
/*-----------------------------------------------------------------------------------------------*/
GO

--[@tSQLt:SkipTest]('TODO: need to review handling of unexpected changes to the tSQLt transaction for NoTransaction tests')
CREATE PROCEDURE Run_Methods_Tests.[test produces meaningful error when pre and post transactions counts don't match in NoTransaction test]
AS
BEGIN
EXEC tSQLt.NewTestClass 'MyInnerTestsB'
EXEC('
--[@'+'tSQLt:NoTransaction](DEFAULT)
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]);
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]);
');

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

BEGIN TRY
EXEC tSQLt.Run 'MyInnerTests.[test should execute outside of transaction]';
EXEC tSQLt.Run 'MyInnerTestsB.[test should execute outside of transaction]';
END TRY
BEGIN CATCH
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]);
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]);
END CATCH;


END;
GO
/*-----------------------------------------------------------------------------------------------*/
GO
EXEC tSQLt.Run 'Run_Methods_Tests.[test produces meaningful error when pre and post transactions counts don''t match]';
GO
SELECT * FROM tSQLt.TestResult;
/*--
Transaction Tests

Expand Down