(t *testing.T)
| 938 | } |
| 939 | |
| 940 | func TestConcurrentEvalCancelDuringDebounce(t *testing.T) { |
| 941 | // Tests context cancellation while awaiting a debounce timeout in the completion drain loop. |
| 942 | prg := mustProgram(t, `delayed_rpc("first", 10) + delayed_rpc("second", 1000)`, |
| 943 | cel.Function("delayed_rpc", |
| 944 | cel.Overload("delayed_rpc_string_int", []*cel.Type{cel.StringType, cel.IntType}, cel.StringType, |
| 945 | cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val { |
| 946 | msg := string(args[0].(types.String)) |
| 947 | delayMs := time.Duration(int64(args[1].(types.Int))) * time.Millisecond |
| 948 | time.Sleep(delayMs) |
| 949 | return types.String(msg) |
| 950 | }), |
| 951 | ), |
| 952 | ), |
| 953 | cel.ConcurrentDrainStrategy(async.DrainReady(10*time.Second)), |
| 954 | ) |
| 955 | |
| 956 | ctx, cancel := context.WithCancel(context.Background()) |
| 957 | resCh := prg.ConcurrentEval(ctx, cel.NoVars()) |
| 958 | |
| 959 | // Wait for the first call (10ms) to complete and enter the 10-second debounce wait. |
| 960 | time.Sleep(30 * time.Millisecond) |
| 961 | cancel() |
| 962 | |
| 963 | select { |
| 964 | case res := <-resCh: |
| 965 | if res.Err == nil || !errors.Is(res.Err, context.Canceled) { |
| 966 | t.Fatalf("ConcurrentEval() error = %v, want context.Canceled", res.Err) |
| 967 | } |
| 968 | case <-time.After(5 * time.Second): |
| 969 | t.Fatal("ConcurrentEval() timed out waiting for cancellation during debounce") |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | func TestConcurrentEvalRecover(t *testing.T) { |
| 974 | env, err := cel.NewEnv( |
nothing calls this directly
no test coverage detected