(t *testing.T)
| 602 | } |
| 603 | |
| 604 | func TestConcurrentEvalProgramThreadSafety(t *testing.T) { |
| 605 | prg := mustProgram(t, `async_func(x) + 1`, |
| 606 | cel.Variable("x", cel.IntType), |
| 607 | cel.Function("async_func", |
| 608 | cel.Overload("async_func_int", []*cel.Type{cel.IntType}, cel.IntType, |
| 609 | cel.AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val { |
| 610 | time.Sleep(5 * time.Millisecond) |
| 611 | return args[0] |
| 612 | }), |
| 613 | ), |
| 614 | ), |
| 615 | ) |
| 616 | |
| 617 | const numGoroutines = 10 |
| 618 | errCh := make(chan error, numGoroutines) |
| 619 | for i := range numGoroutines { |
| 620 | go func(val int64) { |
| 621 | res := awaitEval(context.Background(), t, prg, map[string]any{"x": val}) |
| 622 | if res.Err != nil { |
| 623 | errCh <- res.Err |
| 624 | return |
| 625 | } |
| 626 | if res.Val.Equal(types.Int(val+1)) != types.True { |
| 627 | errCh <- errors.New("unexpected eval result") |
| 628 | return |
| 629 | } |
| 630 | errCh <- nil |
| 631 | }(int64(i * 10)) |
| 632 | } |
| 633 | |
| 634 | for range numGoroutines { |
| 635 | if err := <-errCh; err != nil { |
| 636 | t.Errorf("Concurrent thread safety evaluation failed: %v", err) |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | // TestConcurrentEvalDetailsAfterPublish is a regression test for a data race on the EvalDetails |
| 642 | // returned by ConcurrentEval. |
nothing calls this directly
no test coverage detected