mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Starting to test queue class
This commit is contained in:
parent
c00321208d
commit
6f2461c8be
2 changed files with 32 additions and 5 deletions
|
@ -12,7 +12,6 @@ queueClient = null
|
|||
simulationQueue = null
|
||||
|
||||
module.exports.setupRoutes = (app) ->
|
||||
generateQueueInstance()
|
||||
###queueClient.registerQueue "simulationQueue", {}, (err,data) ->
|
||||
simulationQueue = data
|
||||
simulationQueue.subscribe 'message', (err, data) ->
|
||||
|
@ -24,17 +23,20 @@ module.exports.setupRoutes = (app) ->
|
|||
|
||||
|
||||
|
||||
generateQueueInstance = ->
|
||||
|
||||
module.exports.generateQueueClient = ->
|
||||
if config.isProduction
|
||||
queueClient = new SQSQueueClient()
|
||||
else
|
||||
queueClient = new MongoQueueClient()
|
||||
return queueClient
|
||||
|
||||
|
||||
class SQSQueueClient extends AbstractQueueClient
|
||||
class SQSQueueClient
|
||||
constructor: ->
|
||||
@configure()
|
||||
@sqs = @generateSQSInstance()
|
||||
|
||||
###Public API###
|
||||
registerQueue: (queueName, options, callback) ->
|
||||
#returns new queue in data argument of callback
|
||||
|
@ -89,7 +91,7 @@ class SQSQueue extends events.EventEmitter
|
|||
|
||||
|
||||
|
||||
class MongoQueueClient extends AbstractQueueClient
|
||||
class MongoQueueClient
|
||||
constructor: ->
|
||||
@configure()
|
||||
@createMongoConnection()
|
||||
|
@ -155,7 +157,7 @@ class MongoQueue extends events.EventEmitter
|
|||
queue: @queueName
|
||||
scheduledVisibilityTime: Date.now() + (delaySeconds * 1000)
|
||||
|
||||
messageToSend.save (err) =>
|
||||
messageToSend.save (err,data) =>
|
||||
if err? then @emit 'error',err,data else @emit 'sent',err, data
|
||||
callback? err,data
|
||||
|
||||
|
|
25
server/queue.spec.coffee
Normal file
25
server/queue.spec.coffee
Normal file
|
@ -0,0 +1,25 @@
|
|||
queues = require './queue'
|
||||
config = require '../server_config.js'
|
||||
describe 'Queue', ->
|
||||
describe 'construction interface', ->
|
||||
it 'should construct a MongoQueueClient if not in production', ->
|
||||
config.isProduction = false
|
||||
queue = queues.generateQueueClient()
|
||||
expect(queue.constructor.name).toEqual 'MongoQueueClient'
|
||||
it 'should construct an SQSQueueClient if in production', ->
|
||||
config.isProduction = true
|
||||
queue = queues.generateQueueClient()
|
||||
expect(queue.constructor.name).toEqual 'SQSQueueClient'
|
||||
describe 'registerQueue', ->
|
||||
mongoQueueClient = null
|
||||
sqsQueueClient = null
|
||||
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'
|
||||
|
Loading…
Reference in a new issue