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

Function TestAsyncObserverLifecycle

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

Source from the content-addressed store, hash-verified

351}
352
353func TestAsyncObserverLifecycle(t *testing.T) {
354 ctx, cancel := context.WithCancel(context.Background())
355 defer cancel()
356 frame, closeFrame := newTestFrame(t, ctx)
357 defer closeFrame()
358
359 obs := &recordingObserver{}
360 if err := frame.SetAsyncObserver(obs); err != nil {
361 t.Fatalf("SetAsyncObserver() failed: %v", err)
362 }
363 completions := make(chan int64, 1)
364 if err := frame.SetCompletions(completions); err != nil {
365 t.Fatalf("SetCompletions() failed: %v", err)
366 }
367
368 awaitResult(t, frame, completions, 1, "fn", "fn_int", asyncReturning(types.Int(7), nil), types.Int(1))
369
370 if got := obs.started.Load(); got != 1 {
371 t.Errorf("OnCallStarted called %d times, wanted 1", got)
372 }
373 if got := obs.finished.Load(); got != 1 {
374 t.Errorf("OnCallFinished called %d times, wanted 1", got)
375 }
376}
377
378func TestAsyncObserverOnCancellation(t *testing.T) {
379 ctx, cancel := context.WithCancelCause(context.Background())

Callers

nothing calls this directly

Calls 6

IntTypeAlias · 0.92
newTestFrameFunction · 0.85
awaitResultFunction · 0.85
asyncReturningFunction · 0.85
SetAsyncObserverMethod · 0.80
SetCompletionsMethod · 0.80

Tested by

no test coverage detected