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

Function TestMemoryTrackingConcurrentEval

cel/memory_test.go:116–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

114}
115
116func TestMemoryTrackingConcurrentEval(t *testing.T) {
117 env := testEnv(t, Variable("a", ListType(IntType)))
118 ast, iss := env.Compile(`a + a`)
119 if iss.Err() != nil {
120 t.Fatalf("env.Compile() failed: %v", iss.Err())
121 }
122 program, err := env.Program(ast, MemoryTracking())
123 if err != nil {
124 t.Fatalf("env.Program() failed: %v", err)
125 }
126 ctx, cancel := context.WithCancel(context.Background())
127 defer cancel()
128 res := <-program.ConcurrentEval(ctx, map[string]any{"a": []int64{1, 2}})
129 if res.Err != nil {
130 t.Fatalf("program.ConcurrentEval() failed: %v", res.Err)
131 }
132 peak := res.EvalDetails.PeakMemory()
133 if peak == nil {
134 t.Fatal("EvalDetails.PeakMemory() got nil, wanted non-nil peak")
135 }
136 if *peak != 6 {
137 t.Errorf("EvalDetails.PeakMemory() got %d, wanted 6", *peak)
138 }
139}
140
141func TestMemoryTrackingDisabled(t *testing.T) {
142 env := testEnv(t, Variable("a", ListType(IntType)))

Callers

nothing calls this directly

Calls 8

MemoryTrackingFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
PeakMemoryMethod · 0.80
testEnvFunction · 0.70
VariableFunction · 0.70
CompileMethod · 0.65
ConcurrentEvalMethod · 0.65

Tested by

no test coverage detected