mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Main change is: move functional test suite scaffolding code to
`FunctionalTestBase`. Most of the scaffolding code and test helpers
(more to move) are now in `FunctionalTestBase`. Hierarchy is the
following:
```
- FunctionalTestBase - base for all functional tests
- FunctionalTestSuite - has TaskPoller in it and should be used as base for all non-SDK based tests
- many test suites such as TestUpdateWorkflowSuite.
- ...
- ...
- FunctionalTestSdkSuite - has SdkClient and SdkWorker in it and should be used as base for all SDK based tests
- many test suites such as UpdateWorkflowSdkSuite
- ...
- ...
- some test suites which don't need neither task poller nor SDK. Such as TLSFunctionalSuite
```
Few minor refactorings:
- replace `SetDynamicConfigOverrides` method with
`WithDynamicConfigOverrides` option for `SetupTestCluster()` method.
More DC cleanups are needed there.
- Many renames for better readability.
- Left few TODOs for myself, for later.
## Why?
<!-- Tell your future self why have you made these changes -->
## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
Run it.
## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
No risks.
## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->
No.
## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
No.
142 lines
5.2 KiB
Go
142 lines
5.2 KiB
Go
// The MIT License
|
|
//
|
|
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
|
|
//
|
|
// Copyright (c) 2020 Uber Technologies, Inc.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
package tests
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
updatepb "go.temporal.io/api/update/v1"
|
|
"go.temporal.io/api/workflowservice/v1"
|
|
"go.temporal.io/server/common/payloads"
|
|
"go.temporal.io/server/common/testing/testvars"
|
|
"go.temporal.io/server/tests/testcore"
|
|
)
|
|
|
|
type WorkflowUpdateBaseSuite struct {
|
|
testcore.FunctionalTestSuite
|
|
}
|
|
|
|
type updateResponseErr struct {
|
|
response *workflowservice.UpdateWorkflowExecutionResponse
|
|
err error
|
|
}
|
|
|
|
func (s *WorkflowUpdateBaseSuite) sendUpdateNoErrorWaitPolicyAccepted(tv *testvars.TestVars) <-chan *workflowservice.UpdateWorkflowExecutionResponse {
|
|
s.T().Helper()
|
|
return s.sendUpdateNoErrorInternal(tv, &updatepb.WaitPolicy{LifecycleStage: enumspb.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTED})
|
|
}
|
|
|
|
func (s *WorkflowUpdateBaseSuite) sendUpdateNoErrorInternal(tv *testvars.TestVars, waitPolicy *updatepb.WaitPolicy) <-chan *workflowservice.UpdateWorkflowExecutionResponse {
|
|
s.T().Helper()
|
|
retCh := make(chan *workflowservice.UpdateWorkflowExecutionResponse)
|
|
syncCh := make(chan struct{})
|
|
go func() {
|
|
urCh := s.sendUpdateInternal(testcore.NewContext(), tv, waitPolicy, true)
|
|
// Unblock return only after the server admits update.
|
|
syncCh <- struct{}{}
|
|
// Unblocked when an update result is ready.
|
|
retCh <- (<-urCh).response
|
|
}()
|
|
<-syncCh
|
|
return retCh
|
|
}
|
|
|
|
func (s *WorkflowUpdateBaseSuite) sendUpdateInternal(
|
|
ctx context.Context,
|
|
tv *testvars.TestVars,
|
|
waitPolicy *updatepb.WaitPolicy,
|
|
requireNoError bool,
|
|
) <-chan updateResponseErr {
|
|
|
|
s.T().Helper()
|
|
|
|
updateResultCh := make(chan updateResponseErr)
|
|
go func() {
|
|
updateResp, updateErr := s.FrontendClient().UpdateWorkflowExecution(ctx, s.updateWorkflowRequest(tv, waitPolicy))
|
|
// It is important to do assert here (before writing to channel which doesn't have readers yet)
|
|
// to fail fast without trying to process update in wtHandler.
|
|
if requireNoError {
|
|
require.NoError(s.T(), updateErr)
|
|
}
|
|
updateResultCh <- updateResponseErr{response: updateResp, err: updateErr}
|
|
}()
|
|
s.waitUpdateAdmitted(tv)
|
|
return updateResultCh
|
|
}
|
|
|
|
func (s *WorkflowUpdateBaseSuite) updateWorkflowRequest(
|
|
tv *testvars.TestVars,
|
|
waitPolicy *updatepb.WaitPolicy,
|
|
) *workflowservice.UpdateWorkflowExecutionRequest {
|
|
return &workflowservice.UpdateWorkflowExecutionRequest{
|
|
Namespace: s.Namespace().String(),
|
|
WorkflowExecution: tv.WorkflowExecution(),
|
|
WaitPolicy: waitPolicy,
|
|
Request: &updatepb.Request{
|
|
Meta: &updatepb.Meta{UpdateId: tv.UpdateID()},
|
|
Input: &updatepb.Input{
|
|
Name: tv.HandlerName(),
|
|
Args: payloads.EncodeString("args-value-of-" + tv.UpdateID()),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (s *WorkflowUpdateBaseSuite) waitUpdateAdmitted(tv *testvars.TestVars) {
|
|
s.T().Helper()
|
|
s.EventuallyWithTf(func(collect *assert.CollectT) {
|
|
pollResp, pollErr := s.FrontendClient().PollWorkflowExecutionUpdate(testcore.NewContext(), &workflowservice.PollWorkflowExecutionUpdateRequest{
|
|
Namespace: s.Namespace().String(),
|
|
UpdateRef: tv.UpdateRef(),
|
|
WaitPolicy: &updatepb.WaitPolicy{LifecycleStage: enumspb.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_UNSPECIFIED},
|
|
})
|
|
|
|
assert.NoError(collect, pollErr)
|
|
assert.GreaterOrEqual(collect, pollResp.GetStage(), enumspb.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ADMITTED)
|
|
}, 5*time.Second, 10*time.Millisecond, "update %s did not reach Admitted stage", tv.UpdateID())
|
|
}
|
|
|
|
func (s *WorkflowUpdateBaseSuite) startWorkflow(tv *testvars.TestVars) string {
|
|
s.T().Helper()
|
|
startResp, err := s.FrontendClient().StartWorkflowExecution(testcore.NewContext(), s.startWorkflowRequest(tv))
|
|
s.NoError(err)
|
|
|
|
return startResp.GetRunId()
|
|
}
|
|
|
|
func (s *WorkflowUpdateBaseSuite) startWorkflowRequest(tv *testvars.TestVars) *workflowservice.StartWorkflowExecutionRequest {
|
|
return &workflowservice.StartWorkflowExecutionRequest{
|
|
RequestId: tv.Any().String(),
|
|
Namespace: s.Namespace().String(),
|
|
WorkflowId: tv.WorkflowID(),
|
|
WorkflowType: tv.WorkflowType(),
|
|
TaskQueue: tv.TaskQueue(),
|
|
}
|
|
}
|