@@ -91,6 +91,9 @@ public void NotChain_ExtremeDepth_OnSmallStackThread_IsGracefulNeverProcessDeath
9191 }
9292
9393 private void RunOnSmallStack ( string sql , out object ? result , out Exception ? failure )
94+ => RunOnStack ( 512 * 1024 , sql , out result , out failure ) ;
95+
96+ private void RunOnStack ( int maxStackSize , string sql , out object ? result , out Exception ? failure )
9497 {
9598 object ? captured = null ;
9699 Exception ? caught = null ;
@@ -104,9 +107,9 @@ private void RunOnSmallStack(string sql, out object? result, out Exception? fail
104107 {
105108 caught = ex ;
106109 }
107- } , maxStackSize : 512 * 1024 ) ;
110+ } , maxStackSize ) ;
108111 thread . Start ( ) ;
109- IsTrue ( thread . Join ( TimeSpan . FromSeconds ( 30 ) ) , "query did not complete on the small -stack thread" ) ;
112+ IsTrue ( thread . Join ( TimeSpan . FromSeconds ( 30 ) ) , "query did not complete on the sized -stack thread" ) ;
110113 result = captured ;
111114 failure = caught ;
112115 }
@@ -155,10 +158,15 @@ public void NestedSubqueries_OverLimit_RaisesMsg191()
155158 [ Timeout ( 60000 ) ]
156159 public void NestedFunctions_OverBudget_RaisesMsg191 ( )
157160 {
158- // 501 nested ABS = 501 budget units > 500. On a normal (large) test
159- // thread the structural cap trips before the stack probe.
161+ // 501 nested ABS = 501 budget units > 500. The fat function frames
162+ // exhaust a default 1 MB thread (Windows test runners) near ~97 levels,
163+ // where the stack probe's Msg 8631 would pre-empt the budget's Msg 191
164+ // — a dedicated 16 MB thread keeps the structural cap deterministic.
160165 var sql = "select " + string . Concat ( Enumerable . Repeat ( "abs(" , 501 ) ) + "1" + new string ( ')' , 501 ) ;
161- AreEqual ( 15 , new Simulation ( ) . AssertSqlError ( sql , 191 ) . Class ) ;
166+ RunOnStack ( 16 * 1024 * 1024 , sql , out _ , out var failure ) ;
167+ var ex = IsInstanceOfType < SimulatedSqlException > ( failure ) ;
168+ AreEqual ( 191 , ex . Number ) ;
169+ AreEqual ( 15 , ex . Class ) ;
162170 }
163171
164172 [ TestMethod ]
0 commit comments