(t *testing.T)
| 971 | } |
| 972 | |
| 973 | func TestConcurrentEvalRecover(t *testing.T) { |
| 974 | env, err := cel.NewEnv( |
| 975 | cel.Function("panic", |
| 976 | cel.Overload("global_panic", []*cel.Type{}, cel.BoolType, |
| 977 | cel.FunctionBinding(func(args ...ref.Val) ref.Val { |
| 978 | panic("watch me recover") |
| 979 | }), |
| 980 | ), |
| 981 | ), |
| 982 | cel.Function("cancel_panic", |
| 983 | cel.Overload("global_cancel_panic", []*cel.Type{}, cel.BoolType, |
| 984 | cel.FunctionBinding(func(args ...ref.Val) ref.Val { |
| 985 | panic(interpreter.EvalCancelledError{Message: "eval cancelled", Cause: interpreter.ContextCancelled}) |
| 986 | }), |
| 987 | ), |
| 988 | ), |
| 989 | cel.Function("sleep_func", |
| 990 | cel.Overload("global_sleep_func", []*cel.Type{}, cel.BoolType, |
| 991 | cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val { |
| 992 | time.Sleep(1 * time.Second) |
| 993 | return types.True |
| 994 | }), |
| 995 | ), |
| 996 | ), |
| 997 | ) |
| 998 | if err != nil { |
| 999 | t.Fatalf("cel.NewEnv() failed: %v", err) |
| 1000 | } |
| 1001 | |
| 1002 | tests := []struct { |
| 1003 | name string |
| 1004 | expr string |
| 1005 | prgOpts []cel.ProgramOption |
| 1006 | getCtx func() (context.Context, context.CancelFunc) |
| 1007 | wantErr any |
| 1008 | }{ |
| 1009 | { |
| 1010 | name: "panic", |
| 1011 | expr: "panic()", |
| 1012 | wantErr: "internal error: watch me recover", |
| 1013 | }, |
| 1014 | { |
| 1015 | name: "panic_tracked_state", |
| 1016 | expr: "panic()", |
| 1017 | prgOpts: []cel.ProgramOption{cel.EvalOptions(cel.OptTrackState)}, |
| 1018 | wantErr: "internal error: watch me recover", |
| 1019 | }, |
| 1020 | { |
| 1021 | name: "eval_cancelled_error", |
| 1022 | expr: "cancel_panic()", |
| 1023 | wantErr: &interpreter.EvalCancelledError{}, |
| 1024 | }, |
| 1025 | { |
| 1026 | name: "context_timeout", |
| 1027 | expr: "sleep_func()", |
| 1028 | getCtx: func() (context.Context, context.CancelFunc) { |
| 1029 | return context.WithTimeout(context.Background(), 10*time.Millisecond) |
| 1030 | }, |
nothing calls this directly
no test coverage detected