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

Function TestSyncEvalRejectsAsyncBeforeEvaluating

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

Source from the content-addressed store, hash-verified

656}
657
658func TestSyncEvalRejectsAsyncBeforeEvaluating(t *testing.T) {
659 // The async guard must fire at the entry point, before any evaluation: the async function
660 // must never be invoked (no goroutines launched, no work done) for Eval or ContextEval.
661 var called atomic.Int32
662 prg := mustProgram(t, `rpc("a")`,
663 cel.Function("rpc",
664 cel.Overload("rpc_string", []*cel.Type{cel.StringType}, cel.StringType,
665 cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val {
666 called.Add(1)
667 return args[0]
668 }))),
669 )
670
671 if _, _, err := prg.Eval(cel.NoVars()); err == nil || !strings.Contains(err.Error(), "ConcurrentEval") {
672 t.Errorf("Eval() = %v, want ConcurrentEval error", err)
673 }
674 if _, _, err := prg.ContextEval(context.Background(), cel.NoVars()); err == nil || !strings.Contains(err.Error(), "ConcurrentEval") {
675 t.Errorf("ContextEval() = %v, want ConcurrentEval error", err)
676 }
677 if got := called.Load(); got != 0 {
678 t.Errorf("async function invoked %d times; the guard must reject before evaluating", got)
679 }
680}
681
682func TestSyncEvalRejectedInAsyncEnv(t *testing.T) {
683 // 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