Fixed queue bug and wrote tests

This commit is contained in:
Michael Schmatz 2014-01-25 10:10:03 -08:00
parent 6f2461c8be
commit 45634e9413
2 changed files with 14 additions and 7 deletions

View file

@ -99,7 +99,7 @@ class MongoQueueClient
###Public API###
registerQueue: (queueName, options, callback) ->
newQueue = new MongoQueue queueName,options,this
newQueue = new MongoQueue queueName,options,@messageModel
callback(null, newQueue)
###Public API###
@ -107,7 +107,7 @@ class MongoQueueClient
@databaseAddress = db.generateDatabaseAddress()
@mongoDatabaseName = config.mongoQueue.queueDatabaseName;
createMongoConnection: ->
createMongoConnection: ->
@mongooseConnection = mongoose.createConnection "mongodb://#{@databaseAddress}/#{@mongoDatabaseName}"
@mongooseConnection.on 'error', ->
winston.error "There was an error connecting to the queue in MongoDB"
@ -126,7 +126,10 @@ class MongoQueueClient
class MongoQueue extends events.EventEmitter
constructor: (@queueName, options, @Message) ->
constructor: (queueName, options, messageModel) ->
@Message = messageModel
@queueName = queueName
subscribe: (eventName, callback) -> @on eventName, callback
unsubscribe: (eventName, callback) -> @removeListener eventName, callback
@ -156,7 +159,6 @@ class MongoQueue extends events.EventEmitter
processing: false
queue: @queueName
scheduledVisibilityTime: Date.now() + (delaySeconds * 1000)
messageToSend.save (err,data) =>
if err? then @emit 'error',err,data else @emit 'sent',err, data
callback? err,data

View file

@ -16,10 +16,15 @@ describe 'Queue', ->
beforeEach ->
config.isProduction = false
mongoQueueClient = queues.generateQueueClient()
config.isProduction = true
sqsQueueClient = queues.generateQueueClient()
it 'should generate the correct type of queue', ->
mongoQueueClient.registerQueue "TestQueue", {}, (err, data) ->
expect(data.constructor.name).toEqual 'MongoQueue'
describe 'sendMessage', ->
mongoQueueClient = queues.generateQueueClient()
testQueue = null
it 'should send and retrieve a message', (done) ->
mongoQueueClient.registerQueue "TestQueue", {}, (err, data) ->
testQueue = data
testQueue.sendMessage {"Body":"WOOOO"} ,0, (err2, data2) ->
done()