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

Function TestFrameLifecycleAndPooling

interpreter/frame_test.go:383–422  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

381}
382
383func TestFrameLifecycleAndPooling(t *testing.T) {
384 vars := map[string]any{"a": 1, "b": 2}
385 frame := mustNewExecutionFrame(t, vars)
386 val, found := frame.ResolveName("a")
387 if !found || val != 1 {
388 t.Errorf("ResolveName('a') got %v, %t; want 1, true", val, found)
389 }
390
391 // Wrap in a hierarchical activation (e.g. simulating defaultVars setup in program.go)
392 parentAct, err := NewActivation(map[string]any{"c": 3})
393 if err != nil {
394 t.Fatalf("NewActivation failed: %v", err)
395 }
396 frame.Activation = NewHierarchicalActivation(parentAct, frame.Activation)
397
398 val, found = frame.ResolveName("c")
399 if !found || val != 3 {
400 t.Errorf("ResolveName('c') got %v, %t; want 3, true", val, found)
401 }
402
403 val, found = frame.ResolveName("a")
404 if !found || val != 1 {
405 t.Errorf("ResolveName('a') got %v, %t; want 1, true", val, found)
406 }
407
408 // Close the frame. This should release the pooled evalActivation under the hierarchical activation.
409 frame.Close()
410
411 // Verify that we can obtain a clean frame from the pool.
412 newFrame := mustNewExecutionFrame(t, map[string]any{"x": 10})
413 defer newFrame.Close()
414 val, found = newFrame.ResolveName("x")
415 if !found || val != 10 {
416 t.Errorf("ResolveName('x') got %v, %t; want 10, true", val, found)
417 }
418 val, found = newFrame.ResolveName("a")
419 if found {
420 t.Errorf("ResolveName('a') found on fresh frame: %v", val)
421 }
422}
423
424func TestFrameSetContext(t *testing.T) {
425 ctx := context.Background()

Callers

nothing calls this directly

Calls 5

mustNewExecutionFrameFunction · 0.85
CloseMethod · 0.80
NewActivationFunction · 0.70
ResolveNameMethod · 0.65

Tested by

no test coverage detected