Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for cron workflow using temporal schedule #426

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading