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

Add integration test for SignalWorkflow #235

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/internal_workflow.go
Expand Up @@ -797,7 +797,7 @@ func (c *channelImpl) assignValue(from interface{}, to interface{}) error {
err := decodeAndAssignValue(c.dataConverter, from, to)
// add to metrics
if err != nil {
c.env.GetLogger().Error(fmt.Sprintf("Corrupt signal received on channel %s. Error deserializing", c.name), tagError, err)
c.env.GetLogger().Error(fmt.Sprintf("Deserialization error. Corrupted signal received on channel %s.", c.name), tagError, err)
c.env.GetMetricsScope().Counter(metrics.CorruptedSignalsCounter).Inc(1)
}
return err
Expand Down Expand Up @@ -1239,7 +1239,7 @@ func (w *WorkflowOptions) getSignalChannel(ctx Context, signalName string) Recei
if ch, ok := w.signalChannels[signalName]; ok {
return ch
}
ch := NewBufferedChannel(ctx, defaultSignalChannelSize)
ch := NewNamedBufferedChannel(ctx, signalName, defaultSignalChannelSize)
Copy link
Member Author

Choose a reason for hiding this comment

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

I hope there are no side effects for this change. name is used for error message and it would be great to see something meaningful there rather then empty string.

w.signalChannels[signalName] = ch
return ch
}
Expand Down
21 changes: 21 additions & 0 deletions test/integration_test.go
Expand Up @@ -36,6 +36,7 @@ import (
"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"
"go.temporal.io/api/serviceerror"
workflowpb "go.temporal.io/api/workflow/v1"
Expand Down Expand Up @@ -303,6 +304,26 @@ func (ts *IntegrationTestSuite) TestConsistentQuery() {
ts.Equal("signal-input", queryResult)
}

func (ts *IntegrationTestSuite) TestSignalWorkflow() {
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout)
defer cancel()

wfOpts := ts.startWorkflowOptions("test-signal-workflow")
run, err := ts.client.ExecuteWorkflow(ctx, wfOpts, ts.workflows.SignalWorkflow)
ts.Nil(err)
err = ts.client.SignalWorkflow(ctx, "test-signal-workflow", run.GetRunID(), "string-signal", "string-value")
ts.NoError(err)

wt := &commonpb.WorkflowType{Name: "workflow-type"}
err = ts.client.SignalWorkflow(ctx, "test-signal-workflow", run.GetRunID(), "proto-signal", wt)
ts.NoError(err)

var protoValue *commonpb.WorkflowType
err = run.Get(ctx, &protoValue)
ts.NoError(err)
ts.Equal(commonpb.WorkflowType{Name: "string-value"}, *protoValue)
}

func (ts *IntegrationTestSuite) TestWorkflowIDReuseRejectDuplicate() {
var result string
err := ts.executeWorkflow(
Expand Down
26 changes: 26 additions & 0 deletions test/workflow_test.go
Expand Up @@ -31,6 +31,7 @@ import (
"strconv"
"time"

commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"

"go.temporal.io/sdk/converter"
Expand Down Expand Up @@ -543,6 +544,30 @@ func (w *Workflows) ConsistentQueryWorkflow(ctx workflow.Context, delay time.Dur
return nil
}

func (w *Workflows) SignalWorkflow(ctx workflow.Context) (*commonpb.WorkflowType, error) {
s := workflow.NewSelector(ctx)

stringSignalChan := workflow.GetSignalChannel(ctx, "string-signal")
var stringSignalValue string
s.AddReceive(stringSignalChan, func(c workflow.ReceiveChannel, more bool) {
c.Receive(ctx, &stringSignalValue)
workflow.GetLogger(ctx).Info("Received signal", "signal", "string-signal", "value", stringSignalValue)
})
s.Select(ctx)

protoSignalChan := workflow.GetSignalChannel(ctx, "proto-signal")
var protoSignalValue *commonpb.WorkflowType
s.AddReceive(protoSignalChan, func(c workflow.ReceiveChannel, more bool) {
c.Receive(ctx, &protoSignalValue)
workflow.GetLogger(ctx).Info("Received signal", "signal", "proto-signal", "value", protoSignalValue)
})
s.Select(ctx)

protoSignalValue.Name = stringSignalValue

return protoSignalValue, nil
}

func (w *Workflows) RetryTimeoutStableErrorWorkflow(ctx workflow.Context) ([]string, error) {
ao := workflow.ActivityOptions{
ScheduleToStartTimeout: 1 * time.Second,
Expand Down Expand Up @@ -865,6 +890,7 @@ func (w *Workflows) register(worker worker.Worker) {
worker.RegisterWorkflow(w.WorkflowWithParallelLocalActivities)
worker.RegisterWorkflow(w.WorkflowWithParallelSideEffects)
worker.RegisterWorkflow(w.WorkflowWithParallelMutableSideEffects)
worker.RegisterWorkflow(w.SignalWorkflow)

worker.RegisterWorkflow(w.child)
worker.RegisterWorkflow(w.childForMemoAndSearchAttr)
Expand Down