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

Function TestConcurrentEvalRecover

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

Source from the content-addressed store, hash-verified

814}
815
816func TestConcurrentEvalRecover(t *testing.T) {
817 env, err := cel.NewEnv(
818 cel.Function("panic",
819 cel.Overload("global_panic", []*cel.Type{}, cel.BoolType,
820 cel.FunctionBinding(func(args ...ref.Val) ref.Val {
821 panic("watch me recover")
822 }),
823 ),
824 ),
825 cel.Function("cancel_panic",
826 cel.Overload("global_cancel_panic", []*cel.Type{}, cel.BoolType,
827 cel.FunctionBinding(func(args ...ref.Val) ref.Val {
828 panic(interpreter.EvalCancelledError{Message: "eval cancelled", Cause: interpreter.ContextCancelled})
829 }),
830 ),
831 ),
832 cel.Function("sleep_func",
833 cel.Overload("global_sleep_func", []*cel.Type{}, cel.BoolType,
834 cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val {
835 time.Sleep(1 * time.Second)
836 return types.True
837 }),
838 ),
839 ),
840 )
841 if err != nil {
842 t.Fatalf("cel.NewEnv() failed: %v", err)
843 }
844
845 tests := []struct {
846 name string
847 expr string
848 prgOpts []cel.ProgramOption
849 getCtx func() (context.Context, context.CancelFunc)
850 wantErr any
851 }{
852 {
853 name: "panic",
854 expr: "panic()",
855 wantErr: "internal error: watch me recover",
856 },
857 {
858 name: "panic_tracked_state",
859 expr: "panic()",
860 prgOpts: []cel.ProgramOption{cel.EvalOptions(cel.OptTrackState)},
861 wantErr: "internal error: watch me recover",
862 },
863 {
864 name: "eval_cancelled_error",
865 expr: "cancel_panic()",
866 wantErr: &interpreter.EvalCancelledError{},
867 },
868 {
869 name: "context_timeout",
870 expr: "sleep_func()",
871 getCtx: func() (context.Context, context.CancelFunc) {
872 return context.WithTimeout(context.Background(), 10*time.Millisecond)
873 },

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