Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanos committed May 8, 2024
1 parent 5b680f6 commit 096a1b7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
38 changes: 30 additions & 8 deletions temporalcli/commands.workflow_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package temporalcli_test

import (
"context"
"encoding/json"
"fmt"
"math/rand"
"strconv"
"sync"
"time"

"github.com/google/uuid"
"go.temporal.io/api/enums/v1"
"go.temporal.io/api/history/v1"
"go.temporal.io/api/workflowservice/v1"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/workflow"
"google.golang.org/grpc"
)

func (s *SharedServerSuite) TestWorkflow_Signal_SingleWorkflowSuccess() {
Expand Down Expand Up @@ -277,9 +279,9 @@ func (s *SharedServerSuite) TestWorkflow_Terminate_BatchWorkflow_Ratelimit_Missi
}

func (s *SharedServerSuite) TestWorkflow_Terminate_BatchWorkflowSuccess_Ratelimit() {
events, _ := s.testTerminateBatchWorkflow(2, 1, false)
delay := events[1].EventTime.AsTime().Sub(events[0].EventTime.AsTime()).Abs()
s.InDelta(delay, 1*time.Second, float64(100*time.Millisecond))
var rps float32 = 1
req, _ := s.testTerminateBatchWorkflow(2, rps, false)
s.Equal(rps, req.MaxOperationsPerSecond)
}

func (s *SharedServerSuite) TestWorkflow_Terminate_BatchWorkflowSuccess_JSON() {
Expand All @@ -289,12 +291,34 @@ func (s *SharedServerSuite) TestWorkflow_Terminate_BatchWorkflowSuccess_JSON() {
s.NotEmpty(jsonRes["batchJobId"])
}

func (s *SharedServerSuite) testTerminateBatchWorkflow(total int, rps float32, json bool) ([]*history.HistoryEvent, *CommandResult) {
func (s *SharedServerSuite) testTerminateBatchWorkflow(
total int,
rps float32,
json bool,
) (*workflowservice.StartBatchOperationRequest, *CommandResult) {
s.Worker().OnDevWorkflow(func(ctx workflow.Context, a any) (any, error) {
ctx.Done().Receive(ctx, nil)
return nil, ctx.Err()
})

var lastRequestLock sync.Mutex
var startBatchRequest *workflowservice.StartBatchOperationRequest
s.CommandHarness.Options.AdditionalClientGRPCDialOptions = append(
s.CommandHarness.Options.AdditionalClientGRPCDialOptions,
grpc.WithChainUnaryInterceptor(func(
ctx context.Context,
method string, req, reply any,
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption,
) error {
lastRequestLock.Lock()
if r, ok := req.(*workflowservice.StartBatchOperationRequest); ok {
startBatchRequest = r
}
lastRequestLock.Unlock()
return invoker(ctx, method, req, reply, cc, opts...)
}),
)

// Start workflows
runs := make([]client.WorkflowRun, total)
searchAttr := "keyword-" + uuid.NewString()
Expand Down Expand Up @@ -338,7 +362,6 @@ func (s *SharedServerSuite) testTerminateBatchWorkflow(total int, rps float32, j
s.NoError(res.Err)

// Confirm that all workflows are terminated
var events []*history.HistoryEvent
for _, run := range runs {
s.Contains(run.Get(s.Context, nil).Error(), "terminated")
// Ensure the termination reason was recorded
Expand All @@ -350,12 +373,11 @@ func (s *SharedServerSuite) testTerminateBatchWorkflow(total int, rps float32, j
if term := event.GetWorkflowExecutionTerminatedEventAttributes(); term != nil {
foundReason = true
s.Equal("terminate-test", term.Reason)
events = append(events, event)
}
}
s.True(foundReason)
}
return events, res
return startBatchRequest, res
}

func (s *SharedServerSuite) TestWorkflow_Cancel_SingleWorkflowSuccess() {
Expand Down
2 changes: 1 addition & 1 deletion temporalcli/commandsmd/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This document has a specific structure used by a parser. Here are the rules:
* Can have bullets
* Each bullet is `* <option-names> (<data-type>) - <short-description>. <extra-attributes>`.
* `<option-names>` is `` `--<option-name>` `` and can optionally be followed by ``, `-<short-name>` ``.
* `<data-type>` must be one of `bool`, `duration`, `int`, `string`, `string[]`, `string-enum`, `timestamp`, TODO: more
* `<data-type>` must be one of `bool`, `duration`, `int`, `string`, `string[]`, `string-enum`, `timestamp`, `float`
* `<short-description>` can be just about anything so long as it doesn't match trailing attributes. Any wrap
around to newlines + two-space indention is trimmed to a single space.
* `<extra-attributes>` can be:
Expand Down

0 comments on commit 096a1b7

Please # to comment.