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

Function TestExecutionFrameChildSharesAsyncContext

interpreter/async_test.go:766–811  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

764}
765
766func TestExecutionFrameChildSharesAsyncContext(t *testing.T) {
767 ctx, cancel := context.WithCancel(context.Background())
768 defer cancel()
769 frame, closeFrame := newTestFrame(t, ctx)
770 defer closeFrame()
771
772 completions := make(chan int64, 1)
773 if err := frame.SetCompletions(completions); err != nil {
774 t.Fatalf("SetCompletions() failed: %v", err)
775 }
776
777 // Counts are taken relative to a baseline, since ExecutionFrame draws its tracker from a
778 // process-global pool whose starting pending count is not guaranteed to be zero.
779 base := frame.ActiveAsyncCalls()
780
781 child := frame.Push(EmptyActivation())
782 if got := child.ActiveAsyncCalls(); got != base {
783 t.Errorf("child ActiveAsyncCalls() = %d, wanted %d (shared parent ctx)", got, base)
784 }
785
786 // A call launched from the child frame must be visible through the shared parent tracker.
787 resChild := child.ComputeResult(1, "fn", "fn_int", asyncReturning(types.Int(5), nil), []ref.Val{types.Int(1)})
788 if unk, ok := resChild.(*types.Unknown); ok {
789 child.DispatchPendingAsyncCalls(unk.IDs())
790 }
791 if got := child.ActiveAsyncCalls(); got != base+1 {
792 t.Errorf("child ActiveAsyncCalls() after launch = %d, wanted %d", got, base+1)
793 }
794
795 parent := child.Pop()
796 if parent != frame {
797 t.Fatalf("Pop() did not return the parent frame")
798 }
799 if got := frame.ActiveAsyncCalls(); got != base+1 {
800 t.Errorf("parent ActiveAsyncCalls() after Pop = %d, wanted %d", got, base+1)
801 }
802 // The launched call is retrievable via the parent frame's AsyncCall accessor.
803 select {
804 case callID := <-completions:
805 if call := frame.AsyncCall(callID); call == nil {
806 t.Errorf("AsyncCall(%d) = nil, wanted a call record from the shared tracker", callID)
807 }
808 case <-time.After(2 * time.Second):
809 t.Fatal("timed out waiting for child call completion")
810 }
811}
812
813type recordingObserver struct {
814 started atomic.Int32

Callers

nothing calls this directly

Calls 12

IntTypeAlias · 0.92
newTestFrameFunction · 0.85
EmptyActivationFunction · 0.85
asyncReturningFunction · 0.85
SetCompletionsMethod · 0.80
ActiveAsyncCallsMethod · 0.80
ComputeResultMethod · 0.80
AsyncCallMethod · 0.80
IDsMethod · 0.65
PushMethod · 0.45
PopMethod · 0.45

Tested by

no test coverage detected