Skip to content

Commit ba36895

Browse files
akkieberndverst
andauthored
Migrate Zeebe tests to certification tests (#3112)
Signed-off-by: Christian Kaps <[email protected]> Signed-off-by: Bernd Verst <[email protected]> Co-authored-by: Bernd Verst <[email protected]>
1 parent 0c2ce32 commit ba36895

File tree

78 files changed

+4100
-1933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4100
-1933
lines changed

.github/scripts/test-info.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ const components = {
120120
'bindings.dubbo': {
121121
certification: true,
122122
},
123+
'bindings.zeebe.command': {
124+
certification: true,
125+
},
126+
'bindings.zeebe.jobworker': {
127+
certification: true,
128+
},
123129
'bindings.http': {
124130
conformance: true,
125131
},

Makefile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,4 @@ prettier-format:
249249
################################################################################
250250
.PHONY: conf-tests
251251
conf-tests:
252-
CGO_ENABLED=$(CGO) go test -v -tags=conftests -count=1 ./tests/conformance
253-
254-
################################################################################
255-
# Target: e2e #
256-
################################################################################
257-
include tests/e2e/e2e_tests.mk
252+
CGO_ENABLED=$(CGO) go test -v -tags=conftests -count=1 ./tests/conformance

bindings/zeebe/command/activate_jobs.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"fmt"
2121
"time"
2222

23+
"github.com/camunda/zeebe/clients/go/v8/pkg/entities"
24+
2325
"github.com/dapr/components-contrib/bindings"
2426
"github.com/dapr/components-contrib/metadata"
2527
)
@@ -35,6 +37,7 @@ type activateJobsPayload struct {
3537
Timeout metadata.Duration `json:"timeout"`
3638
WorkerName string `json:"workerName"`
3739
FetchVariables []string `json:"fetchVariables"`
40+
RequestTimeout metadata.Duration `json:"requestTimeout"`
3841
}
3942

4043
func (z *ZeebeCommand) activateJobs(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) {
@@ -68,7 +71,15 @@ func (z *ZeebeCommand) activateJobs(ctx context.Context, req *bindings.InvokeReq
6871
cmd = cmd.FetchVariables(payload.FetchVariables...)
6972
}
7073

71-
response, err := cmd.Send(ctx)
74+
var response []entities.Job
75+
if payload.RequestTimeout.Duration != time.Duration(0) {
76+
ctxWithTimeout, cancel := context.WithTimeout(ctx, payload.RequestTimeout.Duration)
77+
defer cancel()
78+
response, err = cmd.Send(ctxWithTimeout)
79+
} else {
80+
response, err = cmd.Send(ctx)
81+
}
82+
7283
if err != nil {
7384
return nil, fmt.Errorf("cannot activate jobs for type %s: %w", payload.JobType, err)
7485
}

bindings/zeebe/command/command.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import (
3030
const (
3131
// operations.
3232
TopologyOperation bindings.OperationKind = "topology"
33-
DeployProcessOperation bindings.OperationKind = "deploy-process"
33+
DeployResourceOperation bindings.OperationKind = "deploy-resource"
34+
DeployProcessOperation bindings.OperationKind = "deploy-process" // Deprecated, kept for backward compatibility
3435
CreateInstanceOperation bindings.OperationKind = "create-instance"
3536
CancelInstanceOperation bindings.OperationKind = "cancel-instance"
3637
SetVariablesOperation bindings.OperationKind = "set-variables"
@@ -78,6 +79,7 @@ func (z *ZeebeCommand) Operations() []bindings.OperationKind {
7879
return []bindings.OperationKind{
7980
TopologyOperation,
8081
DeployProcessOperation,
82+
DeployResourceOperation,
8183
CreateInstanceOperation,
8284
CancelInstanceOperation,
8385
SetVariablesOperation,
@@ -95,8 +97,8 @@ func (z *ZeebeCommand) Invoke(ctx context.Context, req *bindings.InvokeRequest)
9597
switch req.Operation {
9698
case TopologyOperation:
9799
return z.topology(ctx)
98-
case DeployProcessOperation:
99-
return z.deployProcess(ctx, req)
100+
case DeployResourceOperation, DeployProcessOperation:
101+
return z.deployResource(ctx, req)
100102
case CreateInstanceOperation:
101103
return z.createInstance(ctx, req)
102104
case CancelInstanceOperation:

bindings/zeebe/command/command_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,18 @@ func TestInvoke(t *testing.T) {
9393
func TestOperations(t *testing.T) {
9494
testBinding := ZeebeCommand{logger: logger.NewLogger("test")}
9595
operations := testBinding.Operations()
96-
require.Equal(t, 12, len(operations))
96+
require.Equal(t, 13, len(operations))
9797
assert.Equal(t, TopologyOperation, operations[0])
9898
assert.Equal(t, DeployProcessOperation, operations[1])
99-
assert.Equal(t, CreateInstanceOperation, operations[2])
100-
assert.Equal(t, CancelInstanceOperation, operations[3])
101-
assert.Equal(t, SetVariablesOperation, operations[4])
102-
assert.Equal(t, ResolveIncidentOperation, operations[5])
103-
assert.Equal(t, PublishMessageOperation, operations[6])
104-
assert.Equal(t, ActivateJobsOperation, operations[7])
105-
assert.Equal(t, CompleteJobOperation, operations[8])
106-
assert.Equal(t, FailJobOperation, operations[9])
107-
assert.Equal(t, UpdateJobRetriesOperation, operations[10])
108-
assert.Equal(t, ThrowErrorOperation, operations[11])
99+
assert.Equal(t, DeployResourceOperation, operations[2])
100+
assert.Equal(t, CreateInstanceOperation, operations[3])
101+
assert.Equal(t, CancelInstanceOperation, operations[4])
102+
assert.Equal(t, SetVariablesOperation, operations[5])
103+
assert.Equal(t, ResolveIncidentOperation, operations[6])
104+
assert.Equal(t, PublishMessageOperation, operations[7])
105+
assert.Equal(t, ActivateJobsOperation, operations[8])
106+
assert.Equal(t, CompleteJobOperation, operations[9])
107+
assert.Equal(t, FailJobOperation, operations[10])
108+
assert.Equal(t, UpdateJobRetriesOperation, operations[11])
109+
assert.Equal(t, ThrowErrorOperation, operations[12])
109110
}

bindings/zeebe/command/create_instance.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import (
1818
"encoding/json"
1919
"errors"
2020
"fmt"
21+
"time"
2122

2223
"github.com/camunda/zeebe/clients/go/v8/pkg/commands"
2324

2425
"github.com/dapr/components-contrib/bindings"
26+
"github.com/dapr/components-contrib/metadata"
2527
)
2628

2729
var (
@@ -30,10 +32,13 @@ var (
3032
)
3133

3234
type createInstancePayload struct {
33-
BpmnProcessID string `json:"bpmnProcessId"`
34-
ProcessDefinitionKey *int64 `json:"processDefinitionKey"`
35-
Version *int32 `json:"version"`
36-
Variables interface{} `json:"variables"`
35+
BpmnProcessID string `json:"bpmnProcessId"`
36+
ProcessDefinitionKey *int64 `json:"processDefinitionKey"`
37+
Version *int32 `json:"version"`
38+
Variables interface{} `json:"variables"`
39+
WithResult bool `json:"withResult"`
40+
FetchVariables []string `json:"fetchVariables"`
41+
RequestTimeout metadata.Duration `json:"requestTimeout"`
3742
}
3843

3944
func (z *ZeebeCommand) createInstance(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) {
@@ -75,9 +80,25 @@ func (z *ZeebeCommand) createInstance(ctx context.Context, req *bindings.InvokeR
7580
}
7681
}
7782

78-
response, err := cmd3.Send(ctx)
83+
var response interface{}
84+
// The request timeout has only an affect if WithResult is used. Using WithResult means that the operation is
85+
// synchronous instead of asynchronous, and the request timeout defines how long the client should wait for the
86+
// workflow/process to finish to get the result.
87+
//
88+
// From a code perspective, there are two Send methods in the Zeebe client. One if WithResult was used and
89+
// which extracts the request timeout from the context and another one which will not use any timeout.
90+
if payload.WithResult && payload.RequestTimeout.Duration != time.Duration(0) {
91+
ctxWithTimeout, cancel := context.WithTimeout(ctx, payload.RequestTimeout.Duration)
92+
defer cancel()
93+
response, err = cmd3.WithResult().FetchVariables(payload.FetchVariables...).Send(ctxWithTimeout)
94+
} else if payload.WithResult {
95+
response, err = cmd3.WithResult().FetchVariables(payload.FetchVariables...).Send(ctx)
96+
} else {
97+
response, err = cmd3.Send(ctx)
98+
}
99+
79100
if err != nil {
80-
return nil, fmt.Errorf("cannot create instane for %s: %w", errorDetail, err)
101+
return nil, fmt.Errorf("cannot create instance for %s: %w", errorDetail, err)
81102
}
82103

83104
jsonResponse, err := json.Marshal(response)

bindings/zeebe/command/deploy_process.go renamed to bindings/zeebe/command/deploy_resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929

3030
var ErrMissingFileName = errors.New("fileName is a required attribute")
3131

32-
func (z *ZeebeCommand) deployProcess(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) {
32+
func (z *ZeebeCommand) deployResource(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) {
3333
var deployFileName string
3434

3535
if val, ok := req.Metadata[fileName]; ok && val != "" {
@@ -42,7 +42,7 @@ func (z *ZeebeCommand) deployProcess(ctx context.Context, req *bindings.InvokeRe
4242
AddResource(req.Data, deployFileName).
4343
Send(ctx)
4444
if err != nil {
45-
return nil, fmt.Errorf("cannot deploy process with fileName %s: %w", deployFileName, err)
45+
return nil, fmt.Errorf("cannot deploy resource with fileName %s: %w", deployFileName, err)
4646
}
4747

4848
jsonResponse, err := json.Marshal(response)

bindings/zeebe/command/deploy_process_test.go renamed to bindings/zeebe/command/deploy_resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import (
2323
"github.com/dapr/kit/logger"
2424
)
2525

26-
func TestDeployProcess(t *testing.T) {
26+
func TestDeployResource(t *testing.T) {
2727
testLogger := logger.NewLogger("test")
2828

2929
t.Run("fileName is mandatory", func(t *testing.T) {
3030
cmd := ZeebeCommand{logger: testLogger}
31-
req := &bindings.InvokeRequest{Operation: DeployProcessOperation}
31+
req := &bindings.InvokeRequest{Operation: DeployResourceOperation}
3232
_, err := cmd.Invoke(context.TODO(), req)
3333
assert.Error(t, err, ErrMissingFileName)
3434
})

bindings/zeebe/command/fail_job.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@ import (
1818
"encoding/json"
1919
"errors"
2020
"fmt"
21+
"time"
22+
23+
"github.com/camunda/zeebe/clients/go/v8/pkg/commands"
2124

2225
"github.com/dapr/components-contrib/bindings"
26+
"github.com/dapr/components-contrib/metadata"
2327
)
2428

2529
var ErrMissingRetries = errors.New("retries is a required attribute")
2630

2731
type failJobPayload struct {
28-
JobKey *int64 `json:"jobKey"`
29-
Retries *int32 `json:"retries"`
30-
ErrorMessage string `json:"errorMessage"`
32+
JobKey *int64 `json:"jobKey"`
33+
Retries *int32 `json:"retries"`
34+
ErrorMessage string `json:"errorMessage"`
35+
RetryBackOff metadata.Duration `json:"retryBackOff"`
36+
Variables interface{} `json:"variables"`
3137
}
3238

3339
func (z *ZeebeCommand) failJob(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) {
@@ -53,7 +59,19 @@ func (z *ZeebeCommand) failJob(ctx context.Context, req *bindings.InvokeRequest)
5359
cmd = cmd.ErrorMessage(payload.ErrorMessage)
5460
}
5561

56-
_, err = cmd.Send(ctx)
62+
if payload.RetryBackOff.Duration != time.Duration(0) {
63+
cmd = cmd.RetryBackoff(payload.RetryBackOff.Duration)
64+
}
65+
66+
var cmdDispatch commands.DispatchFailJobCommand = cmd
67+
if payload.Variables != nil {
68+
cmdDispatch, err = cmd.VariablesFromObject(payload.Variables)
69+
if err != nil {
70+
return nil, err
71+
}
72+
}
73+
74+
_, err = cmdDispatch.Send(ctx)
5775
if err != nil {
5876
return nil, fmt.Errorf("cannot fail job for key %d: %w", payload.JobKey, err)
5977
}

bindings/zeebe/command/metadata.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ binding:
1515
- name: topology
1616
description: "Obtains the current topology of the cluster the gateway is part of."
1717
- name: deploy-process
18-
description: "Deploys a single process to Zeebe."
18+
description: "Deprecated alias of 'deploy-resource'."
19+
- name: deploy-resource
20+
description: "Deploys a single resource to Zeebe."
1921
- name: create-instance
2022
description: "Creates and starts an instance of the specified process."
2123
- name: cancel-instance

0 commit comments

Comments
 (0)