Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Fix tests for Camunda Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed Jun 15, 2020
1 parent 066db16 commit 2a8635b
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 190 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ docs
cctest.ts
t.ts
yolo.bpmn
crash-*.log
crash-*.log
camunda-cloud.env
19 changes: 10 additions & 9 deletions example/start-workflow-instance.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// const ZB = require('zeebe-node');
const ZB = require('../dist');
const ZB = require('../dist')

const jobs =
(async () => {
const zbc = new ZB.ZBClient("localhost:26500");
for (let i = 0; i < 10; i++) {
const result = await zbc.createWorkflowInstance("test-process", { testData: "something" });
console.log(result);
}
})();
const jobs = (async () => {
const zbc = new ZB.ZBClient()
for (let i = 0; i < 10; i++) {
const result = await zbc.createWorkflowInstance('test-process', {
testData: 'something',
})
console.log(result)
}
})()
268 changes: 134 additions & 134 deletions example/test.bpmn

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions example/workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
const ZB = require('../dist')

;(async () => {
const zbc = new ZB.ZBClient()

const zbc = new ZB.ZBClient({
onConnectionError: err => console.log('err', err),
onReady: () => console.log('YOO'),
})
const topology = await zbc.topology()
console.log(JSON.stringify(topology, null, 2))

let workflows = await zbc.listWorkflows()
console.log(workflows)

await zbc.deployWorkflow('./test.bpmn')

workflows = await zbc.listWorkflows()
console.log(workflows)
const res = await zbc.deployWorkflow('./test.bpmn')
setTimeout(() => console.log(res), 5000)
})()
23 changes: 9 additions & 14 deletions src/__tests__/integration/Worker-onReady.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@ import { ZBClient } from '../..'
jest.setTimeout(30000)
process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'

test(`Does call the onReady handler if there is a broker`, done => {
test(`Worker calls the onReady handler if there is a broker`, done => {
let called = 0
const zbc2 = new ZBClient()
zbc2.createWorker(
null,
'nonsense-task',
(_, complete) => complete.success,
{
onReady: () => {
called++
},
}
)
zbc2.createWorker('nonsense-task', (_, complete) => complete.success, {
onReady: () => {
called++
},
})
setTimeout(async () => {
expect(called).toBe(1)
await zbc2.close()
done()
}, 6000)
}, 10000)
})

test(`Does set connected: true if there is a broker and eagerConnection: true`, done => {
Expand All @@ -31,7 +26,7 @@ test(`Does set connected: true if there is a broker and eagerConnection: true`,
expect(zbc2.connected).toBe(true)
await zbc2.close()
done()
}, 6000)
}, 7000)
})

