Skip to content

Commit

Permalink
fix: fixes client StartWorkflowOptions timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
cludden committed Oct 22, 2023
1 parent 51b472a commit ba60038
Show file tree
Hide file tree
Showing 11 changed files with 2,188 additions and 799 deletions.
16 changes: 16 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
with-expecter: true
packages:
go.temporal.io/sdk/internal:
config:
dir: mocks/go.temporal.io/sdk/clientutils
outpkg: clientutils
replace-type:
- go.temporal.io/sdk/internal=go.temporal.io/sdk/client
interfaces:
WorkflowRun: {}
go.temporal.io/sdk/client:
config:
replace-type:
- go.temporal.io/sdk/internal=go.temporal.io/sdk/client
interfaces:
Client: {}
56 changes: 56 additions & 0 deletions example/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"context"
"errors"
"fmt"
"testing"
"time"

examplev1 "github.com/cludden/protoc-gen-go-temporal/gen/example/v1"
clientMock "github.com/cludden/protoc-gen-go-temporal/mocks/go.temporal.io/sdk/client"
"github.com/cludden/protoc-gen-go-temporal/mocks/go.temporal.io/sdk/clientutils"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.temporal.io/sdk/client"
)

func TestCreateFooStartWorkflowOptions(t *testing.T) {
ctx, require := context.Background(), require.New(t)

c := clientMock.NewMockClient(t)
c.On("ExecuteWorkflow", mock.Anything, mock.Anything, examplev1.CreateFooWorkflowName, mock.Anything).Return(
func(ctx context.Context, opts client.StartWorkflowOptions, workflow any, params ...any) (run client.WorkflowRun, err error) {
if opts.ID != "create-foo/bar" {
err = errors.Join(err, fmt.Errorf("expected workflow id to equal 'create-foo/bar', got: %q", opts.ID))
}
if opts.WorkflowExecutionTimeout != time.Hour {
err = errors.Join(err, fmt.Errorf("expected workflow execution timeout to equal 1h, got: %s", opts.WorkflowExecutionTimeout))
}
if len(opts.SearchAttributes) != 2 {
err = errors.Join(err, fmt.Errorf("expected 2 search attributes, got: %d", len(opts.SearchAttributes)))
}
if raw, ok := opts.SearchAttributes["foo"]; !ok {
err = errors.Join(err, fmt.Errorf("expected search attributes to contain 'foo' attribute"))
} else if v, ok := raw.(string); !ok {
err = errors.Join(err, fmt.Errorf("expected 'foo' attribute to be string, got: %T", raw))
} else if v != "bar" {
err = errors.Join(err, fmt.Errorf("expected 'foo' to equal 'bar', got: %q", v))
}
if raw, ok := opts.SearchAttributes["created_at"]; !ok {
err = errors.Join(err, fmt.Errorf("expected search attributes to contain 'created_at' attribute"))
} else if v, ok := raw.(time.Time); !ok {
err = errors.Join(err, fmt.Errorf("expected 'created_at' attribute to be string, got: %T", raw))
} else if time.Since(v) > time.Second {
err = errors.Join(err, fmt.Errorf("expected 'created_at' to be within 1s: %q", v))
}
if err != nil {
return nil, err
}
return clientutils.NewMockWorkflowRun(t), nil
},
)
example := examplev1.NewExampleClient(c)
_, err := example.CreateFooAsync(ctx, &examplev1.CreateFooRequest{Name: "bar"})
require.NoError(err)
}
3 changes: 1 addition & 2 deletions example/proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: v1
name: buf.build/cludden/protoc-gen-go-temporal-example
deps:
- buf.build/cludden/protoc-gen-go-temporal:v0.8.0
- buf.build/googleapis/googleapis
- buf.build/cludden/protoc-gen-go-temporal
breaking:
use:
- FILE
Expand Down
3 changes: 3 additions & 0 deletions example/proto/example/v1/example.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ service Example {
execution_timeout: { seconds: 3600 }
id_reuse_policy: WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
id: 'create-foo/${!name.slug()}'
search_attributes:
'foo = name\n'
'created_at = now().ts_tz("UTC")\n'
query: { ref: 'GetFooProgress' }
signal: { ref: 'SetFooProgress', start: true }
update: { ref: 'UpdateFooProgress' }
Expand Down
91 changes: 47 additions & 44 deletions gen/example/v1/example.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 70 additions & 5 deletions gen/example/v1/example_temporal.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ba60038

Please sign in to comment.