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

Function TestConcurrentEvalDrainReady

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

Source from the content-addressed store, hash-verified

862}
863
864func TestConcurrentEvalDrainReady(t *testing.T) {
865 cases := []struct {
866 name string
867 expr string
868 debounce time.Duration
869 want ref.Val
870 wantPasses int
871 minElapsed time.Duration
872 }{
873 {
874 name: "timer_reset",
875 expr: `delayed_rpc("a", 10) + delayed_rpc("b", 25) + delayed_rpc("c", 200)`,
876 debounce: 250 * time.Millisecond,
877 want: types.String("abc"),
878 wantPasses: 2,
879 minElapsed: 200 * time.Millisecond,
880 },
881 {
882 name: "timer_reset",
883 expr: `delayed_rpc("a", 10) + delayed_rpc("b", 25) + delayed_rpc("c", 200)`,
884 debounce: 60 * time.Millisecond,
885 want: types.String("abc"),
886 wantPasses: 3,
887 minElapsed: 200 * time.Millisecond,
888 },
889 {
890 name: "timer_already_fired",
891 expr: `delayed_rpc("a", 5) + delayed_rpc("b", 30) + delayed_rpc("c", 200)`,
892 debounce: 1 * time.Millisecond,
893 want: types.String("abc"),
894 wantPasses: 4,
895 minElapsed: 200 * time.Millisecond,
896 },
897 }
898
899 for _, tc := range cases {
900 t.Run(tc.name, func(t *testing.T) {
901 var evalPasses atomic.Int32
902 opts := []any{
903 cel.Function("delayed_rpc",
904 cel.Overload("delayed_rpc_string_int", []*cel.Type{cel.StringType, cel.IntType}, cel.StringType,
905 cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val {
906 msg := string(args[0].(types.String))
907 delayMs := time.Duration(int64(args[1].(types.Int))) * time.Millisecond
908 time.Sleep(delayMs)
909 return types.String(msg)
910 }),
911 ),
912 ),
913 cel.ConcurrentDrainStrategy(async.DrainReady(tc.debounce)),
914 trackEvalPasses(&evalPasses),
915 }
916
917 start := time.Now()
918 prg := mustProgram(t, tc.expr, opts...)
919 res := awaitEval(context.Background(), t, prg, cel.NoVars())
920 elapsed := time.Since(start)
921

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