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

Function TestConcurrentEvalAsyncObserver

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

Source from the content-addressed store, hash-verified

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