(t *testing.T)
| 360 | } |
| 361 | |
| 362 | func TestTrackerComprehensionReuse(t *testing.T) { |
| 363 | // Regression: a single AST node id evaluated repeatedly with distinct argument values (as |
| 364 | // happens for an async call inside a comprehension) must register one call per distinct |
| 365 | // argument set, and re-lookups must return the existing state rather than relaunching. A |
| 366 | // node-id-keyed map collapses these into a single slot, causing every re-evaluation pass to |
| 367 | // relaunch every iteration and never converge. |
| 368 | tracker := newAsyncCallStateTracker() |
| 369 | completions := make(chan int64, 8) |
| 370 | gate := newAsyncGate(0, completions) |
| 371 | impl := asyncReturning(types.Int(0), nil) |
| 372 | const id = int64(1) |
| 373 | |
| 374 | args := [][]ref.Val{ |
| 375 | {types.Int(1)}, |
| 376 | {types.Int(2)}, |
| 377 | {types.Int(3)}, |
| 378 | } |
| 379 | states := make([]*asyncCallState, len(args)) |
| 380 | for i, a := range args { |
| 381 | states[i] = tracker.getOrCreate(id, "fn", "fn_int", a, impl, gate) |
| 382 | } |
| 383 | |
| 384 | // Each distinct argument set is a distinct, uniquely-identified call. |
| 385 | seen := map[int64]bool{} |
| 386 | for _, s := range states { |
| 387 | if seen[s.CallID()] { |
| 388 | t.Errorf("duplicate callID %d across distinct args", s.CallID()) |
| 389 | } |
| 390 | seen[s.CallID()] = true |
| 391 | } |
| 392 | |
| 393 | // Re-evaluation: every prior (id, args) tuple must resolve to its existing state and must |
| 394 | // not register a new call. |
| 395 | for i, a := range args { |
| 396 | if got := tracker.getOrCreate(id, "fn", "fn_int", a, impl, gate); got != states[i] { |
| 397 | t.Errorf("re-lookup of args %v returned a new state, wanted the existing one", a) |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | // Identical string arguments at the same node dedup to a single call. |
| 402 | s1 := tracker.getOrCreate(2, "fn", "fn_str", []ref.Val{types.String("k")}, impl, gate) |
| 403 | s2 := tracker.getOrCreate(2, "fn", "fn_str", []ref.Val{types.String("k")}, impl, gate) |
| 404 | if s1 != s2 { |
| 405 | t.Error("identical string args did not dedup to a single call") |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | func TestTrackerRegistrationLookup(t *testing.T) { |
| 410 | tracker := newAsyncCallStateTracker() |
nothing calls this directly
no test coverage detected