diff --git a/common/testing/taskpoller/taskpoller.go b/common/testing/taskpoller/taskpoller.go index 15c3e355009..6b2bfa82012 100644 --- a/common/testing/taskpoller/taskpoller.go +++ b/common/testing/taskpoller/taskpoller.go @@ -28,7 +28,6 @@ import ( "context" "errors" "fmt" - "testing" "time" "github.com/nexus-rpc/sdk-go/nexus" @@ -47,8 +46,11 @@ import ( ) type ( + Helper interface { + Helper() + } TaskPoller struct { - t *testing.T + t Helper client workflowservice.WorkflowServiceClient namespace string } @@ -95,7 +97,7 @@ var ( ) func New( - t *testing.T, + t Helper, client workflowservice.WorkflowServiceClient, namespace string, ) *TaskPoller { diff --git a/tests/acquire_shard_test.go b/tests/acquire_shard_test.go index 4d0da3ee78d..d76b281c14f 100644 --- a/tests/acquire_shard_test.go +++ b/tests/acquire_shard_test.go @@ -57,7 +57,7 @@ func (s *AcquireShardSuiteBase) SetupSuite() { func (s *AcquireShardSuiteBase) TearDownSuite() { // we need to wait for all components to start before we can safely tear down time.Sleep(time.Second * 5) //nolint:forbidigo - s.FunctionalTestBase.TearDownSuite() + s.FunctionalTestBase.TearDownCluster() } // newLogRecorder creates a new log recorder. It records all the logs to the given channel. @@ -126,7 +126,7 @@ func TestAcquireShard_OwnershipLostErrorSuite(t *testing.T) { // SetupSuite reads the shard ownership lost error fault injection config from the testdata folder. func (s *OwnershipLostErrorSuite) SetupSuite() { s.AcquireShardSuiteBase.SetupSuite() - s.FunctionalTestBase.SetupSuite("testdata/acquire_shard_ownership_lost_error.yaml") + s.FunctionalTestBase.SetupSuiteWithCluster("testdata/acquire_shard_ownership_lost_error.yaml") } // TestDoesNotRetry verifies that we do not retry acquiring the shard when we get an ownership lost error. @@ -175,7 +175,7 @@ func TestAcquireShard_DeadlineExceededErrorSuite(t *testing.T) { // SetupSuite reads the deadline exceeded error targeted fault injection config from the test data folder. func (s *DeadlineExceededErrorSuite) SetupSuite() { s.AcquireShardSuiteBase.SetupSuite() - s.FunctionalTestBase.SetupSuite("testdata/acquire_shard_deadline_exceeded_error.yaml") + s.FunctionalTestBase.SetupSuiteWithCluster("testdata/acquire_shard_deadline_exceeded_error.yaml") } // TestDoesRetry verifies that we do retry acquiring the shard when we get a deadline exceeded error because that should @@ -226,7 +226,7 @@ func TestAcquireShard_EventualSuccess(t *testing.T) { // the next call to return a successful response. func (s *EventualSuccessSuite) SetupSuite() { s.AcquireShardSuiteBase.SetupSuite() - s.FunctionalTestBase.SetupSuite("testdata/acquire_shard_eventual_success.yaml") + s.FunctionalTestBase.SetupSuiteWithCluster("testdata/acquire_shard_eventual_success.yaml") } // TestEventuallySucceeds verifies that we eventually succeed in acquiring the shard when we get a deadline exceeded diff --git a/tests/activity_api_pause_test.go b/tests/activity_api_pause_test.go index 2fba6b8f672..4dcbc2193a3 100644 --- a/tests/activity_api_pause_test.go +++ b/tests/activity_api_pause_test.go @@ -43,7 +43,7 @@ import ( ) type ActivityApiPauseClientTestSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite tv *testvars.TestVars initialRetryInterval time.Duration scheduleToCloseTimeout time.Duration @@ -53,13 +53,13 @@ type ActivityApiPauseClientTestSuite struct { } func (s *ActivityApiPauseClientTestSuite) SetupSuite() { - s.ClientFunctionalSuite.SetupSuite() + s.FunctionalTestSdkSuite.SetupSuite() s.OverrideDynamicConfig(dynamicconfig.ActivityAPIsEnabled, true) s.tv = testvars.New(s.T()).WithTaskQueue(s.TaskQueue()).WithNamespaceName(s.Namespace()) } func (s *ActivityApiPauseClientTestSuite) SetupTest() { - s.ClientFunctionalSuite.SetupTest() + s.FunctionalTestSdkSuite.SetupTest() s.initialRetryInterval = 1 * time.Second s.scheduleToCloseTimeout = 30 * time.Minute diff --git a/tests/activity_api_reset_test.go b/tests/activity_api_reset_test.go index 719f4f8569a..bf510912a32 100644 --- a/tests/activity_api_reset_test.go +++ b/tests/activity_api_reset_test.go @@ -45,7 +45,7 @@ import ( ) type ActivityApiResetClientTestSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite tv *testvars.TestVars initialRetryInterval time.Duration scheduleToCloseTimeout time.Duration @@ -55,13 +55,13 @@ type ActivityApiResetClientTestSuite struct { } func (s *ActivityApiResetClientTestSuite) SetupSuite() { - s.ClientFunctionalSuite.SetupSuite() + s.FunctionalTestSdkSuite.SetupSuite() s.OverrideDynamicConfig(dynamicconfig.ActivityAPIsEnabled, true) s.tv = testvars.New(s.T()).WithTaskQueue(s.TaskQueue()).WithNamespaceName(s.Namespace()) } func (s *ActivityApiResetClientTestSuite) SetupTest() { - s.ClientFunctionalSuite.SetupTest() + s.FunctionalTestSdkSuite.SetupTest() s.initialRetryInterval = 1 * time.Second s.scheduleToCloseTimeout = 30 * time.Minute diff --git a/tests/activity_api_update_test.go b/tests/activity_api_update_test.go index 6bee1ec7081..ae419eaf9e8 100644 --- a/tests/activity_api_update_test.go +++ b/tests/activity_api_update_test.go @@ -48,18 +48,18 @@ import ( ) type ActivityApiUpdateClientTestSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite tv *testvars.TestVars } func (s *ActivityApiUpdateClientTestSuite) SetupSuite() { - s.ClientFunctionalSuite.SetupSuite() + s.FunctionalTestSdkSuite.SetupSuite() s.OverrideDynamicConfig(dynamicconfig.ActivityAPIsEnabled, true) s.tv = testvars.New(s.T()).WithTaskQueue(s.TaskQueue()).WithNamespaceName(s.Namespace()) } func (s *ActivityApiUpdateClientTestSuite) SetupTest() { - s.ClientFunctionalSuite.SetupTest() + s.FunctionalTestSdkSuite.SetupTest() } func TestActivityApiUpdateClientTestSuite(t *testing.T) { diff --git a/tests/activity_test.go b/tests/activity_test.go index 0b20f424ad4..171bc21b64e 100644 --- a/tests/activity_test.go +++ b/tests/activity_test.go @@ -61,11 +61,11 @@ import ( ) type ActivityTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } type ActivityClientTestSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestActivityTestSuite(t *testing.T) { @@ -313,9 +313,7 @@ func (s *ActivityClientTestSuite) Test_ActivityTimeouts() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -1242,9 +1240,7 @@ func (s *ActivityClientTestSuite) TestActivityHeartbeatDetailsDuringRetry() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") diff --git a/tests/add_tasks_test.go b/tests/add_tasks_test.go index 4ef854f80ed..208a397eb05 100644 --- a/tests/add_tasks_test.go +++ b/tests/add_tasks_test.go @@ -33,7 +33,6 @@ import ( "time" "github.com/pborman/uuid" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" sdkclient "go.temporal.io/sdk/client" "go.temporal.io/sdk/worker" @@ -58,8 +57,8 @@ import ( type ( // AddTasksSuite is a separate suite because we need to override the history service's executable wrapper. AddTasksSuite struct { - testcore.FunctionalTestBase - *require.Assertions + testcore.FunctionalTestSuite + shardController *faultyShardController worker worker.Worker sdkClient sdkclient.Client @@ -142,25 +141,21 @@ func (e *noopExecutor) shouldExecute(task tasks.Task) bool { // SetupSuite creates the test cluster and registers the executorWrapper with the history service. func (s *AddTasksSuite) SetupSuite() { - // We do this here and in SetupTest because we need assertions in the SetupSuite method as well as the individual - // tests, but this is called before SetupTest, and the s.T() value will change when SetupTest is called. - s.Assertions = require.New(s.T()) // Set up the test cluster and register our executable wrapper. - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml", - testcore.WithFxOptionsForService( - primitives.HistoryService, - fx.Provide( - func() queues.ExecutorWrapper { - return &executorWrapper{s: s} - }, - ), - fx.Decorate( - func(c shard.Controller) shard.Controller { - s.shardController = &faultyShardController{Controller: c, s: s} - return s.shardController - }, - ), + s.FunctionalTestSuite.SetupSuiteWithDefaultCluster(testcore.WithFxOptionsForService( + primitives.HistoryService, + fx.Provide( + func() queues.ExecutorWrapper { + return &executorWrapper{s: s} + }, + ), + fx.Decorate( + func(c shard.Controller) shard.Controller { + s.shardController = &faultyShardController{Controller: c, s: s} + return s.shardController + }, ), + ), ) // Get an SDK client so that we can call ExecuteWorkflow. s.sdkClient = s.newSDKClient() @@ -168,13 +163,7 @@ func (s *AddTasksSuite) SetupSuite() { func (s *AddTasksSuite) TearDownSuite() { s.sdkClient.Close() - s.FunctionalTestBase.TearDownSuite() -} - -func (s *AddTasksSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - - s.Assertions = require.New(s.T()) + s.FunctionalTestSuite.TearDownSuite() } func (s *AddTasksSuite) TestAddTasks_Ok() { @@ -284,6 +273,6 @@ func (s *AddTasksSuite) newSDKClient() sdkclient.Client { HostPort: s.FrontendGRPCAddress(), Namespace: s.Namespace().String(), }) - s.NoError(err) + s.Require().NoError(err) return client } diff --git a/tests/admin_test.go b/tests/admin_test.go index 36a749525c9..3c0d1d45f0e 100644 --- a/tests/admin_test.go +++ b/tests/admin_test.go @@ -40,7 +40,7 @@ import ( ) type AdminTestSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestAdminTestSuite(t *testing.T) { diff --git a/tests/advanced_visibility_test.go b/tests/advanced_visibility_test.go index d6e53c52398..847107b1355 100644 --- a/tests/advanced_visibility_test.go +++ b/tests/advanced_visibility_test.go @@ -36,7 +36,6 @@ import ( "github.com/pborman/uuid" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" commandpb "go.temporal.io/api/command/v1" commonpb "go.temporal.io/api/common/v1" @@ -60,7 +59,6 @@ import ( esclient "go.temporal.io/server/common/persistence/visibility/store/elasticsearch/client" "go.temporal.io/server/common/primitives" "go.temporal.io/server/common/searchattribute" - "go.temporal.io/server/common/testing/historyrequire" "go.temporal.io/server/common/testing/protorequire" "go.temporal.io/server/common/worker_versioning" "go.temporal.io/server/service/worker/scanner/build_ids" @@ -76,12 +74,8 @@ const ( ) type AdvancedVisibilitySuite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - *require.Assertions - protorequire.ProtoAssertions - historyrequire.HistoryRequire - testcore.FunctionalTestBase + testcore.FunctionalTestSuite + isElasticsearchEnabled bool testSearchAttributeKey string @@ -110,14 +104,12 @@ func (s *AdvancedVisibilitySuite) SetupSuite() { dynamicconfig.RemovableBuildIdDurationSinceDefault.Key(): time.Microsecond, } - s.SetDynamicConfigOverrides(dynamicConfigOverrides) - if testcore.UsingSQLAdvancedVisibility() { - s.FunctionalTestBase.SetupSuite("testdata/cluster.yaml") + s.FunctionalTestSuite.SetupSuiteWithCluster("testdata/cluster.yaml", testcore.WithDynamicConfigOverrides(dynamicConfigOverrides)) s.Logger.Info(fmt.Sprintf("Running advanced visibility test with %s/%s persistence", testcore.TestFlags.PersistenceType, testcore.TestFlags.PersistenceDriver)) s.isElasticsearchEnabled = false } else { - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") + s.FunctionalTestSuite.SetupSuiteWithCluster("testdata/es_cluster.yaml", testcore.WithDynamicConfigOverrides(dynamicConfigOverrides)) s.Logger.Info("Running advanced visibility test with Elasticsearch persistence") s.isElasticsearchEnabled = true // To ensure that Elasticsearch won't return more than defaultPageSize documents, @@ -126,36 +118,28 @@ func (s *AdvancedVisibilitySuite) SetupSuite() { s.updateMaxResultWindow() } - sdkClient, err := sdkclient.Dial(sdkclient.Options{ + var err error + s.sdkClient, err = sdkclient.Dial(sdkclient.Options{ HostPort: s.FrontendGRPCAddress(), Namespace: s.Namespace().String(), }) - if err != nil { - s.Logger.Fatal("Error when creating SDK client", tag.Error(err)) - } - s.sdkClient = sdkClient - sysSDKClient, err := sdkclient.Dial(sdkclient.Options{ + s.Require().NoError(err) + + s.sysSDKClient, err = sdkclient.Dial(sdkclient.Options{ HostPort: s.FrontendGRPCAddress(), Namespace: primitives.SystemLocalNamespace, }) - if err != nil { - s.Logger.Fatal("Error when creating SDK client", tag.Error(err)) - } - s.sysSDKClient = sysSDKClient + s.Require().NoError(err) } func (s *AdvancedVisibilitySuite) TearDownSuite() { s.sdkClient.Close() - s.FunctionalTestBase.TearDownSuite() + s.FunctionalTestSuite.TearDownSuite() } func (s *AdvancedVisibilitySuite) SetupTest() { - s.FunctionalTestBase.SetupTest() + s.FunctionalTestSuite.SetupTest() - // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil - s.Assertions = require.New(s.T()) - s.ProtoAssertions = protorequire.New(s.T()) - s.HistoryRequire = historyrequire.New(s.T()) s.testSearchAttributeKey = "CustomTextField" s.testSearchAttributeVal = "test value" } @@ -2808,7 +2792,7 @@ func (s *AdvancedVisibilitySuite) updateMaxResultWindow() { } time.Sleep(waitTimeInMs * time.Millisecond) //nolint:forbidigo } - s.FailNow(fmt.Sprintf("ES max result window size hasn't reach target size within %v", (numOfRetry*waitTimeInMs)*time.Millisecond)) + s.Require().FailNowf("", "ES max result window size hasn't reach target size within %v", numOfRetry*waitTimeInMs*time.Millisecond) } func (s *AdvancedVisibilitySuite) addCustomKeywordSearchAttribute(ctx context.Context, attrName string) { diff --git a/tests/archival_test.go b/tests/archival_test.go index d4ceb3fd6b8..916dba488a6 100644 --- a/tests/archival_test.go +++ b/tests/archival_test.go @@ -33,7 +33,6 @@ import ( "time" "github.com/pborman/uuid" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" commandpb "go.temporal.io/api/command/v1" commonpb "go.temporal.io/api/common/v1" @@ -66,8 +65,7 @@ const ( type ( ArchivalSuite struct { - *require.Assertions - testcore.FunctionalTestBase + testcore.FunctionalTestSuite } archivalWorkflowInfo struct { @@ -79,27 +77,13 @@ type ( func TestArchivalSuite(t *testing.T) { // TODO: archival doesn't support parallel yet: t.Parallel() s := new(ArchivalSuite) - dynamicConfigOverrides := map[dynamicconfig.Key]any{ - dynamicconfig.RetentionTimerJitterDuration.Key(): time.Second, - dynamicconfig.ArchivalProcessorArchiveDelay.Key(): time.Duration(0), - } - s.SetDynamicConfigOverrides(dynamicConfigOverrides) suite.Run(t, s) } func (s *ArchivalSuite) SetupSuite() { - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") -} - -func (s *ArchivalSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - -func (s *ArchivalSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - - // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil - s.Assertions = require.New(s.T()) + s.FunctionalTestSuite.SetupSuiteWithDefaultCluster(testcore.WithDynamicConfigOverrides(map[dynamicconfig.Key]any{ + dynamicconfig.ArchivalProcessorArchiveDelay.Key(): time.Duration(0), + })) } func (s *ArchivalSuite) TestArchival_TimerQueueProcessor() { diff --git a/tests/callbacks_test.go b/tests/callbacks_test.go index dcb289ad68e..f19c2cba612 100644 --- a/tests/callbacks_test.go +++ b/tests/callbacks_test.go @@ -62,7 +62,7 @@ func (h *completionHandler) CompleteOperation(ctx context.Context, request *nexu } type CallbacksSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestCallbacksSuite(t *testing.T) { diff --git a/tests/cancel_workflow_test.go b/tests/cancel_workflow_test.go index 06ab008cc18..432f649c883 100644 --- a/tests/cancel_workflow_test.go +++ b/tests/cancel_workflow_test.go @@ -46,7 +46,7 @@ import ( ) type CancelWorkflowSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestCancelWorkflowSuite(t *testing.T) { diff --git a/tests/child_workflow_test.go b/tests/child_workflow_test.go index b3e074199de..2005e3f107b 100644 --- a/tests/child_workflow_test.go +++ b/tests/child_workflow_test.go @@ -50,7 +50,7 @@ import ( ) type ChildWorkflowSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestChildWorkflowSuite(t *testing.T) { @@ -368,7 +368,7 @@ func (s *ChildWorkflowSuite) TestChildWorkflowExecution() { s.NotNil(childCompletedEventFromParent) completedAttributes := childCompletedEventFromParent.GetChildWorkflowExecutionCompletedEventAttributes() s.Equal(s.Namespace().String(), completedAttributes.Namespace) - // TODO: change to s.Equal(s.Namespace()ID) once it is available. + s.Equal(s.NamespaceID().String(), completedAttributes.NamespaceId) s.NotEmpty(completedAttributes.NamespaceId) s.Equal(childID, completedAttributes.WorkflowExecution.WorkflowId) s.Equal(wtChild, completedAttributes.WorkflowType.Name) diff --git a/tests/client_data_converter_test.go b/tests/client_data_converter_test.go index 13d98e81a59..2c4ce07c13f 100644 --- a/tests/client_data_converter_test.go +++ b/tests/client_data_converter_test.go @@ -38,7 +38,6 @@ import ( "go.temporal.io/sdk/converter" "go.temporal.io/sdk/worker" "go.temporal.io/sdk/workflow" - "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/rpc" "go.temporal.io/server/tests/testcore" ) @@ -48,7 +47,7 @@ var ( ) type ClientDataConverterTestSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestClientDataConverterTestSuite(t *testing.T) { @@ -111,17 +110,14 @@ func (s *ClientDataConverterTestSuite) startWorkerWithDataConverter(tl string, d Namespace: s.Namespace().String(), DataConverter: dataConverter, }) - if err != nil { - s.Logger.Fatal("Error when creating SDK client", tag.Error(err)) - } + s.NoError(err) newWorker := worker.New(sdkClient, tl, worker.Options{}) newWorker.RegisterActivity(testActivity) newWorker.RegisterWorkflow(testChildWorkflow) - if err := newWorker.Start(); err != nil { - s.Logger.Fatal("Error when start worker with data converter", tag.Error(err)) - } + err = newWorker.Start() + s.NoError(err) return sdkClient, newWorker } @@ -184,9 +180,7 @@ func (s *ClientDataConverterTestSuite) TestClientDataConverter() { s.Worker().RegisterWorkflow(testDataConverterWorkflow) s.Worker().RegisterActivity(testActivity) we, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, testDataConverterWorkflow, tl) - if err != nil { - s.Logger.Fatal("Start workflow with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(we) s.True(we.GetRunID() != "") @@ -222,9 +216,7 @@ func (s *ClientDataConverterTestSuite) TestClientDataConverterFailed() { s.Worker().RegisterWorkflow(testDataConverterWorkflow) s.Worker().RegisterActivity(testActivity) we, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, testDataConverterWorkflow, tl) - if err != nil { - s.Logger.Fatal("Start workflow with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(we) s.True(we.GetRunID() != "") @@ -273,9 +265,7 @@ func (s *ClientDataConverterTestSuite) TestClientDataConverterWithChild() { s.Worker().RegisterWorkflow(testChildWorkflow) we, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, testParentWorkflow) - if err != nil { - s.Logger.Fatal("Start workflow with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(we) s.True(we.GetRunID() != "") diff --git a/tests/client_misc_test.go b/tests/client_misc_test.go index 01bc087cca6..de3c01f1e81 100644 --- a/tests/client_misc_test.go +++ b/tests/client_misc_test.go @@ -49,7 +49,6 @@ import ( "go.temporal.io/sdk/workflow" "go.temporal.io/server/api/adminservice/v1" "go.temporal.io/server/common" - "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/rpc" "go.temporal.io/server/common/searchattribute" @@ -60,7 +59,7 @@ import ( ) type ClientMiscTestSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite maxPendingSignals int maxPendingCancelRequests int maxPendingActivities int @@ -73,7 +72,7 @@ func TestClientMiscTestSuite(t *testing.T) { } func (s *ClientMiscTestSuite) SetupSuite() { - s.ClientFunctionalSuite.SetupSuite() + s.FunctionalTestSdkSuite.SetupSuite() s.maxPendingSignals = testcore.ClientSuiteLimit s.maxPendingCancelRequests = testcore.ClientSuiteLimit s.maxPendingActivities = testcore.ClientSuiteLimit @@ -546,9 +545,7 @@ func (s *ClientMiscTestSuite) TestWorkflowCanBeCompletedDespiteAdmittedUpdate() WorkflowTaskTimeout: 10 * time.Second, WorkflowRunTimeout: 10 * time.Second, }, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) // Block until first workflow task started. <-readyToSendUpdate @@ -646,9 +643,7 @@ func (s *ClientMiscTestSuite) Test_CancelActivityAndTimerBeforeComplete() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) err = workflowRun.Get(ctx, nil) s.NoError(err) } @@ -694,9 +689,7 @@ func (s *ClientMiscTestSuite) Test_FinishWorkflowWithDeferredCommands() { ctx := context.Background() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -781,9 +774,7 @@ func (s *ClientMiscTestSuite) TestInvalidCommandAttribute() { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -850,9 +841,7 @@ func (s *ClientMiscTestSuite) Test_BufferedQuery() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -959,9 +948,7 @@ func (s *ClientMiscTestSuite) TestBufferedSignalCausesUnhandledCommandAndSchedul WorkflowRunTimeout: 10 * time.Second, } workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -1040,9 +1027,8 @@ func (s *ClientMiscTestSuite) Test_StickyWorkerRestartWorkflowTask() { oldWorker := worker.New(s.SdkClient(), taskQueue, worker.Options{}) oldWorker.RegisterWorkflow(workflowFn) - if err := oldWorker.Start(); err != nil { - s.Logger.Fatal("Error when start worker", tag.Error(err)) - } + err := oldWorker.Start() + s.NoError(err) id := "test-sticky-delay" + tt.name workflowOptions := sdkclient.StartWorkflowOptions{ @@ -1053,12 +1039,10 @@ func (s *ClientMiscTestSuite) Test_StickyWorkerRestartWorkflowTask() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) - s.True(workflowRun.GetRunID() != "") + s.NotEmpty(workflowRun.GetRunID()) s.Eventually(func() bool { // wait until first workflow task completed (so we know sticky is set on workflow) @@ -1082,9 +1066,8 @@ func (s *ClientMiscTestSuite) Test_StickyWorkerRestartWorkflowTask() { // start a new worker newWorker := worker.New(s.SdkClient(), taskQueue, worker.Options{}) newWorker.RegisterWorkflow(workflowFn) - if err := newWorker.Start(); err != nil { - s.Logger.Fatal("Error when start worker", tag.Error(err)) - } + err = newWorker.Start() + s.NoError(err) defer newWorker.Stop() startTime := time.Now() diff --git a/tests/continue_as_new_test.go b/tests/continue_as_new_test.go index 05087ec2524..b78f341ecb0 100644 --- a/tests/continue_as_new_test.go +++ b/tests/continue_as_new_test.go @@ -48,7 +48,7 @@ import ( ) type ContinueAsNewTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestContinueAsNewTestSuite(t *testing.T) { @@ -693,7 +693,7 @@ func (s *ContinueAsNewTestSuite) TestChildWorkflowWithContinueAsNew() { s.NotNil(definition.completedEvent) completedAttributes := definition.completedEvent.GetChildWorkflowExecutionCompletedEventAttributes() s.Equal(s.Namespace().String(), completedAttributes.Namespace) - // TODO: change to s.Equal(s.Namespace()ID) once it is available. + s.Equal(s.NamespaceID().String(), completedAttributes.NamespaceId) s.NotEmpty(completedAttributes.Namespace) s.Equal(childID, completedAttributes.WorkflowExecution.WorkflowId) s.NotEqual( diff --git a/tests/cron_test.go b/tests/cron_test.go index 4cd4667378c..6ccfcc87753 100644 --- a/tests/cron_test.go +++ b/tests/cron_test.go @@ -54,11 +54,11 @@ import ( ) type CronTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } type CronTestClientSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestCronTestSuite(t *testing.T) { diff --git a/tests/deployment_test.go b/tests/deployment_test.go index 80c13331c37..4e08b03d5da 100644 --- a/tests/deployment_test.go +++ b/tests/deployment_test.go @@ -35,7 +35,6 @@ import ( "github.com/dgryski/go-farm" "github.com/pborman/uuid" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" batchpb "go.temporal.io/api/batch/v1" commonpb "go.temporal.io/api/common/v1" @@ -47,7 +46,6 @@ import ( "go.temporal.io/api/workflowservice/v1" sdkclient "go.temporal.io/sdk/client" "go.temporal.io/server/common/dynamicconfig" - "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/payload" "go.temporal.io/server/common/testing/testvars" "go.temporal.io/server/common/tqid" @@ -72,24 +70,18 @@ const ( type ( DeploymentSuite struct { - testcore.FunctionalTestBase - *require.Assertions + testcore.FunctionalTestSuite sdkClient sdkclient.Client } ) -func (s *DeploymentSuite) setAssertions() { - s.Assertions = require.New(s.T()) -} - func TestDeploymentSuite(t *testing.T) { t.Parallel() suite.Run(t, new(DeploymentSuite)) } func (s *DeploymentSuite) SetupSuite() { - s.setAssertions() - dynamicConfigOverrides := map[dynamicconfig.Key]any{ + s.FunctionalTestSuite.SetupSuiteWithDefaultCluster(testcore.WithDynamicConfigOverrides(map[dynamicconfig.Key]any{ dynamicconfig.EnableDeployments.Key(): true, dynamicconfig.FrontendEnableWorkerVersioningDataAPIs.Key(): true, dynamicconfig.FrontendEnableWorkerVersioningWorkflowAPIs.Key(): true, @@ -107,26 +99,18 @@ func (s *DeploymentSuite) SetupSuite() { // Reduce the chance of hitting max batch job limit in tests dynamicconfig.FrontendMaxConcurrentBatchOperationPerNamespace.Key(): maxConcurrentBatchOps, - } - s.SetDynamicConfigOverrides(dynamicConfigOverrides) - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") -} - -func (s *DeploymentSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() + })) } func (s *DeploymentSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - s.setAssertions() - sdkClient, err := sdkclient.Dial(sdkclient.Options{ + s.FunctionalTestSuite.SetupTest() + + var err error + s.sdkClient, err = sdkclient.Dial(sdkclient.Options{ HostPort: s.FrontendGRPCAddress(), Namespace: s.Namespace().String(), }) - if err != nil { - s.Logger.Fatal("Error when creating SDK client", tag.Error(err)) - } - s.sdkClient = sdkClient + s.NoError(err) } func (s *DeploymentSuite) TearDownTest() { diff --git a/tests/describe_task_queue_test.go b/tests/describe_task_queue_test.go index c48d97b79a2..430accd1587 100644 --- a/tests/describe_task_queue_test.go +++ b/tests/describe_task_queue_test.go @@ -29,7 +29,6 @@ import ( "github.com/pborman/uuid" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" commandpb "go.temporal.io/api/command/v1" commonpb "go.temporal.io/api/common/v1" @@ -45,8 +44,7 @@ import ( type ( DescribeTaskQueueSuite struct { - *require.Assertions - testcore.FunctionalTestBase + testcore.FunctionalTestSuite } ) @@ -55,21 +53,6 @@ func TestDescribeTaskQueueSuite(t *testing.T) { suite.Run(t, new(DescribeTaskQueueSuite)) } -func (s *DescribeTaskQueueSuite) SetupSuite() { - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") -} - -func (s *DescribeTaskQueueSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - -func (s *DescribeTaskQueueSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - - // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil - s.Assertions = require.New(s.T()) -} - func (s *DescribeTaskQueueSuite) TestNonRootLegacy() { resp, err := s.FrontendClient().DescribeTaskQueue(context.Background(), &workflowservice.DescribeTaskQueueRequest{ Namespace: s.Namespace().String(), diff --git a/tests/describe_test.go b/tests/describe_test.go index f5493da44f6..0c4a6b86be0 100644 --- a/tests/describe_test.go +++ b/tests/describe_test.go @@ -46,7 +46,7 @@ import ( ) type DescribeTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestDescribeTestSuite(t *testing.T) { diff --git a/tests/dlq_test.go b/tests/dlq_test.go index 413bf702311..96fbd24f682 100644 --- a/tests/dlq_test.go +++ b/tests/dlq_test.go @@ -40,7 +40,6 @@ import ( "time" "github.com/pborman/uuid" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/urfave/cli/v2" enumspb "go.temporal.io/api/enums/v1" @@ -71,8 +70,8 @@ import ( type ( DLQSuite struct { - testcore.FunctionalTestBase - *require.Assertions + testcore.FunctionalTestSuite + dlq persistence.HistoryTaskQueueManager dlqTasks chan tasks.Task writer bytes.Buffer @@ -122,16 +121,14 @@ func TestDLQSuite(t *testing.T) { } func (s *DLQSuite) SetupSuite() { - s.setAssertions() dynamicConfigOverrides := map[dynamicconfig.Key]any{ dynamicconfig.HistoryTaskDLQEnabled.Key(): true, } - s.SetDynamicConfigOverrides(dynamicConfigOverrides) s.dlqTasks = make(chan tasks.Task) testPrefix := "dlq-test-terminal-wfts-" s.failingWorkflowIDPrefix.Store(&testPrefix) - s.FunctionalTestBase.SetupSuite( - "testdata/es_cluster.yaml", + s.FunctionalTestSuite.SetupSuiteWithDefaultCluster( + testcore.WithDynamicConfigOverrides(dynamicConfigOverrides), testcore.WithFxOptionsForService(primitives.HistoryService, fx.Populate(&s.dlq), fx.Provide( @@ -172,15 +169,15 @@ func (s *DLQSuite) SetupSuite() { HostPort: s.FrontendGRPCAddress(), Namespace: s.Namespace().String(), }) - s.NoError(err) + s.Require().NoError(err) s.worker = sdkworker.New(sdkClient, taskQueue, sdkworker.Options{}) s.worker.RegisterWorkflow(myWorkflow) - s.NoError(s.worker.Start()) + s.Require().NoError(s.worker.Start()) } func (s *DLQSuite) TearDownSuite() { s.worker.Stop() - s.FunctionalTestBase.TearDownSuite() + s.FunctionalTestSuite.TearDownSuite() } func myWorkflow(workflow.Context) (string, error) { @@ -188,17 +185,12 @@ func myWorkflow(workflow.Context) (string, error) { } func (s *DLQSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() + s.FunctionalTestSuite.SetupTest() - s.setAssertions() s.deleteBlockCh = make(chan interface{}) close(s.deleteBlockCh) } -func (s *DLQSuite) setAssertions() { - s.Assertions = require.New(s.T()) -} - func (s *DLQSuite) TestReadArtificialDLQTasks() { ctx := context.Background() diff --git a/tests/eager_workflow_start_test.go b/tests/eager_workflow_start_test.go index a02c5029c37..08cfc653eca 100644 --- a/tests/eager_workflow_start_test.go +++ b/tests/eager_workflow_start_test.go @@ -45,7 +45,7 @@ import ( ) type EagerWorkflowTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestEagerWorkflowTestSuite(t *testing.T) { diff --git a/tests/gethistory_test.go b/tests/gethistory_test.go index 53dd75378aa..076e0a64aee 100644 --- a/tests/gethistory_test.go +++ b/tests/gethistory_test.go @@ -32,7 +32,6 @@ import ( "time" "github.com/pborman/uuid" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" commandpb "go.temporal.io/api/command/v1" commonpb "go.temporal.io/api/common/v1" @@ -48,23 +47,20 @@ import ( "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/payloads" "go.temporal.io/server/common/persistence/serialization" - "go.temporal.io/server/common/testing/historyrequire" "go.temporal.io/server/tests/testcore" "google.golang.org/protobuf/types/known/durationpb" ) type RawHistorySuite struct { - *require.Assertions - testcore.FunctionalTestBase - historyrequire.HistoryRequire + testcore.FunctionalTestSuite } type RawHistoryClientSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } type GetHistoryFunctionalSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestRawHistorySuite(t *testing.T) { @@ -86,19 +82,7 @@ func (s *RawHistorySuite) SetupSuite() { dynamicConfigOverrides := map[dynamicconfig.Key]any{ dynamicconfig.SendRawWorkflowHistory.Key(): true, } - s.SetDynamicConfigOverrides(dynamicConfigOverrides) - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") -} - -func (s *RawHistorySuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - -func (s *RawHistorySuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - - s.Assertions = require.New(s.T()) - s.HistoryRequire = historyrequire.New(s.T()) + s.FunctionalTestSuite.SetupSuiteWithDefaultCluster(testcore.WithDynamicConfigOverrides(dynamicConfigOverrides)) } func (s *GetHistoryFunctionalSuite) TestGetWorkflowExecutionHistory_All() { @@ -679,9 +663,7 @@ func (s *RawHistoryClientSuite) TestGetHistoryReverse() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -756,9 +738,7 @@ func (s *RawHistoryClientSuite) TestGetHistoryReverse_MultipleBranches() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") diff --git a/tests/http_api_test.go b/tests/http_api_test.go index 7326bb45fd9..c9198b53473 100644 --- a/tests/http_api_test.go +++ b/tests/http_api_test.go @@ -67,7 +67,7 @@ func jsonPayload(data string) *commonpb.Payloads { } type HttpApiTestSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestHttpApiTestSuite(t *testing.T) { diff --git a/tests/links_test.go b/tests/links_test.go index 2c0ec36cfe8..bb9f1afb087 100644 --- a/tests/links_test.go +++ b/tests/links_test.go @@ -39,7 +39,7 @@ import ( ) type LinksSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestLinksTestSuite(t *testing.T) { diff --git a/tests/max_buffered_event_test.go b/tests/max_buffered_event_test.go index aacdc253011..46f65a7ab92 100644 --- a/tests/max_buffered_event_test.go +++ b/tests/max_buffered_event_test.go @@ -41,7 +41,7 @@ import ( ) type MaxBufferedEventSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestMaxBufferedEventSuite(t *testing.T) { diff --git a/tests/namespace_delete_test.go b/tests/namespace_delete_test.go index 84c390a93d7..b07e570ce9e 100644 --- a/tests/namespace_delete_test.go +++ b/tests/namespace_delete_test.go @@ -36,7 +36,6 @@ import ( "github.com/dgryski/go-farm" "github.com/pborman/uuid" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" commonpb "go.temporal.io/api/common/v1" enumspb "go.temporal.io/api/enums/v1" @@ -44,10 +43,8 @@ import ( "go.temporal.io/api/serviceerror" taskqueuepb "go.temporal.io/api/taskqueue/v1" "go.temporal.io/api/workflowservice/v1" - "go.temporal.io/server/api/adminservice/v1" "go.temporal.io/server/common" "go.temporal.io/server/common/dynamicconfig" - "go.temporal.io/server/common/log" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/rpc" @@ -58,18 +55,7 @@ import ( type ( namespaceTestSuite struct { - *require.Assertions - suite.Suite - - testClusterFactory testcore.TestClusterFactory - - frontendClient workflowservice.WorkflowServiceClient - adminClient adminservice.AdminServiceClient - operatorClient operatorservice.OperatorServiceClient - - cluster *testcore.TestCluster - clusterConfig *testcore.TestClusterConfig - logger log.Logger + testcore.FunctionalTestSuite } ) @@ -81,59 +67,33 @@ func TestNamespaceSuite(t *testing.T) { } func (s *namespaceTestSuite) SetupSuite() { - s.logger = log.NewTestLogger() - s.testClusterFactory = testcore.NewTestClusterFactory() + dynamicConfigOverrides := map[dynamicconfig.Key]any{ + // Run tests at full speed. + dynamicconfig.DeleteNamespaceDeleteActivityRPS.Key(): 1000000, + } if testcore.UsingSQLAdvancedVisibility() { - var err error - s.clusterConfig, err = testcore.GetTestClusterConfig("testdata/cluster.yaml") - s.Require().NoError(err) - s.logger.Info(fmt.Sprintf("Running delete namespace tests with %s/%s persistence", testcore.TestFlags.PersistenceType, testcore.TestFlags.PersistenceDriver)) + s.SetupSuiteWithCluster("testdata/cluster.yaml", testcore.WithDynamicConfigOverrides(dynamicConfigOverrides)) + s.Logger.Info(fmt.Sprintf("Running delete namespace tests with %s/%s persistence", testcore.TestFlags.PersistenceType, testcore.TestFlags.PersistenceDriver)) } else { - var err error - // Elasticsearch is needed to test advanced visibility code path in reclaim resources workflow. - s.clusterConfig, err = testcore.GetTestClusterConfig("testdata/es_cluster.yaml") - s.Require().NoError(err) - s.logger.Info("Running delete namespace tests with Elasticsearch persistence") - } - - s.clusterConfig.DynamicConfigOverrides = map[dynamicconfig.Key]any{ - dynamicconfig.DeleteNamespaceDeleteActivityRPS.Key(): 1000, + s.SetupSuiteWithCluster("testdata/es_cluster.yaml", testcore.WithDynamicConfigOverrides(dynamicConfigOverrides)) } - - cluster, err := s.testClusterFactory.NewCluster(s.T(), s.clusterConfig, s.logger) - s.Require().NoError(err) - s.cluster = cluster - s.frontendClient = s.cluster.FrontendClient() - s.adminClient = s.cluster.AdminClient() - s.operatorClient = s.cluster.OperatorClient() -} - -func (s *namespaceTestSuite) TearDownSuite() { - _ = s.cluster.TearDownCluster() -} - -func (s *namespaceTestSuite) SetupTest() { - s.checkTestShard() - - // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil - s.Assertions = require.New(s.T()) } func (s *namespaceTestSuite) Test_NamespaceDelete_InvalidUTF8() { // don't fail for this test, we're testing this behavior specifically - s.cluster.OverrideDynamicConfig(s.T(), dynamicconfig.ValidateUTF8FailRPCRequest, false) - s.cluster.OverrideDynamicConfig(s.T(), dynamicconfig.ValidateUTF8FailRPCResponse, false) - s.cluster.OverrideDynamicConfig(s.T(), dynamicconfig.ValidateUTF8FailPersistence, false) + s.GetTestCluster().OverrideDynamicConfig(s.T(), dynamicconfig.ValidateUTF8FailRPCRequest, false) + s.GetTestCluster().OverrideDynamicConfig(s.T(), dynamicconfig.ValidateUTF8FailRPCResponse, false) + s.GetTestCluster().OverrideDynamicConfig(s.T(), dynamicconfig.ValidateUTF8FailPersistence, false) - capture := s.cluster.Host().CaptureMetricsHandler().StartCapture() - defer s.cluster.Host().CaptureMetricsHandler().StopCapture(capture) + capture := s.GetTestCluster().Host().CaptureMetricsHandler().StartCapture() + defer s.GetTestCluster().Host().CaptureMetricsHandler().StopCapture(capture) ctx, cancel := rpc.NewContextWithTimeoutAndVersionHeaders(10000 * time.Second) defer cancel() s.False(utf8.Valid([]byte(testcore.InvalidUTF8))) retention := 24 * time.Hour - _, err := s.frontendClient.RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ + _, err := s.FrontendClient().RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ Namespace: "valid-utf8", // we verify internally that these must be valid Description: testcore.InvalidUTF8, Data: map[string]string{testcore.InvalidUTF8: testcore.InvalidUTF8}, @@ -143,25 +103,25 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_InvalidUTF8() { }) s.NoError(err) - descResp, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Namespace: "valid-utf8", }) s.NoError(err) nsID := descResp.GetNamespaceInfo().GetId() - delResp, err := s.operatorClient.DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ + delResp, err := s.OperatorClient().DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ NamespaceId: nsID, }) s.NoError(err) s.Equal("valid-utf8-deleted-"+nsID[:5], delResp.GetDeletedNamespace()) - descResp2, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp2, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) s.NoError(err) s.Equal(enumspb.NAMESPACE_STATE_DELETED, descResp2.GetNamespaceInfo().GetState()) s.Eventually(func() bool { - _, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + _, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) var notFound *serviceerror.NamespaceNotFound @@ -181,7 +141,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_Empty() { defer cancel() retention := 24 * time.Hour - _, err := s.frontendClient.RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ + _, err := s.FrontendClient().RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ Namespace: "ns_name_san_diego", Description: "Namespace to delete", WorkflowExecutionRetentionPeriod: durationpb.New(retention), @@ -190,25 +150,25 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_Empty() { }) s.NoError(err) - descResp, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Namespace: "ns_name_san_diego", }) s.NoError(err) nsID := descResp.GetNamespaceInfo().GetId() - delResp, err := s.operatorClient.DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ + delResp, err := s.OperatorClient().DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ Namespace: "ns_name_san_diego", }) s.NoError(err) s.Equal("ns_name_san_diego-deleted-"+nsID[:5], delResp.GetDeletedNamespace()) - descResp2, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp2, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) s.NoError(err) s.Equal(enumspb.NAMESPACE_STATE_DELETED, descResp2.GetNamespaceInfo().GetState()) s.Eventually(func() bool { - _, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + _, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) var notFound *serviceerror.NamespaceNotFound @@ -224,10 +184,10 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_OverrideDelay() { ctx, cancel := rpc.NewContextWithTimeoutAndVersionHeaders(10000 * time.Second) defer cancel() - s.cluster.OverrideDynamicConfig(s.T(), dynamicconfig.DeleteNamespaceNamespaceDeleteDelay, time.Hour) + s.GetTestCluster().OverrideDynamicConfig(s.T(), dynamicconfig.DeleteNamespaceNamespaceDeleteDelay, time.Hour) retention := 24 * time.Hour - _, err := s.frontendClient.RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ + _, err := s.FrontendClient().RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ Namespace: "ns_name_san_diego", Description: "Namespace to delete", WorkflowExecutionRetentionPeriod: durationpb.New(retention), @@ -236,26 +196,26 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_OverrideDelay() { }) s.NoError(err) - descResp, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Namespace: "ns_name_san_diego", }) s.NoError(err) nsID := descResp.GetNamespaceInfo().GetId() - delResp, err := s.operatorClient.DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ + delResp, err := s.OperatorClient().DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ Namespace: "ns_name_san_diego", NamespaceDeleteDelay: durationpb.New(0), }) s.NoError(err) s.Equal("ns_name_san_diego-deleted-"+nsID[:5], delResp.GetDeletedNamespace()) - descResp2, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp2, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) s.NoError(err) s.Equal(enumspb.NAMESPACE_STATE_DELETED, descResp2.GetNamespaceInfo().GetState()) s.Eventually(func() bool { - _, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + _, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) var notFound *serviceerror.NamespaceNotFound @@ -272,7 +232,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_Empty_WithID() { defer cancel() retention := 24 * time.Hour - _, err := s.frontendClient.RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ + _, err := s.FrontendClient().RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ Namespace: "ns_name_san_diego", Description: "Namespace to delete", WorkflowExecutionRetentionPeriod: durationpb.New(retention), @@ -281,25 +241,25 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_Empty_WithID() { }) s.NoError(err) - descResp, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Namespace: "ns_name_san_diego", }) s.NoError(err) nsID := descResp.GetNamespaceInfo().GetId() - delResp, err := s.operatorClient.DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ + delResp, err := s.OperatorClient().DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ NamespaceId: nsID, }) s.NoError(err) s.Equal("ns_name_san_diego-deleted-"+nsID[:5], delResp.GetDeletedNamespace()) - descResp2, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp2, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) s.NoError(err) s.Equal(enumspb.NAMESPACE_STATE_DELETED, descResp2.GetNamespaceInfo().GetState()) s.Eventually(func() bool { - _, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + _, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) var notFound *serviceerror.NamespaceNotFound @@ -316,7 +276,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithNameAndID() { defer cancel() retention := 24 * time.Hour - _, err := s.frontendClient.RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ + _, err := s.FrontendClient().RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ Namespace: "ns_name_san_diego", Description: "Namespace to delete", WorkflowExecutionRetentionPeriod: durationpb.New(retention), @@ -325,13 +285,13 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithNameAndID() { }) s.NoError(err) - descResp, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Namespace: "ns_name_san_diego", }) s.NoError(err) nsID := descResp.GetNamespaceInfo().GetId() - _, err = s.operatorClient.DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ + _, err = s.OperatorClient().DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ Namespace: "ns_name_san_diego", NamespaceId: nsID, }) @@ -343,7 +303,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithWorkflows() { defer cancel() retention := 24 * time.Hour - _, err := s.frontendClient.RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ + _, err := s.FrontendClient().RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ Namespace: "ns_name_seattle", Description: "Namespace to delete", WorkflowExecutionRetentionPeriod: durationpb.New(retention), @@ -352,7 +312,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithWorkflows() { }) s.NoError(err) - descResp, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Namespace: "ns_name_seattle", }) s.NoError(err) @@ -362,7 +322,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithWorkflows() { var executions []*commonpb.WorkflowExecution for i := 0; i < 100; i++ { wid := "wf_id_" + strconv.Itoa(i) - resp, err := s.frontendClient.StartWorkflowExecution(ctx, &workflowservice.StartWorkflowExecutionRequest{ + resp, err := s.FrontendClient().StartWorkflowExecution(ctx, &workflowservice.StartWorkflowExecutionRequest{ RequestId: uuid.New(), Namespace: "ns_name_seattle", WorkflowId: wid, @@ -378,27 +338,27 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithWorkflows() { // Terminate some workflow executions. for _, execution := range executions[:30] { - _, err = s.frontendClient.TerminateWorkflowExecution(ctx, &workflowservice.TerminateWorkflowExecutionRequest{ + _, err = s.FrontendClient().TerminateWorkflowExecution(ctx, &workflowservice.TerminateWorkflowExecutionRequest{ Namespace: "ns_name_seattle", WorkflowExecution: execution, }) s.NoError(err) } - delResp, err := s.operatorClient.DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ + delResp, err := s.OperatorClient().DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ Namespace: "ns_name_seattle", }) s.NoError(err) s.Equal("ns_name_seattle-deleted-"+nsID[:5], delResp.GetDeletedNamespace()) - descResp2, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp2, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) s.NoError(err) s.Equal(enumspb.NAMESPACE_STATE_DELETED, descResp2.GetNamespaceInfo().GetState()) s.Eventually(func() bool { - _, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + _, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) var notFound *serviceerror.NamespaceNotFound @@ -407,7 +367,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithWorkflows() { } for _, execution := range executions { - _, err = s.frontendClient.DescribeWorkflowExecution(ctx, &workflowservice.DescribeWorkflowExecutionRequest{ + _, err = s.FrontendClient().DescribeWorkflowExecution(ctx, &workflowservice.DescribeWorkflowExecutionRequest{ Namespace: "ns_name_seattle", Execution: &commonpb.WorkflowExecution{ WorkflowId: execution.GetWorkflowId(), @@ -426,7 +386,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithMissingWorkflows() { defer cancel() retention := 24 * time.Hour - _, err := s.frontendClient.RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ + _, err := s.FrontendClient().RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ Namespace: "ns_name_los_angeles", Description: "Namespace to delete", WorkflowExecutionRetentionPeriod: durationpb.New(retention), @@ -435,7 +395,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithMissingWorkflows() { }) s.NoError(err) - descResp, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Namespace: "ns_name_los_angeles", }) s.NoError(err) @@ -446,7 +406,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithMissingWorkflows() { var executions []*commonpb.WorkflowExecution for i := 0; i < 10; i++ { wid := "wf_id_" + strconv.Itoa(i) - resp, err := s.frontendClient.StartWorkflowExecution(ctx, &workflowservice.StartWorkflowExecutionRequest{ + resp, err := s.FrontendClient().StartWorkflowExecution(ctx, &workflowservice.StartWorkflowExecutionRequest{ RequestId: uuid.New(), Namespace: "ns_name_los_angeles", WorkflowId: wid, @@ -466,10 +426,10 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithMissingWorkflows() { shardID := common.WorkflowIDToHistoryShard( nsID, execution.GetWorkflowId(), - s.clusterConfig.HistoryConfig.NumHistoryShards, + s.GetTestClusterConfig().HistoryConfig.NumHistoryShards, ) - err = s.cluster.ExecutionManager().DeleteWorkflowExecution(ctx, &persistence.DeleteWorkflowExecutionRequest{ + err = s.GetTestCluster().ExecutionManager().DeleteWorkflowExecution(ctx, &persistence.DeleteWorkflowExecutionRequest{ ShardID: shardID, NamespaceID: nsID, WorkflowID: execution.GetWorkflowId(), @@ -478,20 +438,20 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithMissingWorkflows() { s.NoError(err) } - delResp, err := s.operatorClient.DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ + delResp, err := s.OperatorClient().DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ Namespace: "ns_name_los_angeles", }) s.NoError(err) s.Equal("ns_name_los_angeles-deleted-"+nsID[:5], delResp.GetDeletedNamespace()) - descResp2, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + descResp2, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) s.NoError(err) s.Equal(enumspb.NAMESPACE_STATE_DELETED, descResp2.GetNamespaceInfo().GetState()) s.Eventually(func() bool { - _, err := s.frontendClient.DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ + _, err := s.FrontendClient().DescribeNamespace(ctx, &workflowservice.DescribeNamespaceRequest{ Id: nsID, }) var notFound *serviceerror.NamespaceNotFound @@ -500,7 +460,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_WithMissingWorkflows() { } for _, execution := range executions { - _, err = s.frontendClient.DescribeWorkflowExecution(ctx, &workflowservice.DescribeWorkflowExecutionRequest{ + _, err = s.FrontendClient().DescribeWorkflowExecution(ctx, &workflowservice.DescribeWorkflowExecutionRequest{ Namespace: "ns_name_los_angeles", Execution: &commonpb.WorkflowExecution{ WorkflowId: execution.GetWorkflowId(), @@ -553,7 +513,7 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_Protected() { tv := testvars.New(s.T()) - _, err := s.frontendClient.RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ + _, err := s.FrontendClient().RegisterNamespace(ctx, &workflowservice.RegisterNamespaceRequest{ Namespace: tv.NamespaceName().String(), Description: tv.Any().String(), WorkflowExecutionRetentionPeriod: tv.Any().InfiniteTimeout(), @@ -562,9 +522,9 @@ func (s *namespaceTestSuite) Test_NamespaceDelete_Protected() { }) s.NoError(err) - s.cluster.OverrideDynamicConfig(s.T(), dynamicconfig.ProtectedNamespaces, []string{tv.NamespaceName().String()}) + s.GetTestCluster().OverrideDynamicConfig(s.T(), dynamicconfig.ProtectedNamespaces, []string{tv.NamespaceName().String()}) - delResp, err := s.operatorClient.DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ + delResp, err := s.OperatorClient().DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{ Namespace: tv.NamespaceName().String(), }) s.Error(err) diff --git a/tests/namespace_interceptor_test.go b/tests/namespace_interceptor_test.go index 0afb3e73ce2..c28edc1667c 100644 --- a/tests/namespace_interceptor_test.go +++ b/tests/namespace_interceptor_test.go @@ -42,7 +42,7 @@ import ( ) type NamespaceInterceptorTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestNamespaceInterceptorTestSuite(t *testing.T) { diff --git a/tests/ndc/ndc_test.go b/tests/ndc/ndc_test.go index 229a976ec9c..c659f6a94c5 100644 --- a/tests/ndc/ndc_test.go +++ b/tests/ndc/ndc_test.go @@ -75,6 +75,7 @@ import ( type ( NDCFunctionalTestSuite struct { + // TODO (alex): use FunctionalTestSuite // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, // not merely log an error *require.Assertions diff --git a/tests/nexus_endpoint_test.go b/tests/nexus_endpoint_test.go index 739dc572cb1..08982cc7dd8 100644 --- a/tests/nexus_endpoint_test.go +++ b/tests/nexus_endpoint_test.go @@ -28,7 +28,6 @@ import ( "testing" "github.com/google/uuid" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" commonpb "go.temporal.io/api/common/v1" enumspb "go.temporal.io/api/enums/v1" @@ -40,7 +39,6 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" commonnexus "go.temporal.io/server/common/nexus" p "go.temporal.io/server/common/persistence" - "go.temporal.io/server/common/testing/protorequire" "go.temporal.io/server/tests/testcore" ) @@ -61,27 +59,7 @@ func TestNexusEndpointsFunctionalSuite(t *testing.T) { } type NexusEndpointFunctionalSuite struct { - testcore.FunctionalTestBase - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - *require.Assertions - protorequire.ProtoAssertions -} - -func (s *NexusEndpointFunctionalSuite) SetupSuite() { - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") -} - -func (s *NexusEndpointFunctionalSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - -func (s *NexusEndpointFunctionalSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - - // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil - s.Assertions = require.New(s.T()) - s.ProtoAssertions = protorequire.New(s.T()) + testcore.FunctionalTestSuite } type CommonSuite struct { diff --git a/tests/nexus_test_base.go b/tests/nexus_test_base.go index ddd4f20d56a..3e942d46ba8 100644 --- a/tests/nexus_test_base.go +++ b/tests/nexus_test_base.go @@ -38,7 +38,7 @@ import ( ) type NexusTestBaseSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func (s *NexusTestBaseSuite) mustToPayload(v any) *commonpb.Payload { diff --git a/tests/purge_dlq_tasks_api_test.go b/tests/purge_dlq_tasks_api_test.go index 1a239a66d80..9b7692be9dc 100644 --- a/tests/purge_dlq_tasks_api_test.go +++ b/tests/purge_dlq_tasks_api_test.go @@ -29,7 +29,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "go.temporal.io/api/serviceerror" "go.temporal.io/server/api/adminservice/v1" @@ -46,8 +45,8 @@ import ( type ( PurgeDLQTasksSuite struct { - *require.Assertions - testcore.FunctionalTestBase + testcore.FunctionalTestSuite + dlq *faultyDLQ sdkClientFactory sdk.ClientFactory } @@ -87,9 +86,7 @@ func (q *faultyDLQ) DeleteTasks( } func (s *PurgeDLQTasksSuite) SetupSuite() { - s.Assertions = require.New(s.T()) - s.FunctionalTestBase.SetupSuite( - "testdata/es_cluster.yaml", + s.FunctionalTestSuite.SetupSuiteWithDefaultCluster( testcore.WithFxOptionsForService(primitives.HistoryService, fx.Decorate(func(manager persistence.HistoryTaskQueueManager) persistence.HistoryTaskQueueManager { s.dlq = &faultyDLQ{HistoryTaskQueueManager: manager} @@ -102,16 +99,6 @@ func (s *PurgeDLQTasksSuite) SetupSuite() { ) } -func (s *PurgeDLQTasksSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - -func (s *PurgeDLQTasksSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - - s.Assertions = require.New(s.T()) -} - func (s *PurgeDLQTasksSuite) TestPurgeDLQTasks() { for _, tc := range []purgeDLQTasksTestCase{ { diff --git a/tests/query_workflow_test.go b/tests/query_workflow_test.go index 92a5c762a97..68fa4aa767a 100644 --- a/tests/query_workflow_test.go +++ b/tests/query_workflow_test.go @@ -49,7 +49,6 @@ import ( sdkclient "go.temporal.io/sdk/client" "go.temporal.io/sdk/worker" "go.temporal.io/sdk/workflow" - "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/testing/testvars" "go.temporal.io/server/common/util" "go.temporal.io/server/service/history/consts" @@ -57,7 +56,7 @@ import ( ) type QueryWorkflowSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestQueryWorkflowSuite(t *testing.T) { @@ -92,9 +91,7 @@ func (s *QueryWorkflowSuite) TestQueryWorkflow_Sticky() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -144,9 +141,7 @@ func (s *QueryWorkflowSuite) TestQueryWorkflow_Consistent_PiggybackQuery() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -257,9 +252,7 @@ func (s *QueryWorkflowSuite) TestQueryWorkflow_QueryBeforeStart() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -289,9 +282,8 @@ func (s *QueryWorkflowSuite) TestQueryWorkflow_QueryBeforeStart() { queryWorker = worker.New(s.SdkClient(), s.TaskQueue(), worker.Options{}) queryWorker.RegisterWorkflow(workflowFn) - if err := queryWorker.Start(); err != nil { - s.Logger.Fatal("Error when start worker", tag.Error(err)) - } + err = queryWorker.Start() + s.NoError(err) // wait query wg.Wait() @@ -325,9 +317,7 @@ func (s *QueryWorkflowSuite) TestQueryWorkflow_QueryFailedWorkflowTask() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") @@ -356,9 +346,7 @@ func (s *QueryWorkflowSuite) TestQueryWorkflow_ClosedWithoutWorkflowTaskStarted( ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, workflowOptions, workflowFn) - if err != nil { - s.Logger.Fatal("Start workflow failed with err", tag.Error(err)) - } + s.NoError(err) s.NotNil(workflowRun) s.True(workflowRun.GetRunID() != "") diff --git a/tests/relay_task_test.go b/tests/relay_task_test.go index 466f3bbb636..1894e571d3f 100644 --- a/tests/relay_task_test.go +++ b/tests/relay_task_test.go @@ -41,7 +41,7 @@ import ( ) type RelayTaskTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestRelayTaskTestSuite(t *testing.T) { diff --git a/tests/reset_workflow_test.go b/tests/reset_workflow_test.go index 32dd27db770..f055eadcd8f 100644 --- a/tests/reset_workflow_test.go +++ b/tests/reset_workflow_test.go @@ -925,9 +925,7 @@ func (s *ResetWorkflowTestSuite) TestResetWorkflow_ResetAfterContinueAsNew() { HostPort: s.FrontendGRPCAddress(), Namespace: s.Namespace().String(), }) - if err != nil { - s.Logger.Fatal("Error when creating SDK client", tag.Error(err)) - } + s.NoError(err) // start workflow that does CaN once w := worker.New(sdkClient, tq, worker.Options{Identity: id}) diff --git a/tests/schedule_test.go b/tests/schedule_test.go index cafebcde0b5..31e4f1d755a 100644 --- a/tests/schedule_test.go +++ b/tests/schedule_test.go @@ -46,11 +46,9 @@ import ( "go.temporal.io/sdk/worker" "go.temporal.io/sdk/workflow" "go.temporal.io/server/common/dynamicconfig" - "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/payload" "go.temporal.io/server/common/payloads" "go.temporal.io/server/common/searchattribute" - "go.temporal.io/server/common/testing/historyrequire" "go.temporal.io/server/common/testing/protorequire" "go.temporal.io/server/service/worker/scheduler" "go.temporal.io/server/tests/testcore" @@ -74,9 +72,8 @@ worker restart/long-poll activity failure: type ( ScheduleFunctionalSuite struct { - protorequire.ProtoAssertions - historyrequire.HistoryRequire - testcore.FunctionalTestBase + testcore.FunctionalTestSuite + sdkClient sdkclient.Client worker worker.Worker taskQueue string @@ -91,38 +88,30 @@ func TestScheduleFunctionalSuite(t *testing.T) { func (s *ScheduleFunctionalSuite) SetupSuite() { if testcore.UsingSQLAdvancedVisibility() { - s.FunctionalTestBase.SetupSuite("testdata/cluster.yaml") + s.FunctionalTestSuite.SetupSuiteWithCluster("testdata/cluster.yaml") s.Logger.Info(fmt.Sprintf("Running schedule tests with %s/%s persistence", testcore.TestFlags.PersistenceType, testcore.TestFlags.PersistenceDriver)) } else { - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") + s.FunctionalTestSuite.SetupSuiteWithCluster("testdata/es_cluster.yaml") s.Logger.Info("Running schedule tests with Elasticsearch persistence") } } -func (s *ScheduleFunctionalSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - func (s *ScheduleFunctionalSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - - s.ProtoAssertions = protorequire.New(s.T()) - s.HistoryRequire = historyrequire.New(s.T()) + s.FunctionalTestSuite.SetupTest() s.dataConverter = testcore.NewTestDataConverter() - sdkClient, err := sdkclient.Dial(sdkclient.Options{ + + var err error + s.sdkClient, err = sdkclient.Dial(sdkclient.Options{ HostPort: s.FrontendGRPCAddress(), Namespace: s.Namespace().String(), DataConverter: s.dataConverter, }) - if err != nil { - s.Logger.Fatal("Error when creating SDK client", tag.Error(err)) - } - s.sdkClient = sdkClient + s.NoError(err) + s.taskQueue = testcore.RandomizeStr("tq") s.worker = worker.New(s.sdkClient, s.taskQueue, worker.Options{}) - if err := s.worker.Start(); err != nil { - s.Logger.Fatal("Error when starting worker", tag.Error(err)) - } + err = s.worker.Start() + s.NoError(err) } func (s *ScheduleFunctionalSuite) TearDownTest() { diff --git a/tests/signal_workflow_test.go b/tests/signal_workflow_test.go index bb68b42590f..3e20fcd69df 100644 --- a/tests/signal_workflow_test.go +++ b/tests/signal_workflow_test.go @@ -56,7 +56,7 @@ import ( ) type SignalWorkflowTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestSignalWorkflowTestSuite(t *testing.T) { diff --git a/tests/sizelimit_test.go b/tests/sizelimit_test.go index 80a838aaa91..345988f9c33 100644 --- a/tests/sizelimit_test.go +++ b/tests/sizelimit_test.go @@ -31,7 +31,6 @@ import ( "time" "github.com/pborman/uuid" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" commandpb "go.temporal.io/api/command/v1" commonpb "go.temporal.io/api/common/v1" @@ -45,7 +44,6 @@ import ( "go.temporal.io/server/common/convert" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/payloads" - "go.temporal.io/server/common/testing/historyrequire" "go.temporal.io/server/service/history/consts" "go.temporal.io/server/tests/testcore" "google.golang.org/protobuf/types/known/durationpb" @@ -53,11 +51,7 @@ import ( ) type SizeLimitFunctionalSuite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - *require.Assertions - historyrequire.HistoryRequire - testcore.FunctionalTestBase + testcore.FunctionalTestSuite } func TestSizeLimitFunctionalSuite(t *testing.T) { @@ -67,19 +61,7 @@ func TestSizeLimitFunctionalSuite(t *testing.T) { // This cluster use customized threshold for history config func (s *SizeLimitFunctionalSuite) SetupSuite() { - s.FunctionalTestBase.SetupSuite("testdata/sizelimit_cluster.yaml") -} - -func (s *SizeLimitFunctionalSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - -func (s *SizeLimitFunctionalSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - - // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil - s.Assertions = require.New(s.T()) - s.HistoryRequire = historyrequire.New(s.T()) + s.FunctionalTestSuite.SetupSuiteWithCluster("testdata/sizelimit_cluster.yaml") } func (s *SizeLimitFunctionalSuite) TestTerminateWorkflowCausedByHistoryCountLimit() { diff --git a/tests/stickytq_test.go b/tests/stickytq_test.go index 3a267655a73..303f0950352 100644 --- a/tests/stickytq_test.go +++ b/tests/stickytq_test.go @@ -43,7 +43,7 @@ import ( ) type StickyTqTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestStickyTqTestSuite(t *testing.T) { diff --git a/tests/testcore/client.go b/tests/testcore/client.go deleted file mode 100644 index aa670d81a80..00000000000 --- a/tests/testcore/client.go +++ /dev/null @@ -1,46 +0,0 @@ -// 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 testcore - -import ( - "go.temporal.io/api/workflowservice/v1" - "go.temporal.io/server/api/adminservice/v1" - "go.temporal.io/server/api/historyservice/v1" -) - -// AdminClient is the interface exposed by admin service client -type AdminClient interface { - adminservice.AdminServiceClient -} - -// FrontendClient is the interface exposed by frontend service client -type FrontendClient interface { - workflowservice.WorkflowServiceClient -} - -// HistoryClient is the interface exposed by history service client -type HistoryClient interface { - historyservice.HistoryServiceClient -} diff --git a/tests/testcore/functional.go b/tests/testcore/functional.go deleted file mode 100644 index 3dcaab1923a..00000000000 --- a/tests/testcore/functional.go +++ /dev/null @@ -1,101 +0,0 @@ -// 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 testcore - -import ( - "time" - - "github.com/stretchr/testify/require" - commonpb "go.temporal.io/api/common/v1" - "go.temporal.io/api/workflowservice/v1" - "go.temporal.io/server/common/dynamicconfig" - "go.temporal.io/server/common/testing/historyrequire" - "go.temporal.io/server/common/testing/protorequire" - "go.temporal.io/server/common/testing/taskpoller" - "go.temporal.io/server/common/testing/updateutils" -) - -type ( - FunctionalSuite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - *require.Assertions - protorequire.ProtoAssertions - historyrequire.HistoryRequire - updateutils.UpdateUtils - FunctionalTestBase - - TaskPoller *taskpoller.TaskPoller - } -) - -func (s *FunctionalSuite) SetupSuite() { - s.dynamicConfigOverrides = map[dynamicconfig.Key]any{ - dynamicconfig.RetentionTimerJitterDuration.Key(): time.Second, - dynamicconfig.EnableEagerWorkflowStart.Key(): true, - dynamicconfig.FrontendEnableExecuteMultiOperation.Key(): true, - } - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") -} - -func (s *FunctionalSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - -func (s *FunctionalSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - s.initAssertions() -} - -func (s *FunctionalSuite) SetupSubTest() { - s.initAssertions() -} - -func (s *FunctionalSuite) initAssertions() { - // `s.Assertions` (as well as other test helpers which depends on `s.T()`) must be initialized on - // both test and subtest levels (but not suite level, where `s.T()` is `nil`). - // - // If these helpers are not reinitialized on subtest level, any failed `assert` in - // subtest will fail the entire test (not subtest) immediately without running other subtests. - - s.Assertions = require.New(s.T()) - s.ProtoAssertions = protorequire.New(s.T()) - s.HistoryRequire = historyrequire.New(s.T()) - s.UpdateUtils = updateutils.New(s.T()) - s.TaskPoller = taskpoller.New(s.T(), s.client, s.Namespace().String()) -} - -func (s *FunctionalSuite) SendSignal(namespace string, execution *commonpb.WorkflowExecution, signalName string, - input *commonpb.Payloads, identity string) error { - _, err := s.client.SignalWorkflowExecution(NewContext(), &workflowservice.SignalWorkflowExecutionRequest{ - Namespace: namespace, - WorkflowExecution: execution, - SignalName: signalName, - Input: input, - Identity: identity, - }) - - return err -} diff --git a/tests/testcore/functional_test_base.go b/tests/testcore/functional_test_base.go index d104b5d127d..d8027c681bb 100644 --- a/tests/testcore/functional_test_base.go +++ b/tests/testcore/functional_test_base.go @@ -56,36 +56,51 @@ import ( "go.temporal.io/server/common/primitives" "go.temporal.io/server/common/primitives/timestamp" "go.temporal.io/server/common/rpc" + "go.temporal.io/server/common/testing/historyrequire" + "go.temporal.io/server/common/testing/protorequire" + "go.temporal.io/server/common/testing/updateutils" "go.temporal.io/server/environment" "go.uber.org/fx" "gopkg.in/yaml.v3" ) type ( - // FunctionalTestBase is a testcore struct for functional tests FunctionalTestBase struct { suite.Suite - testClusterFactory TestClusterFactory - testCluster *TestCluster - testClusterConfig *TestClusterConfig - client workflowservice.WorkflowServiceClient - adminClient adminservice.AdminServiceClient - operatorClient operatorservice.OperatorServiceClient - httpAPIAddress string - Logger log.Logger - namespace namespace.Name - namespaceID namespace.ID - foreignNamespace namespace.Name - archivalNamespace namespace.Name - archivalNamespaceID namespace.ID - dynamicConfigOverrides map[dynamicconfig.Key]interface{} + // `suite.Suite` embeds `*assert.Assertions` which, by default, makes all asserts (like `s.NoError(err)`) + // only log the error, continue test execution, and only then fail the test. + // This is not desired behavior in most cases. The idiomatic way to change this behavior + // is to replace `*assert.Assertions` with `*require.Assertions` by embedding it in every test suite + // (or base struct of every test suite). + *require.Assertions + + protorequire.ProtoAssertions + historyrequire.HistoryRequire + updateutils.UpdateUtils + + Logger log.Logger + + // Test cluster configuration. + testClusterFactory TestClusterFactory + testCluster *TestCluster + testClusterConfig *TestClusterConfig + frontendClient workflowservice.WorkflowServiceClient + adminClient adminservice.AdminServiceClient + operatorClient operatorservice.OperatorServiceClient + httpAPIAddress string + namespace namespace.Name + namespaceID namespace.ID + foreignNamespace namespace.Name + archivalNamespace namespace.Name + archivalNamespaceID namespace.ID } - // TestClusterParams contains the variables which are used to configure test suites via the Option type. + // TestClusterParams contains the variables which are used to configure test cluster via the TestClusterOption type. TestClusterParams struct { - ServiceOptions map[primitives.ServiceName][]fx.Option + ServiceOptions map[primitives.ServiceName][]fx.Option + DynamicConfigOverrides map[dynamicconfig.Key]any } - Option func(params *TestClusterParams) + TestClusterOption func(params *TestClusterParams) ) // WithFxOptionsForService returns an Option which, when passed as an argument to setupSuite, will append the given list @@ -99,12 +114,22 @@ type ( // This is similar to the pattern of plumbing dependencies through the TestClusterConfig, but it's much more convenient, // scalable and flexible. The reason we need to do this on a per-service basis is that there are separate fx apps for // each one. -func WithFxOptionsForService(serviceName primitives.ServiceName, options ...fx.Option) Option { +func WithFxOptionsForService(serviceName primitives.ServiceName, options ...fx.Option) TestClusterOption { return func(params *TestClusterParams) { params.ServiceOptions[serviceName] = append(params.ServiceOptions[serviceName], options...) } } +func WithDynamicConfigOverrides(overrides map[dynamicconfig.Key]any) TestClusterOption { + return func(params *TestClusterParams) { + if params.DynamicConfigOverrides == nil { + params.DynamicConfigOverrides = overrides + } else { + maps.Copy(params.DynamicConfigOverrides, overrides) + } + } +} + func (s *FunctionalTestBase) GetTestCluster() *TestCluster { return s.testCluster } @@ -113,11 +138,11 @@ func (s *FunctionalTestBase) GetTestClusterConfig() *TestClusterConfig { return s.testClusterConfig } -func (s *FunctionalTestBase) FrontendClient() FrontendClient { - return s.client +func (s *FunctionalTestBase) FrontendClient() workflowservice.WorkflowServiceClient { + return s.frontendClient } -func (s *FunctionalTestBase) AdminClient() AdminClient { +func (s *FunctionalTestBase) AdminClient() adminservice.AdminServiceClient { return s.adminClient } @@ -153,46 +178,62 @@ func (s *FunctionalTestBase) FrontendGRPCAddress() string { return s.GetTestCluster().Host().FrontendGRPCAddress() } -func (s *FunctionalTestBase) SetDynamicConfigOverrides(dynamicConfig map[dynamicconfig.Key]interface{}) { - s.dynamicConfigOverrides = dynamicConfig +func (s *FunctionalTestBase) SetupSuite() { + s.SetupSuiteWithDefaultCluster() } -func (s *FunctionalTestBase) SetupSuite(defaultClusterConfigFile string, options ...Option) { - s.testClusterFactory = NewTestClusterFactory() +func (s *FunctionalTestBase) TearDownSuite() { + s.TearDownCluster() +} - params := ApplyTestClusterParams(options) +func (s *FunctionalTestBase) SetupSuiteWithDefaultCluster(options ...TestClusterOption) { + // TODO (alex): rename es_cluster.yaml to default_cluster.yaml + // TODO (alex): reduce the number of configs or may be get rid of it completely. + // TODO (alex): or replace clusterConfigFile param with WithClusterConfigFile option with default value. + s.SetupSuiteWithCluster("testdata/es_cluster.yaml", options...) +} +func (s *FunctionalTestBase) SetupSuiteWithCluster(clusterConfigFile string, options ...TestClusterOption) { + params := ApplyTestClusterOptions(options) - s.setupLogger() + // Logger might be already set by the test suite. + if s.Logger == nil { + s.Logger = log.NewTestLogger() + } - clusterConfig, err := GetTestClusterConfig(defaultClusterConfigFile) + // Setup test cluster. + var err error + s.testClusterConfig, err = readTestClusterConfig(clusterConfigFile) s.Require().NoError(err) - s.Empty(clusterConfig.DeprecatedFrontendAddress, "Functional tests against external frontends are not supported") - s.Empty(clusterConfig.DeprecatedClusterNo, "ClusterNo should not be present in cluster config files") + s.Require().Empty(s.testClusterConfig.DeprecatedFrontendAddress, "Functional tests against external frontends are not supported") + s.Require().Empty(s.testClusterConfig.DeprecatedClusterNo, "ClusterNo should not be present in cluster config files") - if clusterConfig.DynamicConfigOverrides == nil { - clusterConfig.DynamicConfigOverrides = make(map[dynamicconfig.Key]interface{}) + if s.testClusterConfig.DynamicConfigOverrides == nil { + s.testClusterConfig.DynamicConfigOverrides = make(map[dynamicconfig.Key]any) } - maps.Copy(clusterConfig.DynamicConfigOverrides, map[dynamicconfig.Key]any{ + + // TODO (alex): clusterConfig shouldn't have DC at all. + maps.Copy(s.testClusterConfig.DynamicConfigOverrides, map[dynamicconfig.Key]any{ dynamicconfig.HistoryScannerEnabled.Key(): false, dynamicconfig.TaskQueueScannerEnabled.Key(): false, dynamicconfig.ExecutionsScannerEnabled.Key(): false, dynamicconfig.BuildIdScavengerEnabled.Key(): false, // Better to read through in tests than add artificial sleeps (which is what we previously had). dynamicconfig.ForceSearchAttributesCacheRefreshOnRead.Key(): true, + dynamicconfig.RetentionTimerJitterDuration.Key(): time.Second, + dynamicconfig.EnableEagerWorkflowStart.Key(): true, + dynamicconfig.FrontendEnableExecuteMultiOperation.Key(): true, }) - maps.Copy(clusterConfig.DynamicConfigOverrides, s.dynamicConfigOverrides) - clusterConfig.ServiceFxOptions = params.ServiceOptions - clusterConfig.EnableMetricsCapture = true - s.testClusterConfig = clusterConfig + maps.Copy(s.testClusterConfig.DynamicConfigOverrides, params.DynamicConfigOverrides) + + s.testClusterConfig.ServiceFxOptions = params.ServiceOptions + s.testClusterConfig.EnableMetricsCapture = true + + s.testClusterFactory = NewTestClusterFactory() - cluster, err := s.testClusterFactory.NewCluster(s.T(), clusterConfig, s.Logger) + s.testCluster, err = s.testClusterFactory.NewCluster(s.T(), s.testClusterConfig, s.Logger) s.Require().NoError(err) - s.testCluster = cluster - s.client = s.testCluster.FrontendClient() - s.adminClient = s.testCluster.AdminClient() - s.operatorClient = s.testCluster.OperatorClient() - s.httpAPIAddress = cluster.Host().FrontendHTTPAddress() + // Setup test cluster namespaces. s.namespace = namespace.Name(RandomizeStr("namespace")) s.namespaceID, err = s.registerNamespace(s.Namespace(), 1, enumspb.ARCHIVAL_STATE_DISABLED, "", "") s.Require().NoError(err) @@ -201,7 +242,7 @@ func (s *FunctionalTestBase) SetupSuite(defaultClusterConfigFile string, options _, err = s.registerNamespace(s.ForeignNamespace(), 1, enumspb.ARCHIVAL_STATE_DISABLED, "", "") s.Require().NoError(err) - if clusterConfig.EnableArchival { + if s.testClusterConfig.EnableArchival { s.archivalNamespace = namespace.Name(RandomizeStr("archival-enabled-namespace")) s.archivalNamespaceID, err = s.registerNamespace( s.ArchivalNamespace(), @@ -212,6 +253,13 @@ func (s *FunctionalTestBase) SetupSuite(defaultClusterConfigFile string, options ) s.Require().NoError(err) } + + // Setup test cluster clients. + s.frontendClient = s.testCluster.FrontendClient() + s.adminClient = s.testCluster.AdminClient() + s.operatorClient = s.testCluster.OperatorClient() + s.httpAPIAddress = s.testCluster.Host().FrontendHTTPAddress() + } // All test suites that inherit FunctionalTestBase and overwrite SetupTest must @@ -222,6 +270,24 @@ func (s *FunctionalTestBase) SetupSuite(defaultClusterConfigFile string, options // from FunctionalTestBase must implement SetupTest that calls checkTestShard. func (s *FunctionalTestBase) SetupTest() { s.checkTestShard() + s.initAssertions() +} + +func (s *FunctionalTestBase) SetupSubTest() { + s.initAssertions() +} + +func (s *FunctionalTestBase) initAssertions() { + // `s.Assertions` (as well as other test helpers which depends on `s.T()`) must be initialized on + // both test and subtest levels (but not suite level, where `s.T()` is `nil`). + // + // If these helpers are not reinitialized on subtest level, any failed `assert` in + // subtest will fail the entire test (not subtest) immediately without running other subtests. + + s.Assertions = require.New(s.T()) + s.ProtoAssertions = protorequire.New(s.T()) + s.HistoryRequire = historyrequire.New(s.T()) + s.UpdateUtils = updateutils.New(s.T()) } // checkTestShard supports test sharding based on environment variables. @@ -253,7 +319,7 @@ func (s *FunctionalTestBase) checkTestShard() { s.T().Logf("Running %s in test shard %d/%d", s.T().Name(), index+1, total) } -func ApplyTestClusterParams(options []Option) TestClusterParams { +func ApplyTestClusterOptions(options []TestClusterOption) TestClusterParams { params := TestClusterParams{ ServiceOptions: make(map[primitives.ServiceName][]fx.Option), } @@ -263,17 +329,7 @@ func ApplyTestClusterParams(options []Option) TestClusterParams { return params } -// setupLogger sets the Logger for the test suite. -// If the Logger is already set, this method does nothing. -// If the Logger is not set, this method creates a new log.TestLogger which logs to stdout and stderr. -func (s *FunctionalTestBase) setupLogger() { - if s.Logger == nil { - s.Logger = log.NewTestLogger() - } -} - -// GetTestClusterConfig return test cluster config -func GetTestClusterConfig(configFile string) (*TestClusterConfig, error) { +func readTestClusterConfig(configFile string) (*TestClusterConfig, error) { environment.SetupEnv() configLocation := configFile @@ -293,8 +349,8 @@ func GetTestClusterConfig(configFile string) (*TestClusterConfig, error) { return nil, fmt.Errorf("failed to read test cluster config file %s: %w", configLocation, err) } confContent = []byte(os.ExpandEnv(string(confContent))) - var options TestClusterConfig - if err := yaml.Unmarshal(confContent, &options); err != nil { + var clusterConfig TestClusterConfig + if err = yaml.Unmarshal(confContent, &clusterConfig); err != nil { return nil, fmt.Errorf("failed to decode test cluster config %s: %w", configLocation, err) } @@ -307,16 +363,16 @@ func GetTestClusterConfig(configFile string) (*TestClusterConfig, error) { } var fiOptions TestClusterConfig - if err := yaml.Unmarshal(fiConfigContent, &fiOptions); err != nil { + if err = yaml.Unmarshal(fiConfigContent, &fiOptions); err != nil { return nil, fmt.Errorf("failed to decode test cluster fault injection config %s: %w", TestFlags.FaultInjectionConfigFile, err) } - options.FaultInjection = fiOptions.FaultInjection + clusterConfig.FaultInjection = fiOptions.FaultInjection } - return &options, nil + return &clusterConfig, nil } -func (s *FunctionalTestBase) TearDownSuite() { +func (s *FunctionalTestBase) TearDownCluster() { s.Require().NoError(s.markNamespaceAsDeleted(s.Namespace())) s.Require().NoError(s.markNamespaceAsDeleted(s.ForeignNamespace())) if s.ArchivalNamespace() != namespace.EmptyName { @@ -324,12 +380,8 @@ func (s *FunctionalTestBase) TearDownSuite() { } if s.testCluster != nil { - s.NoError(s.testCluster.TearDownCluster()) - s.testCluster = nil + s.Require().NoError(s.testCluster.TearDownCluster()) } - - s.client = nil - s.adminClient = nil } // Register namespace using persistence API because: @@ -398,7 +450,7 @@ func (s *FunctionalTestBase) markNamespaceAsDeleted( ) error { ctx, cancel := rpc.NewContextWithTimeoutAndVersionHeaders(10000 * time.Second) defer cancel() - _, err := s.client.UpdateNamespace(ctx, &workflowservice.UpdateNamespaceRequest{ + _, err := s.frontendClient.UpdateNamespace(ctx, &workflowservice.UpdateNamespaceRequest{ Namespace: nsName.String(), UpdateInfo: &namespacepb.UpdateNamespaceInfo{ State: enumspb.NAMESPACE_STATE_DELETED, @@ -410,7 +462,7 @@ func (s *FunctionalTestBase) markNamespaceAsDeleted( func (s *FunctionalTestBase) GetHistoryFunc(namespace string, execution *commonpb.WorkflowExecution) func() []*historypb.HistoryEvent { return func() []*historypb.HistoryEvent { - historyResponse, err := s.client.GetWorkflowExecutionHistory(NewContext(), &workflowservice.GetWorkflowExecutionHistoryRequest{ + historyResponse, err := s.frontendClient.GetWorkflowExecutionHistory(NewContext(), &workflowservice.GetWorkflowExecutionHistoryRequest{ Namespace: namespace, Execution: execution, MaximumPageSize: 5, // Use small page size to force pagination code path @@ -419,7 +471,7 @@ func (s *FunctionalTestBase) GetHistoryFunc(namespace string, execution *commonp events := historyResponse.History.Events for historyResponse.NextPageToken != nil { - historyResponse, err = s.client.GetWorkflowExecutionHistory(NewContext(), &workflowservice.GetWorkflowExecutionHistoryRequest{ + historyResponse, err = s.frontendClient.GetWorkflowExecutionHistory(NewContext(), &workflowservice.GetWorkflowExecutionHistoryRequest{ Namespace: namespace, Execution: execution, NextPageToken: historyResponse.NextPageToken, @@ -535,3 +587,17 @@ func (s *FunctionalTestBase) WaitForChannel(ctx context.Context, ch chan struct{ s.FailNow("context timeout while waiting for channel") } } + +// TODO (alex): change to nsName namespace.Name +func (s *FunctionalTestBase) SendSignal(nsName string, execution *commonpb.WorkflowExecution, signalName string, + input *commonpb.Payloads, identity string) error { + _, err := s.frontendClient.SignalWorkflowExecution(NewContext(), &workflowservice.SignalWorkflowExecutionRequest{ + Namespace: nsName, + WorkflowExecution: execution, + SignalName: signalName, + Input: input, + Identity: identity, + }) + + return err +} diff --git a/tests/testcore/functional_test_base_suite.go b/tests/testcore/functional_test_base_suite.go deleted file mode 100644 index cdfbabaa1b2..00000000000 --- a/tests/testcore/functional_test_base_suite.go +++ /dev/null @@ -1,73 +0,0 @@ -// 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 testcore - -import ( - "github.com/stretchr/testify/require" - "go.temporal.io/server/common/primitives" - "go.uber.org/fx" -) - -type FunctionalTestBaseSuite struct { - *require.Assertions - FunctionalTestBase - frontendServiceName primitives.ServiceName - matchingServiceName primitives.ServiceName - historyServiceName primitives.ServiceName - workerServiceName primitives.ServiceName -} - -func (s *FunctionalTestBaseSuite) SetupSuite() { - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml", - WithFxOptionsForService(primitives.FrontendService, fx.Populate(&s.frontendServiceName)), - WithFxOptionsForService(primitives.MatchingService, fx.Populate(&s.matchingServiceName)), - WithFxOptionsForService(primitives.HistoryService, fx.Populate(&s.historyServiceName)), - WithFxOptionsForService(primitives.WorkerService, fx.Populate(&s.workerServiceName)), - ) - -} - -func (s *FunctionalTestBaseSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - -func (s *FunctionalTestBaseSuite) TestWithFxOptionsForService() { - // This test works by using the WithFxOptionsForService option to obtain the ServiceName from the graph, and then - // it verifies that the ServiceName is correct. It does this because we are targeting the fx.App for a particular - // service, so we'll know our fx options were provided to the right service if, when we use them to get the current - // service name, it matches the target service. A more realistic example would use the option to obtain an actual - // useful object like a history shard controller, or do some graph modifications with fx.Decorate. - - s.Equal(primitives.FrontendService, s.frontendServiceName) - s.Equal(primitives.MatchingService, s.matchingServiceName) - s.Equal(primitives.HistoryService, s.historyServiceName) - s.Equal(primitives.WorkerService, s.workerServiceName) -} - -func (s *FunctionalTestBaseSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() - - s.Assertions = require.New(s.T()) -} diff --git a/tests/testcore/functional_test_base_test.go b/tests/testcore/functional_test_base_test.go index 469a27e89f2..727ad3f20b6 100644 --- a/tests/testcore/functional_test_base_test.go +++ b/tests/testcore/functional_test_base_test.go @@ -28,9 +28,50 @@ import ( "testing" "github.com/stretchr/testify/suite" + "go.temporal.io/server/common/primitives" + "go.uber.org/fx" ) +type FunctionalTestBaseSuite struct { + FunctionalTestBase + + frontendServiceName primitives.ServiceName + matchingServiceName primitives.ServiceName + historyServiceName primitives.ServiceName + workerServiceName primitives.ServiceName +} + func TestFunctionalTestBaseSuite(t *testing.T) { t.Parallel() - suite.Run(t, new(FunctionalTestBaseSuite)) + suite.Run(t, &FunctionalTestBaseSuite{}) +} + +func (s *FunctionalTestBaseSuite) SetupSuite() { + s.FunctionalTestBase.SetupSuiteWithCluster("testdata/es_cluster.yaml", + WithFxOptionsForService(primitives.FrontendService, fx.Populate(&s.frontendServiceName)), + WithFxOptionsForService(primitives.MatchingService, fx.Populate(&s.matchingServiceName)), + WithFxOptionsForService(primitives.HistoryService, fx.Populate(&s.historyServiceName)), + WithFxOptionsForService(primitives.WorkerService, fx.Populate(&s.workerServiceName)), + ) +} + +func (s *FunctionalTestBaseSuite) TearDownSuite() { + s.FunctionalTestBase.TearDownCluster() +} + +func (s *FunctionalTestBaseSuite) SetupTest() { + s.FunctionalTestBase.SetupTest() +} + +func (s *FunctionalTestBaseSuite) TestWithFxOptionsForService() { + // This test works by using the WithFxOptionsForService option to obtain the ServiceName from the graph, and then + // it verifies that the ServiceName is correct. It does this because we are targeting the fx.App for a particular + // service, so we'll know our fx options were provided to the right service if, when we use them to get the current + // service name, it matches the target service. A more realistic example would use the option to obtain an actual + // useful object like a history shard controller, or do some graph modifications with fx.Decorate. + + s.Equal(primitives.FrontendService, s.frontendServiceName) + s.Equal(primitives.MatchingService, s.matchingServiceName) + s.Equal(primitives.HistoryService, s.historyServiceName) + s.Equal(primitives.WorkerService, s.workerServiceName) } diff --git a/tests/testcore/client_suite.go b/tests/testcore/functional_test_sdk_suite.go similarity index 65% rename from tests/testcore/client_suite.go rename to tests/testcore/functional_test_sdk_suite.go index 41099a087f4..2ff9e62b5f0 100644 --- a/tests/testcore/client_suite.go +++ b/tests/testcore/functional_test_sdk_suite.go @@ -30,31 +30,23 @@ import ( "fmt" "time" - "github.com/stretchr/testify/require" enumspb "go.temporal.io/api/enums/v1" historypb "go.temporal.io/api/history/v1" sdkclient "go.temporal.io/sdk/client" "go.temporal.io/sdk/worker" "go.temporal.io/server/common/backoff" "go.temporal.io/server/common/dynamicconfig" - "go.temporal.io/server/common/log/tag" - "go.temporal.io/server/common/testing/historyrequire" "go.temporal.io/server/components/callbacks" "go.temporal.io/server/components/nexusoperations" ) type ( - ClientFunctionalSuite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - *require.Assertions + FunctionalTestSdkSuite struct { FunctionalTestBase - historyrequire.HistoryRequire + sdkClient sdkclient.Client worker worker.Worker taskQueue string - - baseConfigPath string } ) @@ -63,19 +55,19 @@ var ( ErrEncodingIsNotSupported = errors.New("payload encoding is not supported") ) -func (s *ClientFunctionalSuite) Worker() worker.Worker { +func (s *FunctionalTestSdkSuite) Worker() worker.Worker { return s.worker } -func (s *ClientFunctionalSuite) SdkClient() sdkclient.Client { +func (s *FunctionalTestSdkSuite) SdkClient() sdkclient.Client { return s.sdkClient } -func (s *ClientFunctionalSuite) TaskQueue() string { +func (s *FunctionalTestSdkSuite) TaskQueue() string { return s.taskQueue } -func (s *ClientFunctionalSuite) SetupSuite() { +func (s *FunctionalTestSdkSuite) SetupSuite() { // these limits are higher in production, but our tests would take too long if we set them that high dynamicConfigOverrides := map[dynamicconfig.Key]any{ dynamicconfig.NumPendingChildExecutionsLimitError.Key(): ClientSuiteLimit, @@ -88,43 +80,34 @@ func (s *ClientFunctionalSuite) SetupSuite() { dynamicconfig.RefreshNexusEndpointsMinWait.Key(): 1 * time.Millisecond, callbacks.AllowedAddresses.Key(): []any{map[string]any{"Pattern": "*", "AllowInsecure": true}}, } - s.SetDynamicConfigOverrides(dynamicConfigOverrides) - s.FunctionalTestBase.SetupSuite("testdata/client_cluster.yaml") -} -func (s *ClientFunctionalSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() + s.FunctionalTestBase.SetupSuiteWithCluster("testdata/client_cluster.yaml", WithDynamicConfigOverrides(dynamicConfigOverrides)) } -func (s *ClientFunctionalSuite) SetupTest() { +func (s *FunctionalTestSdkSuite) SetupTest() { s.FunctionalTestBase.SetupTest() - s.initAssertions() - // Set URL template after httpAPAddress is set, see commonnexus.RouteCompletionCallback s.OverrideDynamicConfig( nexusoperations.CallbackURLTemplate, "http://"+s.HttpAPIAddress()+"/namespaces/{{.NamespaceName}}/nexus/callback") - sdkClient, err := sdkclient.Dial(sdkclient.Options{ + var err error + s.sdkClient, err = sdkclient.Dial(sdkclient.Options{ HostPort: s.FrontendGRPCAddress(), Namespace: s.Namespace().String(), }) - if err != nil { - s.Logger.Fatal("Error when creating SDK client", tag.Error(err)) - } - s.sdkClient = sdkClient + s.NoError(err) s.taskQueue = RandomizeStr("tq") // We need to set this timeout to 0 to disable the deadlock detector. Otherwise, the deadlock detector will cause // TestTooManyChildWorkflows to fail because it thinks there is a deadlock due to the blocked child workflows. s.worker = worker.New(s.sdkClient, s.taskQueue, worker.Options{DeadlockDetectionTimeout: 0}) - if err := s.worker.Start(); err != nil { - s.Logger.Fatal("Error when start worker", tag.Error(err)) - } + err = s.worker.Start() + s.NoError(err) } -func (s *ClientFunctionalSuite) TearDownTest() { +func (s *FunctionalTestSdkSuite) TearDownTest() { if s.worker != nil { s.worker.Stop() } @@ -133,22 +116,7 @@ func (s *ClientFunctionalSuite) TearDownTest() { } } -func (s *ClientFunctionalSuite) SetupSubTest() { - s.initAssertions() -} - -func (s *ClientFunctionalSuite) initAssertions() { - // `s.Assertions` (as well as other test helpers which depends on `s.T()`) must be initialized on - // both test and subtest levels (but not suite level, where `s.T()` is `nil`). - // - // If these helpers are not reinitialized on subtest level, any failed `assert` in - // subtest will fail the entire test (not subtest) immediately without running other subtests. - - s.Assertions = require.New(s.T()) - s.HistoryRequire = historyrequire.New(s.T()) -} - -func (s *ClientFunctionalSuite) EventuallySucceeds(ctx context.Context, operationCtx backoff.OperationCtx) { +func (s *FunctionalTestSdkSuite) EventuallySucceeds(ctx context.Context, operationCtx backoff.OperationCtx) { s.T().Helper() s.NoError(backoff.ThrottleRetryContext( ctx, @@ -161,7 +129,7 @@ func (s *ClientFunctionalSuite) EventuallySucceeds(ctx context.Context, operatio )) } -func (s *ClientFunctionalSuite) HistoryContainsFailureCausedBy( +func (s *FunctionalTestSdkSuite) HistoryContainsFailureCausedBy( ctx context.Context, workflowId string, cause enumspb.WorkflowTaskFailedCause, @@ -188,15 +156,3 @@ func (s *ClientFunctionalSuite) HistoryContainsFailureCausedBy( return fmt.Errorf("did not find a failed task whose cause was %q", cause) }) } - -// Uncomment if you need to debug history. -// func (s *ClientFunctionalSuite) printHistory(workflowID string, runID string) { -// iter := s.sdkClient.GetWorkflowHistory(context.Background(), workflowID, runID, false, 0) -// history := &historypb.History{} -// for iter.HasNext() { -// event, err := iter.Next() -// s.NoError(err) -// history.Events = append(history.Events, event) -// } -// common.PrettyPrintHistory(history, s.Logger) -// } diff --git a/tests/testcore/functional_test.go b/tests/testcore/functional_test_suite.go similarity index 80% rename from tests/testcore/functional_test.go rename to tests/testcore/functional_test_suite.go index 3b27c0a07a6..43c07a59a5d 100644 --- a/tests/testcore/functional_test.go +++ b/tests/testcore/functional_test_suite.go @@ -25,12 +25,18 @@ package testcore import ( - "testing" + "go.temporal.io/server/common/testing/taskpoller" +) + +type ( + FunctionalTestSuite struct { + FunctionalTestBase - "github.com/stretchr/testify/suite" + TaskPoller *taskpoller.TaskPoller + } ) -func TestFunctionalSuite(t *testing.T) { - t.Parallel() - suite.Run(t, new(FunctionalSuite)) +func (s *FunctionalTestSuite) SetupTest() { + s.FunctionalTestBase.SetupTest() + s.TaskPoller = taskpoller.New(s.T(), s.frontendClient, s.Namespace().String()) } diff --git a/tests/testcore/onebox.go b/tests/testcore/onebox.go index 1bb3ed47ef3..481d0e4600b 100644 --- a/tests/testcore/onebox.go +++ b/tests/testcore/onebox.go @@ -138,8 +138,10 @@ type ( // HistoryConfig contains configs for history service HistoryConfig struct { - NumHistoryShards int32 - NumHistoryHosts int + NumHistoryShards int32 + NumHistoryHosts int + + // TODO (alex): Remove all this limits and replace them with consts in sizelimit_tests.go HistoryCountLimitError int HistoryCountLimitWarn int HistorySizeLimitError int diff --git a/tests/testcore/test_cluster.go b/tests/testcore/test_cluster.go index 5c4b6dbd552..a3e3ee59670 100644 --- a/tests/testcore/test_cluster.go +++ b/tests/testcore/test_cluster.go @@ -37,6 +37,7 @@ import ( "github.com/pborman/uuid" "go.temporal.io/api/operatorservice/v1" + "go.temporal.io/api/workflowservice/v1" "go.temporal.io/server/api/adminservice/v1" "go.temporal.io/server/api/historyservice/v1" "go.temporal.io/server/api/matchingservice/v1" @@ -103,7 +104,7 @@ type ( ESConfig *esclient.Config MockAdminClient map[string]adminservice.AdminServiceClient FaultInjection config.FaultInjection `yaml:"faultInjection"` - DynamicConfigOverrides map[dynamicconfig.Key]interface{} + DynamicConfigOverrides map[dynamicconfig.Key]any GenerateMTLS bool EnableMetricsCapture bool // ServiceFxOptions can be populated using WithFxOptionsForService. @@ -564,13 +565,11 @@ func (tc *TestCluster) ArchivalBase() *ArchiverBase { return tc.archiverBase } -// FrontendClient returns a frontend client from the test cluster -func (tc *TestCluster) FrontendClient() FrontendClient { +func (tc *TestCluster) FrontendClient() workflowservice.WorkflowServiceClient { return tc.host.FrontendClient() } -// AdminClient returns an admin client from the test cluster -func (tc *TestCluster) AdminClient() AdminClient { +func (tc *TestCluster) AdminClient() adminservice.AdminServiceClient { return tc.host.AdminClient() } diff --git a/tests/testcore/test_search_attribute_mapper.go b/tests/testcore/test_search_attribute_mapper.go deleted file mode 100644 index 699a2deb7f9..00000000000 --- a/tests/testcore/test_search_attribute_mapper.go +++ /dev/null @@ -1,58 +0,0 @@ -// 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 testcore - -import ( - "fmt" - "strings" - - "go.temporal.io/api/serviceerror" - "go.temporal.io/server/common/searchattribute" -) - -type ( - SearchAttributeTestMapper struct{} -) - -func NewSearchAttributeTestMapper() *SearchAttributeTestMapper { - return &SearchAttributeTestMapper{} -} - -func (t *SearchAttributeTestMapper) GetAlias(fieldName string, namespace string) (string, error) { - if _, err := searchattribute.TestNameTypeMap.GetType(fieldName); err == nil { - return "AliasFor" + fieldName, nil - } - return "", serviceerror.NewInvalidArgument(fmt.Sprintf("fieldname '%s' has no search-attribute defined for '%s' namespace", fieldName, namespace)) -} - -func (t *SearchAttributeTestMapper) GetFieldName(alias string, namespace string) (string, error) { - if strings.HasPrefix(alias, "AliasFor") { - fieldName := strings.TrimPrefix(alias, "AliasFor") - if _, err := searchattribute.TestNameTypeMap.GetType(fieldName); err == nil { - return fieldName, nil - } - } - return "", serviceerror.NewInvalidArgument(fmt.Sprintf("search-attribute '%s' not found for '%s' namespace", alias, namespace)) -} diff --git a/tests/testcore/utils.go b/tests/testcore/utils.go index af10abd416b..04d45b7a5de 100644 --- a/tests/testcore/utils.go +++ b/tests/testcore/utils.go @@ -37,6 +37,8 @@ import ( "go.temporal.io/server/common/persistence/versionhistory" ) +// TODO (alex): move this to functional_test_base.go as methods. + func RandomizeStr(id string) string { return fmt.Sprintf("%v-%v", id, uuid.New()) } diff --git a/tests/tls_test.go b/tests/tls_test.go index bc4e92e3ca4..9ab0742d774 100644 --- a/tests/tls_test.go +++ b/tests/tls_test.go @@ -35,7 +35,6 @@ import ( "go.temporal.io/api/workflowservice/v1" sdkclient "go.temporal.io/sdk/client" "go.temporal.io/server/common/authorization" - "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/rpc" "go.temporal.io/server/tests/testcore" ) @@ -51,11 +50,11 @@ func TestTLSFunctionalSuite(t *testing.T) { } func (s *TLSFunctionalSuite) SetupSuite() { - s.FunctionalTestBase.SetupSuite("testdata/tls_cluster.yaml") + s.FunctionalTestBase.SetupSuiteWithCluster("testdata/tls_cluster.yaml") } func (s *TLSFunctionalSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() + s.FunctionalTestBase.TearDownCluster() } func (s *TLSFunctionalSuite) SetupTest() { @@ -69,9 +68,7 @@ func (s *TLSFunctionalSuite) SetupTest() { TLS: s.GetTestCluster().Host().TlsConfigProvider().FrontendClientConfig, }, }) - if err != nil { - s.Logger.Fatal("Error when creating SDK client", tag.Error(err)) - } + s.NoError(err) } func (s *TLSFunctionalSuite) TearDownTest() { diff --git a/tests/transient_task_test.go b/tests/transient_task_test.go index 343d07f88cc..e16a9e7549e 100644 --- a/tests/transient_task_test.go +++ b/tests/transient_task_test.go @@ -46,7 +46,7 @@ import ( ) type TransientTaskSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestTransientTaskSuite(t *testing.T) { diff --git a/tests/update_workflow_sdk_test.go b/tests/update_workflow_sdk_test.go index 6fc76624692..fa0bd656228 100644 --- a/tests/update_workflow_sdk_test.go +++ b/tests/update_workflow_sdk_test.go @@ -47,7 +47,7 @@ var ( ) type UpdateWorkflowSdkSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestUpdateWorkflowSdkSuite(t *testing.T) { diff --git a/tests/update_workflow_suite_base.go b/tests/update_workflow_suite_base.go index 2e73fa1432b..3bcd2a52192 100644 --- a/tests/update_workflow_suite_base.go +++ b/tests/update_workflow_suite_base.go @@ -39,7 +39,7 @@ import ( ) type WorkflowUpdateBaseSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } type updateResponseErr struct { diff --git a/tests/user_metadata_test.go b/tests/user_metadata_test.go index f8d3b8ce8be..bd8fc4ce140 100644 --- a/tests/user_metadata_test.go +++ b/tests/user_metadata_test.go @@ -38,7 +38,7 @@ import ( ) type UserMetadataSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestUserMetadataSuite(t *testing.T) { diff --git a/tests/user_timers_test.go b/tests/user_timers_test.go index d8e0fa5f7e4..e8a66e44c4c 100644 --- a/tests/user_timers_test.go +++ b/tests/user_timers_test.go @@ -45,7 +45,7 @@ import ( ) type UserTimersTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestUserTimersTestSuite(t *testing.T) { diff --git a/tests/versioning_3_test.go b/tests/versioning_3_test.go index ebd53ae32ea..999764af527 100644 --- a/tests/versioning_3_test.go +++ b/tests/versioning_3_test.go @@ -67,9 +67,7 @@ const ( ) type Versioning3Suite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - testcore.FunctionalTestBase + testcore.FunctionalTestSuite } func TestVersioning3FunctionalSuite(t *testing.T) { @@ -92,16 +90,7 @@ func (s *Versioning3Suite) SetupSuite() { dynamicconfig.MatchingNumTaskqueueReadPartitions.Key(): 4, dynamicconfig.MatchingNumTaskqueueWritePartitions.Key(): 4, } - s.SetDynamicConfigOverrides(dynamicConfigOverrides) - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") -} - -func (s *Versioning3Suite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() -} - -func (s *Versioning3Suite) SetupTest() { - s.FunctionalTestBase.SetupTest() + s.FunctionalTestSuite.SetupSuiteWithDefaultCluster(testcore.WithDynamicConfigOverrides(dynamicConfigOverrides)) } func (s *Versioning3Suite) TestPinnedTask_NoProperPoller() { diff --git a/tests/versioning_test.go b/tests/versioning_test.go index 1951f31cbe2..57f09da5746 100644 --- a/tests/versioning_test.go +++ b/tests/versioning_test.go @@ -54,7 +54,6 @@ import ( persistencespb "go.temporal.io/server/api/persistence/v1" taskqueuespb "go.temporal.io/server/api/taskqueue/v1" "go.temporal.io/server/common/dynamicconfig" - "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/searchattribute" "go.temporal.io/server/common/tqid" "go.temporal.io/server/common/worker_versioning" @@ -63,9 +62,7 @@ import ( ) type VersioningIntegSuite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - testcore.FunctionalTestBase + testcore.FunctionalTestSuite sdkClient sdkclient.Client } @@ -126,25 +123,18 @@ func (s *VersioningIntegSuite) SetupSuite() { // behaviour related to versioning dynamicconfig.TaskQueueInfoByBuildIdTTL.Key(): 0 * time.Second, } - s.SetDynamicConfigOverrides(dynamicConfigOverrides) - s.FunctionalTestBase.SetupSuite("testdata/es_cluster.yaml") -} - -func (s *VersioningIntegSuite) TearDownSuite() { - s.FunctionalTestBase.TearDownSuite() + s.FunctionalTestSuite.SetupSuiteWithDefaultCluster(testcore.WithDynamicConfigOverrides(dynamicConfigOverrides)) } func (s *VersioningIntegSuite) SetupTest() { - s.FunctionalTestBase.SetupTest() + s.FunctionalTestSuite.SetupTest() - sdkClient, err := sdkclient.Dial(sdkclient.Options{ + var err error + s.sdkClient, err = sdkclient.Dial(sdkclient.Options{ HostPort: s.FrontendGRPCAddress(), Namespace: s.Namespace().String(), }) - if err != nil { - s.Logger.Fatal("Error when creating SDK client", tag.Error(err)) - } - s.sdkClient = sdkClient + s.NoError(err) } func (s *VersioningIntegSuite) TearDownTest() { diff --git a/tests/workflow_buffered_events_test.go b/tests/workflow_buffered_events_test.go index 63920aeb8ff..be465dd3605 100644 --- a/tests/workflow_buffered_events_test.go +++ b/tests/workflow_buffered_events_test.go @@ -46,7 +46,7 @@ import ( ) type WorkflowBufferedEventsTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestWorkflowBufferedEventsTestSuite(t *testing.T) { diff --git a/tests/workflow_delete_execution_test.go b/tests/workflow_delete_execution_test.go index 35a06b7a6b1..ecc3f35de63 100644 --- a/tests/workflow_delete_execution_test.go +++ b/tests/workflow_delete_execution_test.go @@ -53,7 +53,7 @@ const ( ) type WorkflowDeleteExecutionSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestWorkflowDeleteExecutionSuite(t *testing.T) { diff --git a/tests/workflow_failures_test.go b/tests/workflow_failures_test.go index abe782122b1..0b9e9069db3 100644 --- a/tests/workflow_failures_test.go +++ b/tests/workflow_failures_test.go @@ -51,7 +51,7 @@ import ( ) type WorkflowFailuresTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestWorkflowFailuresTestSuite(t *testing.T) { diff --git a/tests/workflow_memo_test.go b/tests/workflow_memo_test.go index abf1b72de76..6934e6b1195 100644 --- a/tests/workflow_memo_test.go +++ b/tests/workflow_memo_test.go @@ -46,7 +46,7 @@ import ( ) type WorkflowMemoTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestWorkflowMemoTestSuite(t *testing.T) { diff --git a/tests/workflow_reset_test.go b/tests/workflow_reset_test.go index 1bf9b776666..b6a6f33bf89 100644 --- a/tests/workflow_reset_test.go +++ b/tests/workflow_reset_test.go @@ -45,7 +45,7 @@ import ( // Tests workflow reset feature type WorkflowResetSuite struct { - testcore.ClientFunctionalSuite + testcore.FunctionalTestSdkSuite } func TestWorkflowResetTestSuite(t *testing.T) { diff --git a/tests/workflow_task_test.go b/tests/workflow_task_test.go index b4a3d7bc7a0..9eb16d3bd06 100644 --- a/tests/workflow_task_test.go +++ b/tests/workflow_task_test.go @@ -42,7 +42,7 @@ import ( ) type WorkflowTaskTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestWorkflowTaskTestSuite(t *testing.T) { diff --git a/tests/workflow_test.go b/tests/workflow_test.go index 9dc2b2e2924..6d15a15daaa 100644 --- a/tests/workflow_test.go +++ b/tests/workflow_test.go @@ -56,7 +56,7 @@ import ( ) type WorkflowTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestWorkflowTestSuite(t *testing.T) { diff --git a/tests/workflow_timer_test.go b/tests/workflow_timer_test.go index 527f8e010a9..a83439dd6a1 100644 --- a/tests/workflow_timer_test.go +++ b/tests/workflow_timer_test.go @@ -42,7 +42,7 @@ import ( ) type WorkflowTimerTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestWorkflowTimerTestSuite(t *testing.T) { diff --git a/tests/workflow_visibility_test.go b/tests/workflow_visibility_test.go index 869609c95b2..cbf56aff58a 100644 --- a/tests/workflow_visibility_test.go +++ b/tests/workflow_visibility_test.go @@ -43,7 +43,7 @@ import ( ) type WorkflowVisibilityTestSuite struct { - testcore.FunctionalSuite + testcore.FunctionalTestSuite } func TestWorkflowVisibilityTestSuite(t *testing.T) { diff --git a/tests/xdc/advanced_visibility_test.go b/tests/xdc/advanced_visibility_test.go index ad36acc63db..063cd0eda50 100644 --- a/tests/xdc/advanced_visibility_test.go +++ b/tests/xdc/advanced_visibility_test.go @@ -65,6 +65,7 @@ import ( ) type AdvVisCrossDCTestSuite struct { + // TODO (alex): use FunctionalTestSuite // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, // not merely log an error *require.Assertions diff --git a/tests/xdc/base.go b/tests/xdc/base.go index b6a2591ca00..aaac17925d5 100644 --- a/tests/xdc/base.go +++ b/tests/xdc/base.go @@ -56,6 +56,7 @@ import ( type ( xdcBaseSuite struct { + // TODO (alex): use FunctionalTestSuite // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, // not merely log an error *require.Assertions @@ -88,10 +89,10 @@ func (s *xdcBaseSuite) clusterReplicationConfig() []*replicationpb.ClusterReplic return config } -func (s *xdcBaseSuite) setupSuite(clusterNames []string, opts ...testcore.Option) { +func (s *xdcBaseSuite) setupSuite(clusterNames []string, opts ...testcore.TestClusterOption) { s.testClusterFactory = testcore.NewTestClusterFactory() - params := testcore.ApplyTestClusterParams(opts) + params := testcore.ApplyTestClusterOptions(opts) s.clusterNames = clusterNames for idx, clusterName := range s.clusterNames { diff --git a/tests/xdc/failover_test.go b/tests/xdc/failover_test.go index be12250d3e2..fd71c652cbf 100644 --- a/tests/xdc/failover_test.go +++ b/tests/xdc/failover_test.go @@ -2325,16 +2325,6 @@ func (s *FunctionalClustersTestSuite) TestActivityHeartbeatFailover() { s.Equal(2, lastAttemptCount) } -// Uncomment if you need to debug history. -// func (s *funcClustersTestSuite) printHistory(frontendClient workflowservice.WorkflowServiceClient, namespace, workflowID, runID string) { -// events := s.getHistory(frontendClient, namespace, &commonpb.WorkflowExecution{ -// WorkflowId: workflowID, -// RunId: runID, -// }) -// history := &historypb.History{Events: events} -// common.PrettyPrintHistory(history, s.logger) -// } - func (s *FunctionalClustersTestSuite) TestLocalNamespaceMigration() { testCtx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel()