diff --git a/src/network/requestQueue/index.js b/src/network/requestQueue/index.js index eee14d66c..988b1c459 100644 --- a/src/network/requestQueue/index.js +++ b/src/network/requestQueue/index.js @@ -294,7 +294,9 @@ module.exports = class RequestQueue extends EventEmitter { this[PRIVATE.EMIT_QUEUE_SIZE_EVENT]() } + // if (this.pending.length) { this.scheduleCheckPendingRequests() + // } } /** diff --git a/src/network/requestQueue/index.spec.js b/src/network/requestQueue/index.spec.js index 238fbf310..265e7de77 100644 --- a/src/network/requestQueue/index.spec.js +++ b/src/network/requestQueue/index.spec.js @@ -269,6 +269,21 @@ describe('Network > RequestQueue', () => { expect(request.entry.resolve).toHaveBeenCalledWith(expect.objectContaining({ size, payload })) }) + it('does not start checking for pending requests needlessly (in an infinite loop)', async () => { + const checkPendingRequests = jest.spyOn(requestQueue, 'checkPendingRequests') + + // fulfill request is called as soon as the connection starts, so + // this emulates the beginning of a successful connection to the cluster + requestQueue.fulfillRequest({ + correlationId: request.entry.correlationId, + payload, + size, + }) + + await sleep(1000) + expect(checkPendingRequests).toHaveBeenCalledTimes(1) + }) + describe('when there are pending requests', () => { beforeEach(() => { while (requestQueue.inflight.size < requestQueue.maxInFlightRequests) {