(t *testing.T)
| 680 | } |
| 681 | |
| 682 | func 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 | |
| 707 | func TestConcurrentEvalDrainReady(t *testing.T) { |
| 708 | cases := []struct { |
nothing calls this directly
no test coverage detected