Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

some func tests for update activity #6869

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

some func tests for update activity #6869

wants to merge 1 commit into from

Conversation

ychebotarev
Copy link
Contributor

@ychebotarev ychebotarev commented Nov 22, 2024

What changed?

  1. Add some basic unit tests for activity update.
  2. Small bug fix.

Why?

To build some functional test coverage for the activity API

@ychebotarev ychebotarev requested a review from a team as a code owner November 22, 2024 01:50
suite.Run(t, s)
}

func (s *ActivityApiUpdateClientTestSuite) waitForChan(ctx context.Context, ch chan struct{}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be generic helper which must be used on all chan operations!

Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should run all of these tests in parallel ideally to save CI time.


var activityCompleted atomic.Int32
activityFunction := func() (string, error) {
if activityCompleted.Load() == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s.Worker().RegisterWorkflow(workflowFn)
s.Worker().RegisterActivity(activityFunction)

wfId := "functional-test-activity-update-api"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd introduce some randomness here just in case you want to be able to rerun this test without restarting the server.

Suggested change
wfId := "functional-test-activity-update-api"
wfId := testcore.RandomizeStr("wfid-"+s.T().Name())

description, err := s.SdkClient().DescribeWorkflowExecution(ctx, workflowRun.GetID(), workflowRun.GetRunID())
assert.NoError(t, err)
assert.Equal(t, 1, len(description.PendingActivities))
assert.Equal(t, int32(1), activityCompleted.Load())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check the number of attempts via DescribeWorkflowExecution so you know for sure the server got the first error?

s.NotNil(resp)

description, err := s.SdkClient().DescribeWorkflowExecution(ctx, workflowRun.GetID(), workflowRun.GetRunID())
s.NotNil(description)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can assume that describe response will not be nil and if there's an error, you'll want the test to fail with that error so we know what happened.

Suggested change
s.NotNil(description)
s.NoError(err)

s.activityRetryPolicy = &temporal.RetryPolicy{
InitialInterval: s.initialRetryInterval,
BackoffCoefficient: 1,
MaximumInterval: 10 * time.Second,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required if the coefficient is 1?

assert.Equal(t, int32(2), activityCompleted.Load())
}, 3*time.Second, 500*time.Millisecond)

description, err = s.SdkClient().DescribeWorkflowExecution(ctx, workflowRun.GetID(), workflowRun.GetRunID())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, redundant.

ActivityID: "activity-id",
DisableEagerExecution: true,
StartToCloseTimeout: s.startToCloseTimeout,
ScheduleToCloseTimeout: s.scheduleToCloseTimeout,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't set this. It doesn't give you much. You have a context deadline in the test already that will prevent it from running too long.

s.NotNil(resp)

// activity should fail immediately
s.EventuallyWithT(func(t *assert.CollectT) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, if the workflow is closed there won't be pending activities.

Comment on lines +302 to +304
s.EventuallyWithT(func(t *assert.CollectT) {
assert.Equal(t, int32(1), activityCompleted.Load())
}, 2*time.Second, 200*time.Millisecond)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would wait for the server to record the failure, it's more reliable.

WorkflowId: workflowRun.GetID(),
ActivityId: "activity-id",
ActivityOptions: &activitypb.ActivityOptions{
ScheduleToCloseTimeout: durationpb.New(5 * time.Second),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't changing anything, you already set the schedule to close timeout to 5 seconds in the beginning of this test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants