1
1
// tslint:disable-next-line: no-implicit-dependencies
2
- import { GenericContainer } from '@sitapati/testcontainers'
2
+ import { GenericContainer , Wait } from '@sitapati/testcontainers'
3
3
import { ZBClient } from '../..'
4
- // import { createUniqueTaskType } from '../../lib/createUniqueTaskType'
5
4
6
5
process . env . ZEEBE_NODE_LOG_LEVEL = process . env . ZEEBE_NODE_LOG_LEVEL || 'NONE'
7
6
@@ -14,45 +13,66 @@ let worker
14
13
15
14
afterEach ( async ( ) => {
16
15
await container ?. stop ( )
17
- await worker ?. stop ( )
16
+ await worker ?. close ( )
18
17
} )
19
18
20
19
test ( 'reconnects after a pod reschedule' , async done => {
20
+ let readyCount = 0
21
+ let errorCount = 0
21
22
const delay = timeout =>
22
23
new Promise ( res => setTimeout ( ( ) => res ( ) , timeout ) )
23
24
25
+ // tslint:disable-next-line: no-console
26
+ console . log ( '##### Starting container' ) // @DEBUG
27
+
24
28
container = await new GenericContainer (
25
29
'camunda/zeebe' ,
26
30
ZEEBE_DOCKER_TAG ,
27
31
undefined ,
28
32
26500
29
33
)
30
34
. withExposedPorts ( 26500 )
35
+ . withWaitStrategy ( Wait . forLogMessage ( 'Bootstrap Broker-0 succeeded.' ) )
31
36
. start ( )
32
37
33
38
await delay ( 10000 )
34
39
35
40
const zbc = new ZBClient ( `localhost` )
36
41
await zbc . deployWorkflow ( './src/__tests__/testdata/disconnection.bpmn' )
37
- worker = zbc . createWorker ( {
38
- taskHandler : ( _ , complete ) => {
39
- complete . success ( )
40
- } ,
41
- taskType : 'disconnection-task' ,
42
+ worker = zbc
43
+ . createWorker ( {
44
+ taskHandler : ( _ , complete ) => {
45
+ complete . success ( )
46
+ } ,
47
+ taskType : 'disconnection-task' ,
48
+ } )
49
+ . on ( 'connectionError' , ( ) => {
50
+ errorCount ++
51
+ } )
52
+ . on ( 'ready' , ( ) => {
53
+ readyCount ++
54
+ } )
55
+
56
+ // tslint:disable-next-line: no-console
57
+ console . log ( '##### Deploying workflow' ) // @DEBUG
58
+
59
+ const wf = await zbc . createWorkflowInstanceWithResult ( {
60
+ bpmnProcessId : 'disconnection' ,
61
+ requestTimeout : 25000 ,
62
+ variables : { } ,
42
63
} )
43
- const wf = await zbc . createWorkflowInstanceWithResult ( 'disconnection' , { } )
44
64
expect ( wf . bpmnProcessId ) . toBeTruthy ( )
45
65
46
66
// tslint:disable-next-line: no-console
47
- // console.log('##### Stopping container...') // @DEBUG
67
+ console . log ( '##### Stopping container...' ) // @DEBUG
48
68
49
69
await container . stop ( )
50
70
51
71
// tslint:disable-next-line: no-console
52
- // console.log('##### Container stopped.') // @DEBUG
72
+ console . log ( '##### Container stopped.' ) // @DEBUG
53
73
54
74
// tslint:disable-next-line: no-console
55
- // console.log('##### Starting container....') // @DEBUG
75
+ console . log ( '##### Starting container....' ) // @DEBUG
56
76
57
77
container = await new GenericContainer (
58
78
'camunda/zeebe' ,
@@ -61,6 +81,7 @@ test('reconnects after a pod reschedule', async done => {
61
81
26500
62
82
)
63
83
. withExposedPorts ( 26500 )
84
+ . withWaitStrategy ( Wait . forLogMessage ( 'Bootstrap Broker-0 succeeded.' ) )
64
85
. start ( )
65
86
66
87
// tslint:disable-next-line: no-console
@@ -75,20 +96,32 @@ test('reconnects after a pod reschedule', async done => {
75
96
await container . stop ( )
76
97
container = undefined
77
98
worker = undefined
99
+ expect ( readyCount ) . toBe ( 2 )
100
+ expect ( errorCount ) . toBe ( 1 )
78
101
done ( )
79
102
} )
80
103
81
104
test ( 'a worker that started first, connects to a broker that starts later' , async done => {
105
+ let readyCount = 0
106
+ let errorCount = 0
107
+
82
108
const delay = timeout =>
83
109
new Promise ( res => setTimeout ( ( ) => res ( ) , timeout ) )
84
110
85
111
const zbc = new ZBClient ( `localhost` )
86
- worker = zbc . createWorker ( {
87
- taskHandler : ( _ , complete ) => {
88
- complete . success ( )
89
- } ,
90
- taskType : 'disconnection-task' ,
91
- } )
112
+ worker = zbc
113
+ . createWorker ( {
114
+ taskHandler : ( _ , complete ) => {
115
+ complete . success ( )
116
+ } ,
117
+ taskType : 'disconnection-task' ,
118
+ } )
119
+ . on ( 'connectionError' , ( ) => {
120
+ errorCount ++
121
+ } )
122
+ . on ( 'ready' , ( ) => {
123
+ readyCount ++
124
+ } )
92
125
93
126
container = await new GenericContainer (
94
127
'camunda/zeebe' ,
@@ -97,6 +130,7 @@ test('a worker that started first, connects to a broker that starts later', asyn
97
130
26500
98
131
)
99
132
. withExposedPorts ( 26500 )
133
+ . withWaitStrategy ( Wait . forLogMessage ( 'Bootstrap Broker-0 succeeded.' ) )
100
134
. start ( )
101
135
102
136
await delay ( 10000 )
@@ -109,5 +143,7 @@ test('a worker that started first, connects to a broker that starts later', asyn
109
143
await container . stop ( )
110
144
container = undefined
111
145
worker = undefined
146
+ expect ( readyCount ) . toBe ( 1 )
147
+ expect ( errorCount ) . toBe ( 1 )
112
148
done ( )
113
149
} )
0 commit comments