Skip to content

Commit

Permalink
fix(zeebe): fix waitForReady deadline (#151)
Browse files Browse the repository at this point in the history
This fixes a bug in the grpc channel connection sensing

fixes #150
  • Loading branch information
jwulf authored May 6, 2024
1 parent d1df3d3 commit a88ea2e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ test('Calls the onConnectionError handler if there is no broker and eagerConnect
}, 7000)
}))

test('Sets connected:false if there is no broker and no setting of eagerConnection', () =>
test('Sets connected:undefined if there is no broker and no setting of eagerConnection', () =>
new Promise((done) => {
const zbc2 = new ZeebeGrpcClient({
config: { ZEEBE_ADDRESS: 'localtoast: 267890' },
}) // Broker doesn't exist!!!
setTimeout(async () => {
expect(zbc2.connected).toBe(false)
expect(zbc2.connected).toBe(undefined)
await zbc2.close()
done(null)
}, 5000)
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/zeebe/integration/Client-onReady.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('Does not call the onReady handler if there is no broker', (done) => {
}, 4000)
})

test('Does call the onReady handler if there is a broker and eagerConnection is true', (done) => {
test('Calls the onReady handler if there is a broker and eagerConnection is true', (done) => {
let called = 0
const zbc2 = new ZeebeGrpcClient({
config: { zeebeGrpcSettings: { ZEEBE_GRPC_CLIENT_EAGER_CONNECT: true } },
Expand All @@ -35,7 +35,7 @@ test('Does call the onReady handler if there is a broker and eagerConnection is
}, 6000)
})

test('Does set connected to true if there is a broker', (done) => {
test('Sets connected to true if there is a broker', (done) => {
const zbc2 = new ZeebeGrpcClient({
config: { zeebeGrpcSettings: { ZEEBE_GRPC_CLIENT_EAGER_CONNECT: true } },
})
Expand All @@ -47,7 +47,7 @@ test('Does set connected to true if there is a broker', (done) => {
}, 6000)
})

test('Does emit the ready event if there is a broker and eagerConnection: true', (done) => {
test('emits the ready event if there is a broker and eagerConnection: true', (done) => {
let called = 0
const zbc2 = new ZeebeGrpcClient({
config: { zeebeGrpcSettings: { ZEEBE_GRPC_CLIENT_EAGER_CONNECT: true } },
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/zeebe/integration/Worker-onReady.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ test('Does set connected: true if there is a broker and eagerConnection: true',
}, 7000)
})

test('Does not set connected: true if there is a broker and eagerConnection: false', (done) => {
test('Sets connected: true if there is a broker and eagerConnection: false', (done) => {
const zbc2 = new ZeebeGrpcClient()
setTimeout(async () => {
expect(zbc2.connected).toBe(false)
expect(zbc2.connected).toBe(true)
await zbc2.close()
done()
}, 7000)
Expand Down
3 changes: 2 additions & 1 deletion src/zeebe/lib/GrpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ export class GrpcClient extends EventEmitter {
})
this.listNameMethods = []

this.client.waitForReady(10000, (error) =>
// See https://github.com/camunda/camunda-8-js-sdk/issues/150
this.client.waitForReady(new Date(Date.now() + 10000), (error) =>
error
? this.emit(MiddlewareSignals.Event.Error, error)
: this.emit(MiddlewareSignals.Event.Ready)
Expand Down

0 comments on commit a88ea2e

Please sign in to comment.