(t *testing.T)
| 773 | } |
| 774 | |
| 775 | func 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 | |
| 799 | func TestSyncEvalRejectedInAsyncEnv(t *testing.T) { |
| 800 | // Env-level rejection: an environment that declares any async function rejects the synchronous |
nothing calls this directly
no test coverage detected