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

Function TestSyncEvalRejectedInAsyncEnv

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

Source from the content-addressed store, hash-verified

680}
681
682func TestSyncEvalRejectedInAsyncEnv(t *testing.T) {
683 // Env-level rejection: an environment that declares any async function rejects the synchronous
684 // entry points even for an expression that does not call the async function. Callers needing
685 // synchronous evaluation should build a separate, non-async environment.
686 prg := mustProgram(t, `x + 1`, // pure, synchronous, does not use rpc
687 cel.Variable("x", cel.IntType),
688 cel.Function("rpc",
689 cel.Overload("rpc_string", []*cel.Type{cel.StringType}, cel.StringType,
690 cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val { return args[0] }))),
691 )
692 if _, _, err := prg.Eval(map[string]any{"x": 1}); err == nil || !strings.Contains(err.Error(), "ConcurrentEval") {
693 t.Errorf("Eval() in async env = %v, want ConcurrentEval error", err)
694 }
695
696 // A separate non-async env evaluates the same expression synchronously.
697 syncPrg := mustProgram(t, `x + 1`, cel.Variable("x", cel.IntType))
698 out, _, err := syncPrg.Eval(map[string]any{"x": 1})
699 if err != nil {
700 t.Fatalf("Eval() in non-async env returned error: %v", err)
701 }
702 if out.Equal(types.Int(2)) != types.True {
703 t.Errorf("Eval() = %v, want 2", out)
704 }
705}
706
707func TestConcurrentEvalDrainReady(t *testing.T) {
708 cases := []struct {

Callers

nothing calls this directly

Calls 10

VariableFunction · 0.92
FunctionFunction · 0.92
OverloadFunction · 0.92
AsyncBindingFunction · 0.92
IntTypeAlias · 0.92
mustProgramFunction · 0.85
EvalMethod · 0.65
ContainsMethod · 0.65
EqualMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected