-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add passive option to queueFsm
allows for checkQueue instead of assertQueue when clients have restricted permissions fixes issue #183
- Loading branch information
Showing
4 changed files
with
122 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require('../setup.js'); | ||
var ampqQueue = require('../../src/amqp/queue'); | ||
|
||
describe('AMQP Queue', function () { | ||
let amqpChannelMock, options, topology, serializers; | ||
|
||
beforeEach(() => { | ||
amqpChannelMock = { | ||
ack: sinon.stub().callsFake(() => Promise.resolve()), | ||
nack: sinon.stub().callsFake(() => Promise.resolve()), | ||
checkQueue: sinon.stub().callsFake(() => Promise.resolve()), | ||
assertQueue: sinon.stub().callsFake(() => Promise.resolve()) | ||
}; | ||
|
||
options = { | ||
uniqueName: 'one-unique-name-coming-up' | ||
}; | ||
|
||
topology = { | ||
connection: { | ||
getChannel: sinon.stub().callsFake(() => Promise.resolve(amqpChannelMock)) | ||
} | ||
}; | ||
|
||
serializers = sinon.stub(); | ||
}); | ||
|
||
describe('when executing "define"', () => { | ||
describe('when options.passive is not set', () => { | ||
it('calls assertQueue', function () { | ||
return ampqQueue(options, topology, serializers) | ||
.then((instance) => { | ||
return instance.define(); | ||
}) | ||
.then(() => { | ||
amqpChannelMock.checkQueue.calledOnce.should.equal(false); | ||
amqpChannelMock.assertQueue.calledOnce.should.equal(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when options.passive is true', function () { | ||
it('calls checkQueue instead of assertQueue', () => { | ||
options.passive = true; | ||
return ampqQueue(options, topology, serializers) | ||
.then((instance) => { | ||
return instance.define(); | ||
}) | ||
.then(() => { | ||
amqpChannelMock.checkQueue.calledOnce.should.equal(true); | ||
amqpChannelMock.assertQueue.calledOnce.should.equal(false); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require('../setup'); | ||
const rabbit = require('../../src/index.js'); | ||
|
||
describe('Adding Queues', function () { | ||
describe('when the queue does not already exist', function () { | ||
it('should error on addQueue in passive mode', function () { | ||
return rabbit.configure({ | ||
connection: { | ||
name: 'passiveErrorWithNoQueue' | ||
} | ||
}).then(() => { | ||
return rabbit.addQueue('no-queue-here', { passive: true }, 'passiveErrorWithNoQueue') | ||
.then( | ||
() => { throw new Error('Should not have succeeded in the checkQueue call'); }, | ||
(err) => { | ||
err.toString().should.contain("Failed to create queue 'no-queue-here' on connection 'passiveErrorWithNoQueue' with 'Error: Operation failed: QueueDeclare; 404 (NOT-FOUND)"); | ||
}); | ||
}); | ||
}); | ||
after(function () { | ||
rabbit.reset(); | ||
return rabbit.shutdown('passiveErrorWithNoQueue'); | ||
}); | ||
}); | ||
|
||
describe('when the queue does exist', function () { | ||
const existingQueueName = 'totes-exists-already'; | ||
it('should NOT error on addQueue when in passive mode', function () { | ||
return rabbit.configure({ | ||
connection: { | ||
name: 'passiveEnabledWithExistingQueue' | ||
}, | ||
queues: [ | ||
{ name: existingQueueName, connection: 'passiveEnabledWithExistingQueue' } | ||
] | ||
}).then(() => { | ||
return rabbit.addQueue(existingQueueName, { passive: true }, 'passiveEnabledWithExistingQueue'); | ||
}); | ||
}); | ||
|
||
after(function () { | ||
return rabbit.deleteQueue(existingQueueName, 'passiveEnabledWithExistingQueue') | ||
.then(() => { | ||
rabbit.reset(); | ||
return rabbit.shutdown(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters