mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 19:06:59 -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
|
simulationQueue = null
|
||||||
|
|
||||||
module.exports.setupRoutes = (app) ->
|
module.exports.setupRoutes = (app) ->
|
||||||
generateQueueInstance()
|
|
||||||
###queueClient.registerQueue "simulationQueue", {}, (err,data) ->
|
###queueClient.registerQueue "simulationQueue", {}, (err,data) ->
|
||||||
simulationQueue = data
|
simulationQueue = data
|
||||||
simulationQueue.subscribe 'message', (err, data) ->
|
simulationQueue.subscribe 'message', (err, data) ->
|
||||||
|
@ -24,17 +23,20 @@ module.exports.setupRoutes = (app) ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
generateQueueInstance = ->
|
|
||||||
|
module.exports.generateQueueClient = ->
|
||||||
if config.isProduction
|
if config.isProduction
|
||||||
queueClient = new SQSQueueClient()
|
queueClient = new SQSQueueClient()
|
||||||
else
|
else
|
||||||
queueClient = new MongoQueueClient()
|
queueClient = new MongoQueueClient()
|
||||||
|
return queueClient
|
||||||
|
|
||||||
|
|
||||||
class SQSQueueClient extends AbstractQueueClient
|
class SQSQueueClient
|
||||||
constructor: ->
|
constructor: ->
|
||||||
@configure()
|
@configure()
|
||||||
@sqs = @generateSQSInstance()
|
@sqs = @generateSQSInstance()
|
||||||
|
|
||||||
###Public API###
|
###Public API###
|
||||||
registerQueue: (queueName, options, callback) ->
|
registerQueue: (queueName, options, callback) ->
|
||||||
#returns new queue in data argument of 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: ->
|
constructor: ->
|
||||||
@configure()
|
@configure()
|
||||||
@createMongoConnection()
|
@createMongoConnection()
|
||||||
|
@ -155,7 +157,7 @@ class MongoQueue extends events.EventEmitter
|
||||||
queue: @queueName
|
queue: @queueName
|
||||||
scheduledVisibilityTime: Date.now() + (delaySeconds * 1000)
|
scheduledVisibilityTime: Date.now() + (delaySeconds * 1000)
|
||||||
|
|
||||||
messageToSend.save (err) =>
|
messageToSend.save (err,data) =>
|
||||||
if err? then @emit 'error',err,data else @emit 'sent',err, data
|
if err? then @emit 'error',err,data else @emit 'sent',err, data
|
||||||
callback? 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