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

Function TestMemoryTrackingComprehension

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

Source from the content-addressed store, hash-verified

88}
89
90func TestMemoryTrackingComprehension(t *testing.T) {
91 env := testEnv(t, Variable("a", ListType(IntType)))
92 ast, iss := env.Compile(`a.map(x, x * 2)`)
93 if iss.Err() != nil {
94 t.Fatalf("env.Compile() failed: %v", iss.Err())
95 }
96 program, err := env.Program(ast, MemoryTracking())
97 if err != nil {
98 t.Fatalf("env.Program() failed: %v", err)
99 }
100 in := map[string]any{"a": []int64{1, 2, 3, 4, 5}}
101 _, details, err := program.Eval(in)
102 if err != nil {
103 t.Fatalf("program.Eval() failed: %v", err)
104 }
105 peak := details.PeakMemory()
106 if peak == nil {
107 t.Fatal("EvalDetails.PeakMemory() got nil, wanted non-nil peak")
108 }
109 // The comprehension result is 1 (container) + 5 elements; the peak must be at least as
110 // large since the final accumulation observes the input alongside the built list.
111 if *peak < 6 {
112 t.Errorf("EvalDetails.PeakMemory() got %d, wanted at least 6", *peak)
113 }
114}
115
116func TestMemoryTrackingConcurrentEval(t *testing.T) {
117 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
EvalMethod · 0.65

Tested by

no test coverage detected