4141`
4242
4343func TestMemoryQuotaExceeded (t * testing.T ) {
44- engine := MustNewEngine ( Config {
44+ script := compileScriptWithConfig ( t , Config {
4545 StepQuota : 20000 ,
4646 MemoryQuotaBytes : 2048 ,
47- })
48-
49- script , err := engine .Compile (quotaFixture )
50- if err != nil {
51- t .Fatalf ("compile failed: %v" , err )
52- }
47+ }, quotaFixture )
5348
49+ var err error
5450 _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
5551 if err == nil {
5652 t .Fatalf ("expected memory quota error" )
@@ -61,16 +57,12 @@ func TestMemoryQuotaExceeded(t *testing.T) {
6157}
6258
6359func TestMemoryQuotaCountsClassVars (t * testing.T ) {
64- engine := MustNewEngine ( Config {
60+ script := compileScriptWithConfig ( t , Config {
6561 StepQuota : 20000 ,
6662 MemoryQuotaBytes : 3072 ,
67- })
68-
69- script , err := engine .Compile (classVarFixture )
70- if err != nil {
71- t .Fatalf ("compile failed: %v" , err )
72- }
63+ }, classVarFixture )
7364
65+ var err error
7466 _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
7567 if err == nil {
7668 t .Fatalf ("expected memory quota error" )
@@ -81,16 +73,12 @@ func TestMemoryQuotaCountsClassVars(t *testing.T) {
8173}
8274
8375func TestMemoryQuotaAllowsExecution (t * testing.T ) {
84- engine := MustNewEngine ( Config {
76+ script := compileScriptWithConfig ( t , Config {
8577 StepQuota : 20000 ,
8678 MemoryQuotaBytes : 1 << 20 ,
87- })
88-
89- script , err := engine .Compile (quotaFixture )
90- if err != nil {
91- t .Fatalf ("compile failed: %v" , err )
92- }
79+ }, quotaFixture )
9380
81+ var err error
9482 result , err := script .Call (context .Background (), "run" , nil , CallOptions {})
9583 if err != nil {
9684 t .Fatalf ("unexpected error: %v" , err )
@@ -101,17 +89,13 @@ func TestMemoryQuotaAllowsExecution(t *testing.T) {
10189}
10290
10391func TestMemoryQuotaExceededOnCompletion (t * testing.T ) {
104- engine := MustNewEngine ( Config {
92+ script := compileScriptWithConfig ( t , Config {
10593 StepQuota : 20000 ,
10694 MemoryQuotaBytes : 2048 ,
107- })
108-
109- script , err := engine .Compile (splitFixture )
110- if err != nil {
111- t .Fatalf ("compile failed: %v" , err )
112- }
95+ }, splitFixture )
11396
11497 input := strings .Repeat ("a," , 4000 )
98+ var err error
11599 _ , err = script .Call (context .Background (), "run" , []Value {NewString (input )}, CallOptions {})
116100 if err == nil {
117101 t .Fatalf ("expected memory quota error" )
@@ -122,20 +106,18 @@ func TestMemoryQuotaExceededOnCompletion(t *testing.T) {
122106}
123107
124108func TestMemoryQuotaExceededForEmptyBodyDefaultArg (t * testing.T ) {
125- engine := MustNewEngine ( Config {
109+ cfg := Config {
126110 StepQuota : 20000 ,
127111 MemoryQuotaBytes : 2048 ,
128- })
112+ }
129113
130114 largeCSV := strings .Repeat ("abcdefghij," , 1500 )
131115 source := `def run(payload = "` + largeCSV + `".split(","))
132116end`
133117
134- script , err := engine .Compile (source )
135- if err != nil {
136- t .Fatalf ("compile failed: %v" , err )
137- }
118+ script := compileScriptWithConfig (t , cfg , source )
138119
120+ var err error
139121 _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
140122 if err == nil {
141123 t .Fatalf ("expected memory quota error" )
@@ -146,23 +128,19 @@ end`
146128}
147129
148130func TestMemoryQuotaExceededForBoundArguments (t * testing.T ) {
149- engine := MustNewEngine ( Config {
131+ script := compileScriptWithConfig ( t , Config {
150132 StepQuota : 20000 ,
151133 MemoryQuotaBytes : 2048 ,
152- })
153-
154- script , err := engine .Compile (`def run(payload)
134+ }, `def run(payload)
155135end` )
156- if err != nil {
157- t .Fatalf ("compile failed: %v" , err )
158- }
159136
160137 parts := make ([]Value , 2000 )
161138 for i := range parts {
162139 parts [i ] = NewString ("abcdefghij" )
163140 }
164141 largeArg := NewArray (parts )
165142
143+ var err error
166144 _ , err = script .Call (context .Background (), "run" , []Value {largeArg }, CallOptions {})
167145 if err == nil {
168146 t .Fatalf ("expected memory quota error for positional arg" )
@@ -185,22 +163,18 @@ end`)
185163}
186164
187165func TestMemoryQuotaCountsIndependentEmptySlices (t * testing.T ) {
188- engine := MustNewEngine ( Config {
166+ script := compileScriptWithConfig ( t , Config {
189167 StepQuota : 20000 ,
190168 MemoryQuotaBytes : 4096 ,
191- })
192-
193- script , err := engine .Compile (`def run
169+ }, `def run
194170 items = []
195171 for i in 1..400
196172 items = items.push([])
197173 end
198174 items.size
199175end` )
200- if err != nil {
201- t .Fatalf ("compile failed: %v" , err )
202- }
203176
177+ var err error
204178 _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
205179 if err == nil {
206180 t .Fatalf ("expected memory quota error for many independent empty slices" )
@@ -211,12 +185,10 @@ end`)
211185}
212186
213187func TestMemoryQuotaExceededWithWhileLoopAllocations (t * testing.T ) {
214- engine := MustNewEngine ( Config {
188+ script := compileScriptWithConfig ( t , Config {
215189 StepQuota : 20000 ,
216190 MemoryQuotaBytes : 2048 ,
217- })
218-
219- script , err := engine .Compile (`def run()
191+ }, `def run()
220192 items = []
221193 n = 0
222194 while n < 200
@@ -225,10 +197,8 @@ func TestMemoryQuotaExceededWithWhileLoopAllocations(t *testing.T) {
225197 end
226198 items.size
227199end` )
228- if err != nil {
229- t .Fatalf ("compile failed: %v" , err )
230- }
231200
201+ var err error
232202 _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
233203 if err == nil {
234204 t .Fatalf ("expected memory quota error for while-loop allocations" )
0 commit comments