MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestConcurrentEvalRecover

Function TestConcurrentEvalRecover

cel/program_async_test.go:973–1073  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

971}
972
973func 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 },

Callers

nothing calls this directly

Calls 14

CompileMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
FunctionFunction · 0.92
OverloadFunction · 0.92
FunctionBindingFunction · 0.92
AsyncBindingFunction · 0.92
EvalOptionsFunction · 0.92
NoVarsFunction · 0.92
awaitEvalFunction · 0.85
ErrMethod · 0.80
ContainsMethod · 0.65

Tested by

no test coverage detected