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

Function TestConcurrentEvalAsyncObserver

cel/program_async_test.go:575–601  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

573}
574
575func TestConcurrentEvalAsyncObserver(t *testing.T) {
576 obs := &countingObserver{}
577 prg := mustProgram(t, `async_func(10) + async_func(20)`,
578 cel.Function("async_func",
579 cel.Overload("async_func_int", []*cel.Type{cel.IntType}, cel.IntType,
580 cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val {
581 time.Sleep(5 * time.Millisecond)
582 return args[0]
583 }),
584 ),
585 ),
586 cel.AsyncCallObserver(obs),
587 )
588 res := awaitEval(t, prg, context.Background(), cel.NoVars())
589 if res.Err != nil {
590 t.Fatalf("ConcurrentEval() error: %v", res.Err)
591 }
592 if res.Val.Equal(types.Int(30)) != types.True {
593 t.Errorf("ConcurrentEval() = %v, want 30", res.Val)
594 }
595 if got := obs.started.Load(); got != 2 {
596 t.Errorf("OnCallStarted count = %d, want 2", got)
597 }
598 if got := obs.finished.Load(); got != 2 {
599 t.Errorf("OnCallFinished count = %d, want 2", got)
600 }
601}
602
603func TestConcurrentEvalProgramThreadSafety(t *testing.T) {
604 prg := mustProgram(t, `async_func(x) + 1`,

Callers

nothing calls this directly

Calls 9

FunctionFunction · 0.92
OverloadFunction · 0.92
AsyncBindingFunction · 0.92
AsyncCallObserverFunction · 0.92
NoVarsFunction · 0.92
IntTypeAlias · 0.92
mustProgramFunction · 0.85
awaitEvalFunction · 0.85
EqualMethod · 0.65

Tested by

no test coverage detected