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

Function TestConcurrentEvalDrainReady

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

Source from the content-addressed store, hash-verified

705}
706
707func TestConcurrentEvalDrainReady(t *testing.T) {
708 cases := []struct {
709 name string
710 expr string
711 debounce time.Duration
712 want ref.Val
713 wantPasses int
714 minElapsed time.Duration
715 }{
716 {
717 name: "timer_reset",
718 expr: `delayed_rpc("a", 10) + delayed_rpc("b", 25) + delayed_rpc("c", 200)`,
719 debounce: 250 * time.Millisecond,
720 want: types.String("abc"),
721 wantPasses: 2,
722 minElapsed: 200 * time.Millisecond,
723 },
724 {
725 name: "timer_reset",
726 expr: `delayed_rpc("a", 10) + delayed_rpc("b", 25) + delayed_rpc("c", 200)`,
727 debounce: 60 * time.Millisecond,
728 want: types.String("abc"),
729 wantPasses: 3,
730 minElapsed: 200 * time.Millisecond,
731 },
732 {
733 name: "timer_already_fired",
734 expr: `delayed_rpc("a", 5) + delayed_rpc("b", 30) + delayed_rpc("c", 200)`,
735 debounce: 1 * time.Millisecond,
736 want: types.String("abc"),
737 wantPasses: 4,
738 minElapsed: 200 * time.Millisecond,
739 },
740 }
741
742 for _, tc := range cases {
743 t.Run(tc.name, func(t *testing.T) {
744 var evalPasses atomic.Int32
745 opts := []any{
746 cel.Function("delayed_rpc",
747 cel.Overload("delayed_rpc_string_int", []*cel.Type{cel.StringType, cel.IntType}, cel.StringType,
748 cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val {
749 msg := string(args[0].(types.String))
750 delayMs := time.Duration(int64(args[1].(types.Int))) * time.Millisecond
751 time.Sleep(delayMs)
752 return types.String(msg)
753 }),
754 ),
755 ),
756 cel.ConcurrentDrainStrategy(async.DrainReady(tc.debounce)),
757 trackEvalPasses(&evalPasses),
758 }
759
760 start := time.Now()
761 prg := mustProgram(t, tc.expr, opts...)
762 res := awaitEval(t, prg, context.Background(), cel.NoVars())
763 elapsed := time.Since(start)
764

Callers

nothing calls this directly

Calls 11

StringTypeAlias · 0.92
FunctionFunction · 0.92
OverloadFunction · 0.92
AsyncBindingFunction · 0.92
ConcurrentDrainStrategyFunction · 0.92
DrainReadyFunction · 0.92
NoVarsFunction · 0.92
trackEvalPassesFunction · 0.85
mustProgramFunction · 0.85
awaitEvalFunction · 0.85
EqualMethod · 0.65

Tested by

no test coverage detected