test(`Does not set connected: true if there is a broker and eagerConnection: false`, done => {
Expand All @@ -40,7 +35,7 @@ test(`Does not set connected: true if there is a broker and eagerConnection: fal
expect(zbc2.connected).toBe(undefined)
await zbc2.close()
done()
}, 6000)
}, 7000)
})

test(`Does emit the ready event if there is a broker`, done => {
Expand Down
42 changes: 23 additions & 19 deletions src/__tests__/local-integration/OnConnectionError.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,69 @@ jest.setTimeout(16000)
process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'

test(`Calls the onConnectionError handler if there is no broker and eagerConnection:true`, async done => {
let called = 0
let calledA = 0
const zbc2 = new ZBClient('localtoast: 267890', {
eagerConnection: true,
onConnectionError: () => {
called++
calledA++
},
})
setTimeout(async () => {
expect(called).toBe(1)
expect(calledA).toBe(1)
await zbc2.close()
done()
}, 5000)
})

test(`Does not call the onConnectionError handler if there is a broker`, async done => {
let called = 0
let calledB = 0
const zbc2 = new ZBClient({
onConnectionError: () => {
called++
// tslint:disable-next-line: no-debugger
debugger
calledB++
// tslint:disable-next-line: no-console
console.log('ERROR')
},
})
setTimeout(async () => {
expect(called).toBe(0)
expect(calledB).toBe(0)
await zbc2.close()
done()
}, 5000)
})

test(`Calls ZBClient onConnectionError once when there is no broker, eagerConnection:true, and workers with no handler`, async done => {
let called = 0
let calledC = 0
const zbc2 = new ZBClient('localtoast:234532534', {
eagerConnection: true,
onConnectionError: () => {
called++
calledC++
},
})
zbc2.createWorker(null, 'whatever', (_, complete) => complete.success)
zbc2.createWorker(null, 'whatever', (_, complete) => complete.success)
setTimeout(() => {
zbc2.close()
expect(called).toBe(1)
expect(calledC).toBe(1)
done()
}, 10000)
})

test(`Calls ZBClient onConnectionError when there no broker, for the client and each worker with a handler`, async done => {
let called = 0
let calledD = 0
const zbc2 = new ZBClient('localtoast:234532534', {
onConnectionError: () => {
called++
calledD++
},
})
zbc2.createWorker('whatever', (_, complete) => complete.success, {
onConnectionError: () => called++,
onConnectionError: () => calledD++,
})
// @TOFIX - debouncing
setTimeout(() => {
zbc2.close()
expect(called).toBe(4) // Should be 2 if it is debounced
expect(calledD).toBe(4) // Should be 2 if it is debounced
done()
}, 10000)
})
Expand All @@ -86,33 +90,33 @@ test(`Debounces onConnectionError`, async done => {
})

test(`Trailing parameter worker onConnectionError handler API works`, async done => {
let called = 0
let calledE = 0
const zbc2 = new ZBClient('localtoast:234532534', {})
zbc2.createWorker('whatever', (_, complete) => complete.success, {
onConnectionError: () => called++,
onConnectionError: () => calledE++,
})
// @TOFIX - debouncing
setTimeout(async () => {
await zbc2.close()
expect(called).toBe(4) // should be 1 if debounced
expect(calledE).toBe(4) // should be 1 if debounced
done()
}, 10000)
})

test(`Does not call the onConnectionError handler if there is a business error`, async done => {
let called = 0
let calledF = 0
let wf = 'arstsrasrateiuhrastulyharsntharsie'
const zbc2 = new ZBClient({
onConnectionError: () => {
called++
calledF++
},
})
zbc2.createWorkflowInstance(wf, {}).catch(() => {
wf = 'throw error away'
})
setTimeout(async () => {
expect(zbc2.connected).toBe(true)
expect(called).toBe(0)
expect(calledF).toBe(0)
await zbc2.close()
done()
}, 10000)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ConnectionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const ConnectionCharacteristics: {
CAMUNDA_CLOUD: {
_tag: 'CAMUNDA_CLOUD',
startupTime: parseInt(
process.env.ZEEBE_INITIAL_CONNECTION_TOLERANCE || '5000',
process.env.ZEEBE_INITIAL_CONNECTION_TOLERANCE || '6000',
10
),
},
Expand All @@ -28,7 +28,7 @@ export const ConnectionCharacteristics: {
},
}

export type State = 'ERROR' | 'CONNECTED'
export type State = 'ERROR' | 'CONNECTED' | 'UNKNOWN'

export class ConnectionFactory {
public static getGrpcClient({
Expand Down
6 changes: 4 additions & 2 deletions src/lib/GrpcMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ export class GrpcMiddleware {
}) {
this.characteristics = characteristics
this.blocking = this.characteristics.startupTime > 0
this.state = this.blocking ? 'ERROR' : 'CONNECTED'
this.state = 'UNKNOWN'
log.logDebug(`Grpc Middleware blocking: ${this.blocking}`)
if (this.blocking) {
setTimeout(() => {
this.blocking = false
log.logDebug(`Grpc Middleware state: ${this.state}`)
if (this.state === 'ERROR') {
this.emitError()
} else {
} else if (this.state === 'CONNECTED') {
this.emitReady()
} else if (this.state === 'UNKNOWN') {
this.grpcClient.emit(ConnectionStatusEvent.Unknown)
}
}, this.characteristics.startupTime)
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/ZBWorkerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class ZBWorkerBase<
this.connected = true
}
}
this.grpcClient.on(ConnectionStatusEvent.Unknown, onReady)
this.grpcClient.on(ConnectionStatusEvent.Ready, onReady)
this.cancelWorkflowOnException =
options.failWorkflowOnException || false
Expand Down
1 change: 1 addition & 0 deletions src/zb/ZBClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const idColors = [
export const ConnectionStatusEvent = {
ConnectionError: 'connectionError' as 'connectionError',
Ready: 'ready' as 'ready',
Unknown: 'unknown' as 'unknown',
}

export class ZBClient extends EventEmitter {
Expand Down

0 comments on commit 2a8635b

Please sign in to comment.