| 616 | } |
| 617 | |
| 618 | func NewTemporalClient(t *testing.T) client.Client { |
| 619 | t.Helper() |
| 620 | |
| 621 | logger := slog.New(shared.NewSlogHandler( |
| 622 | slog.NewJSONHandler( |
| 623 | &testWriter{t}, |
| 624 | &slog.HandlerOptions{Level: slog.LevelWarn}, |
| 625 | ), |
| 626 | )) |
| 627 | |
| 628 | var lastErr error |
| 629 | deadline := time.Now().Add(time.Minute) |
| 630 | for attempt := 1; ; attempt++ { |
| 631 | tc, err := client.Dial(client.Options{ |
| 632 | HostPort: "localhost:7233", |
| 633 | Logger: logger, |
| 634 | }) |
| 635 | if err == nil { |
| 636 | return tc |
| 637 | } |
| 638 | lastErr = err |
| 639 | if ctxErr := t.Context().Err(); ctxErr != nil { |
| 640 | t.Fatalf("Failed to connect temporal client: %v", ctxErr) |
| 641 | } |
| 642 | if time.Now().After(deadline) { |
| 643 | t.Fatalf("Failed to connect temporal client after %d attempts: %v", attempt, lastErr) |
| 644 | } |
| 645 | t.Logf("Temporal client dial attempt %d failed: %v", attempt, err) |
| 646 | time.Sleep(time.Second) |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | func NewApiClient() (protos.FlowServiceClient, error) { |
| 651 | client, err := grpc.NewClient("0.0.0.0:8112", grpc.WithTransportCredentials(insecure.NewCredentials())) |