Skip to content

Commit a6b8260

Browse files
committed
Updated documentation and skipped tests in Run_Methods_Tests.class.sql based on learnings around the try-catch w/transactions defect
1 parent 33f7bd9 commit a6b8260

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

Tests/Run_Methods_Tests.class.sql

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,7 @@ GO
24412441
/*-----------------------------------------------------------------------------------------------*/
24422442
GO
24432443

2444+
--[@tSQLt:SkipTest]('TODO: tSQLt should handle this, but does not at the moment because of the issue with transactions started within a try-catch block')
24442445
CREATE PROCEDURE Run_Methods_Tests.[test produces meaningful error when pre and post transactions counts don't match]
24452446
AS
24462447
BEGIN
@@ -2455,37 +2456,47 @@ GO
24552456
/*-----------------------------------------------------------------------------------------------*/
24562457
GO
24572458

2458-
--[@tSQLt:SkipTest]('TODO: need to review handling of unexpected changes to the tSQLt transaction for NoTransaction tests')
2459+
--[@tSQLt:SkipTest]('TODO: tSQLt should handle this, but does not at the moment because of the issue with transactions started within a try-catch block')
24592460
CREATE PROCEDURE Run_Methods_Tests.[test produces meaningful error when pre and post transactions counts don't match in NoTransaction test]
24602461
AS
24612462
BEGIN
24622463
EXEC tSQLt.NewTestClass 'MyInnerTestsB'
24632464
EXEC('
24642465
--[@'+'tSQLt:NoTransaction](DEFAULT)
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]);
2466+
CREATE PROCEDURE MyInnerTestsB.[test should execute outside of transaction] AS BEGIN TRAN;
24662467
');
24672468

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

2470-
BEGIN TRY
2471-
EXEC tSQLt.Run 'MyInnerTestsB.[test should execute outside of transaction]';
2472-
END TRY
2473-
BEGIN CATCH
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]);
2475-
END CATCH;
2472+
-- FOR FUTURE DEBUGGING
2473+
--BEGIN TRY
2474+
-- EXEC tSQLt.Run 'MyInnerTestsB.[test should execute outside of transaction]';
2475+
--END TRY
2476+
--BEGIN CATCH
2477+
-- 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]);
2478+
--END CATCH;
24762479
END;
24772480
GO
24782481
/*-----------------------------------------------------------------------------------------------*/
24792482
GO
24802483
/*--
2481-
Transaction Tests
2482-
2483-
- NoTransaction, but suddenly has transaction
2484-
- with transaction, but creates additional transaction
2485-
- transaction, but is committed (FATAL)
2486-
- what should we do if the original transaction was rolled back and a new one was created?
2487-
- what should we do if the original transaction was committed and a new one was created?
2488-
- we still need to save the TranName as something somewhere.
2484+
Transaction Tests to be considered
2485+
2486+
1. NoTransaction test starts a transaction
2487+
1a. The transaction is commitable (THIS FEELS UNLIKELY GIVEN OUR RESEARCH.)
2488+
1b. The transaction is not commitable
2489+
2490+
2. Transaction test rolls-back tSQLt transaction(s)
2491+
2a. No transaction after test (ROLLBACK, but no new transactions created within the test)
2492+
2b. New transaction after test (ROLLBACK, but new one created within the test)
2493+
2494+
3. Transaction test commits tSQLt transactions(s)
2495+
3a. No transaction after test (COMMIT, but no new transactions created within the test)
2496+
3b. New transaction after test (COMMIT, but new one created within the test)
2497+
2498+
4. Transaction test renders transaction uncommitable (Won't be able to write to anything, including tSQLt.TestResults or a variety of temp tables.)
2499+
24892500
- do existing tests already cover some of the scenarios described above?
24902501
24912502
--*/

0 commit comments

Comments
 (0)