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

Function TestSyncEvalRejectsAsyncBeforeEvaluating

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

Source from the content-addressed store, hash-verified

773}
774
775func TestSyncEvalRejectsAsyncBeforeEvaluating(t *testing.T) {
776 // The async guard must fire at the entry point, before any evaluation: the async function
777 // must never be invoked (no goroutines launched, no work done) for Eval or ContextEval.
778 var called atomic.Int32
779 prg := mustProgram(t, `rpc("a")`,
780 cel.Function("rpc",
781 cel.Overload("rpc_string", []*cel.Type{cel.StringType}, cel.StringType,
782 cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val {
783 called.Add(1)
784 return args[0]
785 }))),
786 )
787
788 if _, _, err := prg.Eval(cel.NoVars()); err == nil || !strings.Contains(err.Error(), "ConcurrentEval") {
789 t.Errorf("Eval() = %v, want ConcurrentEval error", err)
790 }
791 if _, _, err := prg.ContextEval(context.Background(), cel.NoVars()); err == nil || !strings.Contains(err.Error(), "ConcurrentEval") {
792 t.Errorf("ContextEval() = %v, want ConcurrentEval error", err)
793 }
794 if got := called.Load(); got != 0 {
795 t.Errorf("async function invoked %d times; the guard must reject before evaluating", got)
796 }
797}
798
799func TestSyncEvalRejectedInAsyncEnv(t *testing.T) {
800 // Env-level rejection: an environment that declares any async function rejects the synchronous

Callers

nothing calls this directly

Calls 10

FunctionFunction · 0.92
OverloadFunction · 0.92
AsyncBindingFunction · 0.92
NoVarsFunction · 0.92
mustProgramFunction · 0.85
AddMethod · 0.65
EvalMethod · 0.65
ContainsMethod · 0.65
ContextEvalMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected