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 --> Update Temporal Worker's identity so it can be recognized by users ## Why? <!-- Tell your future self why have you made these changes --> The worker terminology is confusing to customers ## How did you test it? <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> ## Potential risks <!-- Assuming the worst case, what can be broken when deploying this change to production? --> ## 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/`? --> ## Is hotfix candidate? <!-- Is this PR a hotfix candidate or does it require a notification to be sent to the broader community? (Yes/No) --> --------- Co-authored-by: David Reiss <[email protected]>
98 lines
3.9 KiB
Go
98 lines
3.9 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 scanner
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/suite"
|
|
"go.temporal.io/sdk/activity"
|
|
"go.temporal.io/sdk/testsuite"
|
|
"go.temporal.io/sdk/worker"
|
|
"go.temporal.io/sdk/workflow"
|
|
p "go.temporal.io/server/common/persistence"
|
|
"go.temporal.io/server/common/primitives"
|
|
"go.temporal.io/server/common/resourcetest"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
type scannerWorkflowTestSuite struct {
|
|
suite.Suite
|
|
testsuite.WorkflowTestSuite
|
|
}
|
|
|
|
func TestScannerWorkflowTestSuite(t *testing.T) {
|
|
suite.Run(t, new(scannerWorkflowTestSuite))
|
|
}
|
|
|
|
func (s *scannerWorkflowTestSuite) registerWorkflows(env *testsuite.TestWorkflowEnvironment) {
|
|
env.RegisterWorkflowWithOptions(TaskQueueScannerWorkflow, workflow.RegisterOptions{Name: tqScannerWFTypeName})
|
|
env.RegisterWorkflowWithOptions(HistoryScannerWorkflow, workflow.RegisterOptions{Name: historyScannerWFTypeName})
|
|
env.RegisterActivityWithOptions(TaskQueueScavengerActivity, activity.RegisterOptions{Name: taskQueueScavengerActivityName})
|
|
env.RegisterActivityWithOptions(HistoryScavengerActivity, activity.RegisterOptions{Name: historyScavengerActivityName})
|
|
}
|
|
|
|
func (s *scannerWorkflowTestSuite) registerActivities(env *testsuite.TestActivityEnvironment) {
|
|
env.RegisterActivityWithOptions(TaskQueueScavengerActivity, activity.RegisterOptions{Name: taskQueueScavengerActivityName})
|
|
env.RegisterActivityWithOptions(HistoryScavengerActivity, activity.RegisterOptions{Name: historyScavengerActivityName})
|
|
}
|
|
|
|
func (s *scannerWorkflowTestSuite) TestWorkflow() {
|
|
env := s.NewTestWorkflowEnvironment()
|
|
s.registerWorkflows(env)
|
|
env.OnActivity(taskQueueScavengerActivityName, mock.Anything).Return(nil)
|
|
env.ExecuteWorkflow(tqScannerWFTypeName)
|
|
s.True(env.IsWorkflowCompleted())
|
|
}
|
|
|
|
func (s *scannerWorkflowTestSuite) TestScavengerActivity() {
|
|
env := s.NewTestActivityEnvironment()
|
|
s.registerActivities(env)
|
|
controller := gomock.NewController(s.T())
|
|
defer controller.Finish()
|
|
mockResource := resourcetest.NewTest(controller, primitives.WorkerService)
|
|
|
|
mockResource.TaskMgr.EXPECT().ListTaskQueue(gomock.Any(), gomock.Any()).Return(&p.ListTaskQueueResponse{}, nil)
|
|
|
|
ctx := scannerContext{
|
|
logger: mockResource.GetLogger(),
|
|
metricsHandler: mockResource.GetMetricsHandler(),
|
|
executionManager: mockResource.GetExecutionManager(),
|
|
taskManager: mockResource.GetTaskManager(),
|
|
historyClient: mockResource.GetHistoryClient(),
|
|
hostInfo: mockResource.GetHostInfo(),
|
|
}
|
|
env.SetTestTimeout(time.Second * 5)
|
|
env.SetWorkerOptions(worker.Options{
|
|
BackgroundActivityContext: context.WithValue(context.Background(), scannerContextKey, ctx),
|
|
})
|
|
tlScavengerHBInterval = time.Millisecond * 10
|
|
_, err := env.ExecuteActivity(taskQueueScavengerActivityName)
|
|
s.NoError(err)
|
|
}
|