Misc cleanup/README
This commit is contained in:
parent
3df2344362
commit
995d8e4489
|
@ -57,10 +57,18 @@ ActivePush makes extensive use of "promises" (specifically Q promises, which are
|
|||
|
||||
npm test
|
||||
|
||||
Or:
|
||||
|
||||
mocha --compilers coffee:coffee-script test
|
||||
|
||||
The integration tests assume a STOMP broker is running on `localhost:61613`. ActiveMQ can be started with the following command:
|
||||
|
||||
activemq start broker:stomp://localhost:61613
|
||||
|
||||
They also assume Selenium/WebDriver is running on `localhost:4444`. If you want to disable the WebDriver tests (they are significantly slower) comment out the last line of `test/integration-webdriver.coffee`, or run:
|
||||
|
||||
mocha --compilers coffee:coffee-script test/integration-socketio-client.coffee
|
||||
|
||||
`integration-common.coffee` implements the logic of the tests while `integration-socketio-client.coffee` and `integration-webdriver.coffee` implement a common API to create either an in-process `socket.io-client` or a remote WebDriver instance running the demo.html page (which stores messages it receives in `window.messages` for introspection by the test)
|
||||
|
||||
Unfortunately there is no easy way to tell when all messages have propagated from the running test to the ActiveMQ queue back to the ActivePush server and through the Socket.io client, so we currently have short delays before testing that messages have been received. This leads to occasional non-deterministic test failures. Increasing the delays reduces the frequency at a cost of longer running tests.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
Q = require "q"
|
||||
|
||||
Consumer = require("./common").Module
|
||||
|
||||
socket_io = require "socket.io"
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
|
||||
Q = require "q"
|
||||
Producer = require("./common").Module
|
||||
merge = require "deepmerge"
|
||||
|
||||
Producer = require("./common").Module
|
||||
|
||||
class StompProducer extends Producer
|
||||
constructor: (options) ->
|
||||
Producer.call @, options
|
||||
|
||||
getHealth: ->
|
||||
name: "stomp"
|
||||
host: @options.host
|
||||
port: @options.port
|
||||
inbox: @options.inbox
|
||||
|
||||
|
||||
{ Stomp } = require "stomp"
|
||||
{ ReconnectingStomp } = require "./reconnecting-stomp"
|
||||
|
||||
# Library #1: stomp
|
||||
class NodeStompProducer extends StompProducer
|
||||
constructor: (options) ->
|
||||
Producer.call @, options
|
||||
|
||||
start: ->
|
||||
deferred = Q.defer()
|
||||
|
@ -64,54 +65,52 @@ NodeStompProducer.publish = (options, push_id, message) ->
|
|||
stomp.publish(push_id, message)
|
||||
stomp.stop()
|
||||
|
||||
# Library #2: stompit
|
||||
stompit = require "stompit"
|
||||
class StompitProducer extends StompProducer
|
||||
constructor: (options) ->
|
||||
Producer.call @, options
|
||||
|
||||
start: ->
|
||||
deferred = Q.defer()
|
||||
@stomp = stompit.connect host: @options.host, port: @options.port, =>
|
||||
@_onConnected()
|
||||
deferred.resolve()
|
||||
deferred.promise
|
||||
|
||||
stop: ->
|
||||
Q.try =>
|
||||
@stomp.disconnect()
|
||||
|
||||
_onConnected: =>
|
||||
@stomp.subscribe { destination: @options.inbox }, @_onMessage
|
||||
@logger.info "STOMP connected: %s:%s%s", @options.host, @options.port, @options.inbox
|
||||
|
||||
_onMessage: (message) =>
|
||||
body = ""
|
||||
message.on "data", (data) ->
|
||||
body += data.toString("utf-8")
|
||||
message.on "end", =>
|
||||
push_id = message.headers.push_id
|
||||
@logger.debug "STOMP receive push_id=%s message=%s", push_id, body
|
||||
@subscriptions.emit push_id, body
|
||||
|
||||
publish: (push_id, message) ->
|
||||
frame = @stomp.send(
|
||||
destination: @options.inbox
|
||||
push_id: push_id
|
||||
persistent: false
|
||||
)
|
||||
Q.ninvoke(frame, "end", message)
|
||||
|
||||
StompitProducer.publish = (options, push_id, message) ->
|
||||
console.log "options", options
|
||||
stomp = new StompitProducer options
|
||||
stomp.start().then ->
|
||||
stomp.publish(push_id, message)
|
||||
.then ->
|
||||
stomp.stop()
|
||||
|
||||
# Default to one of the two:
|
||||
StompProducer = NodeStompProducer
|
||||
|
||||
# Library #2: stompit
|
||||
# stompit = require "stompit"
|
||||
# class StompitProducer extends StompProducer
|
||||
|
||||
# start: ->
|
||||
# deferred = Q.defer()
|
||||
# @stomp = stompit.connect host: @options.host, port: @options.port, =>
|
||||
# @_onConnected()
|
||||
# deferred.resolve()
|
||||
# deferred.promise
|
||||
|
||||
# stop: ->
|
||||
# Q.try =>
|
||||
# @stomp.disconnect()
|
||||
|
||||
# _onConnected: =>
|
||||
# @stomp.subscribe { destination: @options.inbox }, @_onMessage
|
||||
# @logger.info "STOMP connected: %s:%s%s", @options.host, @options.port, @options.inbox
|
||||
|
||||
# _onMessage: (message) =>
|
||||
# body = ""
|
||||
# message.on "data", (data) ->
|
||||
# body += data.toString("utf-8")
|
||||
# message.on "end", =>
|
||||
# push_id = message.headers.push_id
|
||||
# @logger.debug "STOMP receive push_id=%s message=%s", push_id, body
|
||||
# @subscriptions.emit push_id, body
|
||||
|
||||
# publish: (push_id, message) ->
|
||||
# frame = @stomp.send(
|
||||
# destination: @options.inbox
|
||||
# push_id: push_id
|
||||
# persistent: false
|
||||
# )
|
||||
# Q.ninvoke(frame, "end", message)
|
||||
|
||||
# StompitProducer.publish = (options, push_id, message) ->
|
||||
# console.log "options", options
|
||||
# stomp = new StompitProducer options
|
||||
# stomp.start().then ->
|
||||
# stomp.publish(push_id, message)
|
||||
# .then ->
|
||||
# stomp.stop()
|
||||
|
||||
# StompProducer = StompitProducer
|
||||
|
||||
module.exports = { Producer, StompProducer }
|
||||
|
|
Loading…
Reference in New Issue