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

Function TestTrackerDedupAndCallIDs

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

Source from the content-addressed store, hash-verified

124}
125
126func TestTrackerDedupAndCallIDs(t *testing.T) {
127 // Exercise the tracker directly to keep bookkeeping assertions isolated from the
128 // process-global frame/tracker pools used by ExecutionFrame.
129 tracker := newAsyncCallStateTracker()
130 completions := make(chan int64, 4)
131 gate := newAsyncGate(0, completions)
132 impl := asyncReturning(types.Int(1), nil)
133
134 // Same node id, same args, invoked repeatedly: must dedup to a single registered call.
135 a1 := tracker.getOrCreate(1, "fn", "fn_int", []ref.Val{types.Int(1)}, impl, gate)
136 a2 := tracker.getOrCreate(1, "fn", "fn_int", []ref.Val{types.Int(1)}, impl, gate)
137 if a1 != a2 {
138 t.Error("getOrCreate returned distinct states for identical (id, args)")
139 }
140 if a1.CallID() != a2.CallID() {
141 t.Errorf("dedup callIDs differ: %d vs %d", a1.CallID(), a2.CallID())
142 }
143 if got := tracker.getByID(a1.CallID()); got != a1 {
144 t.Errorf("getByID(%d) did not return the registered call", a1.CallID())
145 }
146
147 // Same node id, different args: a new call must be registered (re-evaluation with new inputs).
148 a3 := tracker.getOrCreate(1, "fn", "fn_int", []ref.Val{types.Int(2)}, impl, gate)
149 if a3.CallID() == a1.CallID() {
150 t.Error("arg change reused the prior callID, wanted a fresh call")
151 }
152 if got := tracker.getByID(a3.CallID()); got != a3 {
153 t.Errorf("getByID(%d) did not return the second registered call", a3.CallID())
154 }
155 // Registration alone does not mark a call as in-flight; pending counts launched calls only.
156 if got := gate.ActiveCalls(); got != 0 {
157 t.Errorf("ActiveCalls() after registration only = %d, wanted 0", got)
158 }
159}
160
161func TestHashCall(t *testing.T) {
162 type hashInput struct {

Callers

nothing calls this directly

Calls 9

IntTypeAlias · 0.92
newAsyncCallStateTrackerFunction · 0.85
newAsyncGateFunction · 0.85
asyncReturningFunction · 0.85
getOrCreateMethod · 0.80
getByIDMethod · 0.80
ActiveCallsMethod · 0.80
CallIDMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected