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

Function TestConcurrentEvalCancelDuringDebounce

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

Source from the content-addressed store, hash-verified

938}
939
940func 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
973func TestConcurrentEvalRecover(t *testing.T) {
974 env, err := cel.NewEnv(

Callers

nothing calls this directly

Calls 10

FunctionFunction · 0.92
OverloadFunction · 0.92
AsyncBindingFunction · 0.92
StringTypeAlias · 0.92
ConcurrentDrainStrategyFunction · 0.92
DrainReadyFunction · 0.92
NoVarsFunction · 0.92
mustProgramFunction · 0.85
ConcurrentEvalMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected