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 unit tests for GetVersion #1389

Merged
merged 2 commits into from
Nov 6, 2024
Merged
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
5 changes: 4 additions & 1 deletion internal/internal_event_handlers.go
Original file line number Diff line number Diff line change
@@ -623,7 +623,10 @@
// Also upsert search attributes to enable ability to search by changeVersion.
version = maxSupported
wc.decisionsHelper.recordVersionMarker(changeID, version, wc.GetDataConverter())
wc.UpsertSearchAttributes(createSearchAttributesForChangeVersion(changeID, version, wc.changeVersions))
err := wc.UpsertSearchAttributes(createSearchAttributesForChangeVersion(changeID, version, wc.changeVersions))
if err != nil {
wc.logger.Warn("UpsertSearchAttributes failed", zap.Error(err))
}

Check warning on line 629 in internal/internal_event_handlers.go

Codecov / codecov/patch

internal/internal_event_handlers.go#L628-L629

Added lines #L628 - L629 were not covered by tests
}

validateVersion(changeID, version, minSupported, maxSupported)
43 changes: 43 additions & 0 deletions internal/internal_event_handlers_test.go
Original file line number Diff line number Diff line change
@@ -720,6 +720,49 @@ func TestSideEffect(t *testing.T) {
})
}

func TestGetVersion_validation(t *testing.T) {
t.Run("version < minSupported", func(t *testing.T) {
assert.PanicsWithValue(t, `Workflow code removed support of version 1. for "test" changeID. The oldest supported version is 2`, func() {
validateVersion("test", 1, 2, 3)
})
})
t.Run("version > maxSupported", func(t *testing.T) {
assert.PanicsWithValue(t, `Workflow code is too old to support version 3 for "test" changeID. The maximum supported version is 2`, func() {
validateVersion("test", 3, 1, 2)
})
})
t.Run("success", func(t *testing.T) {
validateVersion("test", 2, 1, 3)
})
}

func TestGetVersion(t *testing.T) {
t.Run("version exists", func(t *testing.T) {
weh := testWorkflowExecutionEventHandler(t, newRegistry())
weh.changeVersions = map[string]Version{
"test": 2,
}
res := weh.GetVersion("test", 1, 3)
assert.Equal(t, Version(2), res)
})
t.Run("version doesn't exist in replay", func(t *testing.T) {
weh := testWorkflowExecutionEventHandler(t, newRegistry())
weh.isReplay = true
res := weh.GetVersion("test", DefaultVersion, 3)
assert.Equal(t, DefaultVersion, res)
require.Contains(t, weh.changeVersions, "test")
assert.Equal(t, DefaultVersion, weh.changeVersions["test"])
})
t.Run("version doesn't exist without replay", func(t *testing.T) {
weh := testWorkflowExecutionEventHandler(t, newRegistry())
res := weh.GetVersion("test", DefaultVersion, 3)
assert.Equal(t, Version(3), res)
require.Contains(t, weh.changeVersions, "test")
assert.Equal(t, Version(3), weh.changeVersions["test"])
assert.Equal(t, []byte(`["test-3"]`), weh.workflowInfo.SearchAttributes.IndexedFields[CadenceChangeVersion], "ensure search attributes are updated")
})
}

func testWorkflowExecutionEventHandler(t *testing.T, registry *registry) *workflowExecutionEventHandlerImpl {
return newWorkflowExecutionEventHandler(
testWorkflowInfo,