Skip to content

Commit

Permalink
Add check for cron workflow using temporal schedule (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng authored Sep 23, 2024
1 parent 997a5d4 commit ef706ab
Show file tree
Hide file tree
Showing 6 changed files with 831 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Unit Test
on:
pull_request:
push:
branches:
- 'main'

jobs:
tests:
name: "Unit testing"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "Run unit tests"
run: make unitTests
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ stressTestsCadenceNoSearch:
stressTestsTemporalNoSearch:
$Q go test -v ./integ -repeat=10 -cadence=false -search=false | tee test.log

unitTests:
$Q go test -v ./service/...

help:
@# print help first, so it's visible
@printf "\033[36m%-20s\033[0m %s\n" 'help' 'Prints a help message showing any specially-commented targets'
Expand Down
5 changes: 5 additions & 0 deletions service/api/temporal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func (t *temporalClient) Close() {
}

func (t *temporalClient) IsWorkflowAlreadyStartedError(err error) bool {
if err.Error() == "schedule with this ID is already registered" {
// there is no type to check, just a string
// https://github.com/temporalio/sdk-go/blob/d10e87118a07b44fd09bf88d39a628f0e6e70c34/internal/error.go#L336
return true
}
return realtemporal.IsWorkflowExecutionAlreadyStartedError(err)
}

Expand Down
32 changes: 32 additions & 0 deletions service/api/temporal/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package temporal

import (
"errors"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"go.temporal.io/api/serviceerror"
"testing"
)

func TestAlreadyStartedErrorForWorkflow(t *testing.T) {
ctrl := gomock.NewController(t)
mockRealTemporalClient := NewMockClient(ctrl)
mockDataConverter := NewMockDataConverter(ctrl)

client := NewTemporalClient(mockRealTemporalClient, "test-ns", mockDataConverter, false)

err := &serviceerror.WorkflowExecutionAlreadyStarted{}
assert.Equal(t, true, client.IsWorkflowAlreadyStartedError(err))
}

func TestAlreadyStartedErrorForCronWorkflow(t *testing.T) {
ctrl := gomock.NewController(t)
mockRealTemporalClient := NewMockClient(ctrl)
mockDataConverter := NewMockDataConverter(ctrl)

client := NewTemporalClient(mockRealTemporalClient, "test-ns", mockDataConverter, false)

err := errors.New("schedule with this ID is already registered")

assert.Equal(t, true, client.IsWorkflowAlreadyStartedError(err))
}
130 changes: 130 additions & 0 deletions service/api/temporal/data_conveter_mock.go

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

Loading

0 comments on commit ef706ab

Please sign in to comment.