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

Function TestAsyncObserverLifecycle

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

Source from the content-addressed store, hash-verified

428}
429
430func TestAsyncObserverLifecycle(t *testing.T) {
431 ctx, cancel := context.WithCancel(context.Background())
432 defer cancel()
433 frame, closeFrame := newTestFrame(t, ctx)
434 defer closeFrame()
435
436 obs := &recordingObserver{}
437 if err := frame.SetAsyncObserver(obs); err != nil {
438 t.Fatalf("SetAsyncObserver() failed: %v", err)
439 }
440 completions := make(chan int64, 1)
441 if err := frame.SetCompletions(completions); err != nil {
442 t.Fatalf("SetCompletions() failed: %v", err)
443 }
444
445 awaitResult(t, frame, completions, 1, "fn", "fn_int", asyncReturning(types.Int(7), nil), types.Int(1))
446
447 if got := obs.started.Load(); got != 1 {
448 t.Errorf("OnCallStarted called %d times, wanted 1", got)
449 }
450 if got := obs.finished.Load(); got != 1 {
451 t.Errorf("OnCallFinished called %d times, wanted 1", got)
452 }
453}
454
455func TestAsyncObserverOnCancellation(t *testing.T) {
456 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