(t *testing.T)
| 573 | } |
| 574 | |
| 575 | func 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 | |
| 603 | func TestConcurrentEvalProgramThreadSafety(t *testing.T) { |
| 604 | prg := mustProgram(t, `async_func(x) + 1`, |
nothing calls this directly
no test coverage detected