| 2353 | } |
| 2354 | |
| 2355 | func TestExpr_timeout(t *testing.T) { |
| 2356 | tests := []struct{ code string }{ |
| 2357 | {`-999999..999999`}, |
| 2358 | {`map(1..999999, 1..999999)`}, |
| 2359 | {`map(1..999999, repeat('a', #))`}, |
| 2360 | } |
| 2361 | |
| 2362 | for _, tt := range tests { |
| 2363 | t.Run(tt.code, func(t *testing.T) { |
| 2364 | program, err := expr.Compile(tt.code) |
| 2365 | require.NoError(t, err) |
| 2366 | |
| 2367 | timeout := make(chan bool, 1) |
| 2368 | go func() { |
| 2369 | time.Sleep(time.Second) |
| 2370 | timeout <- true |
| 2371 | }() |
| 2372 | |
| 2373 | done := make(chan bool, 1) |
| 2374 | go func() { |
| 2375 | out, err := expr.Run(program, nil) |
| 2376 | // Make sure out is used. |
| 2377 | _ = fmt.Sprintf("%v", out) |
| 2378 | assert.Error(t, err) |
| 2379 | done <- true |
| 2380 | }() |
| 2381 | |
| 2382 | select { |
| 2383 | case <-done: |
| 2384 | // Success. |
| 2385 | case <-timeout: |
| 2386 | t.Fatal("timeout") |
| 2387 | } |
| 2388 | }) |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | func TestIssue432(t *testing.T) { |
| 2393 | env := map[string]any{ |