Skip to content

Commit 6bb6abf

Browse files
Added basic test cases
Task: BABEL-6037 Signed-off-by: Manisha Deshpande <mmdeshp@amazon.com>
1 parent cfa6402 commit 6bb6abf

File tree

6 files changed

+919
-0
lines changed

6 files changed

+919
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
-- BABEL-6037 POC Test - Cleanup
3+
-- Drops all test procedures created during testing
4+
PRINT 'Starting cleanup of BABEL-6037 POC test procedures...';
5+
GO
6+
7+
-- Drop Test 1: Simple procedure without arguments
8+
DROP PROCEDURE IF EXISTS dbo.small_proc;
9+
PRINT 'Dropped: dbo.small_proc';
10+
GO
11+
12+
-- Drop Test 2: Simple procedure with arguments
13+
DROP PROCEDURE IF EXISTS dbo.small_proc_param;
14+
PRINT 'Dropped: dbo.small_proc_param';
15+
GO
16+
17+
-- Drop Test 3: Procedure with unsupported node type
18+
DROP PROCEDURE IF EXISTS dbo.proc_param_supported;
19+
PRINT 'Dropped: dbo.proc_with_unsupported';
20+
GO
21+
22+
-- Drop Test 4: Procedure with unsupported node type
23+
DROP PROCEDURE IF EXISTS dbo.proc_param_unsupported;
24+
PRINT 'Dropped: dbo.proc_with_unsupported';
25+
GO
26+
27+
-- Drop Test 5: Complex procedure
28+
DROP PROCEDURE IF EXISTS dbo.complex_proc;
29+
PRINT 'Dropped: dbo.complex_proc';
30+
GO
31+
32+
-- Drop Test 6: Same-session procedure (if it still exists)
33+
DROP PROCEDURE IF EXISTS dbo.samesession_proc;
34+
PRINT 'Dropped: dbo.samesession_proc';
35+
GO
36+
37+
-- Drop Test 7: Old-session procedure (if it still exists)
38+
DROP PROCEDURE IF EXISTS dbo.oldsession_proc;
39+
PRINT 'Dropped: dbo.newsession_proc';
40+
GO
41+
42+
PRINT 'Cleanup completed successfully';
43+
GO
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
2+
-- BABEL-6037 POC Test - Prepare
3+
-- Creates test procedures for parse tree serialization/deserialization testing
4+
-- Test 1: Simple procedure without arguments
5+
-- This tests basic serialization with minimal complexity
6+
CREATE PROCEDURE dbo.small_proc
7+
AS
8+
BEGIN
9+
DECLARE @var1 INT = 1;
10+
SELECT @var1;
11+
END;
12+
GO
13+
14+
-- Test 2: Simple procedure with arguments (from focused revision doc)
15+
-- This tests parameter handling and variable serialization
16+
CREATE PROCEDURE dbo.small_proc_param
17+
@param1 INT,
18+
@param2 VARCHAR(50)
19+
AS
20+
BEGIN
21+
DECLARE @var1 INT = 1;
22+
SELECT @var1, @param1, @param2;
23+
CREATE TABLE #test(id int);
24+
END;
25+
GO
26+
27+
-- Test 3: Procedure with supported node types (PRINT, WHILE, GOTO, TRY-CATCH, CASE, BREAK, CONTINUE)
28+
-- This tests various statement types within a BLOCK statement
29+
CREATE PROCEDURE dbo.proc_param_supported
30+
@input_val INT = 10
31+
AS
32+
BEGIN
33+
DECLARE @counter INT = 0;
34+
DECLARE @result VARCHAR(100) = '';
35+
DECLARE @status INT = 0;
36+
37+
-- Test PRINT statement
38+
PRINT 'Starting test procedure';
39+
40+
-- Test WHILE loop with BREAK and CONTINUE
41+
WHILE @counter < 3
42+
BEGIN
43+
SET @counter = @counter + 1;
44+
45+
-- Test IF with EXECSQL
46+
IF @counter = 2
47+
BEGIN
48+
SELECT @result = 'Found two';
49+
END
50+
END
51+
52+
-- Test WHILE with BREAK and CONTINUE
53+
SET @counter = 0;
54+
WHILE 1 = 1
55+
BEGIN
56+
SET @counter = @counter + 1;
57+
58+
-- Test BREAK statement
59+
IF @counter > 5
60+
BREAK;
61+
62+
-- Test CONTINUE statement
63+
IF @counter = 3
64+
CONTINUE;
65+
66+
SET @result = @result + CAST(@counter AS VARCHAR);
67+
END
68+
69+
-- Test CASE statement
70+
SET @status = CASE @input_val
71+
WHEN 10 THEN 1
72+
WHEN 20 THEN 2
73+
WHEN 30 THEN 3
74+
ELSE 0
75+
END;
76+
77+
-- Test GOTO and LABEL
78+
IF @status = 0
79+
GOTO skip_section;
80+
81+
skip_section:
82+
PRINT 'Skipped or continued';
83+
84+
-- Test TRY-CATCH block
85+
BEGIN TRY
86+
-- Test EXECSQL with potential error
87+
DECLARE @test_val INT;
88+
SELECT @test_val = 100 / @input_val;
89+
90+
-- Test ASSIGN statement
91+
SET @result = 'Success: ' + CAST(@test_val AS VARCHAR);
92+
END TRY
93+
BEGIN CATCH
94+
-- Error handling
95+
SET @result = 'Error handled';
96+
END CATCH
97+
98+
-- Test RETURN statement
99+
IF @input_val < 0
100+
RETURN;
101+
102+
-- Final output
103+
SELECT @result AS FinalResult, @status AS Status, @counter AS Counter;
104+
END;
105+
GO
106+
107+
108+
-- Test 4: Procedure with unsupported node type (EXEC_SP / sp_executesql)
109+
-- PLTSQL_STMT_EXEC_SP is not in pltsql_is_serializable; triggers PLTSQL_SERIAL_UNSUPPORTED
110+
-- Each new session falls back to full ANTLR recompile instead of using persistent cache
111+
CREATE PROCEDURE dbo.proc_param_unsupported
112+
@max INT
113+
AS
114+
BEGIN
115+
DECLARE @sql NVARCHAR(100) = N'SELECT ' + CAST(@max AS NVARCHAR);
116+
EXEC sp_executesql @sql;
117+
END;
118+
GO
119+
120+
121+
122+
-- Test 5: Complex procedure that may lead to serialize error
123+
-- Tests nested blocks, multiple statement types, and IF conditions
124+
CREATE PROCEDURE dbo.complex_proc
125+
@input INT,
126+
@flag BIT
127+
AS
128+
BEGIN
129+
DECLARE @result INT;
130+
DECLARE @temp VARCHAR(100);
131+
132+
-- Test ASSIGN statement
133+
SET @result = @input * 2;
134+
135+
-- Test IF statement with nested block
136+
IF @flag = 1
137+
BEGIN
138+
SET @temp = 'Flag is true';
139+
SELECT @result, @temp;
140+
141+
-- Nested temp table operations
142+
CREATE TABLE #temp1(id INT, value VARCHAR(50));
143+
INSERT INTO #temp1 VALUES (@result, @temp);
144+
SELECT * FROM #temp1;
145+
END
146+
ELSE
147+
BEGIN
148+
SET @temp = 'Flag is false';
149+
SELECT @result, @temp;
150+
END;
151+
152+
-- Test EXECSQL with UNPIVOT (complex SQL expression within serializable proc)
153+
SELECT col, val
154+
FROM (SELECT @input AS input_val, @result AS doubled_val) AS src
155+
UNPIVOT (val FOR col IN (input_val, doubled_val)) AS unpvt;
156+
-- Test RETURN statement
157+
RETURN @result;
158+
END;
159+
GO
160+
161+
162+
-- Test 6: Procedure for same-session testing
163+
-- Test 7: Procedure for new-session testing
164+
-- This will be used to test ALTER and DROP in new session
165+
CREATE PROCEDURE dbo.oldsession_proc
166+
@value INT
167+
AS
168+
BEGIN
169+
SELECT @value AS original_value;
170+
END;
171+
GO
172+
173+
PRINT 'All test procedures created successfully';
174+
GO

0 commit comments

Comments
 (0)