                tgt: { node: 'World', port: 'in' }
           ]
 
-          addListener = ->
-            connection.once 'message', (message) ->
-              data = JSON.parse message.utf8Data
-              validateSchema data, "/network/output/#{data.command}"
-              for expected, i in expects
-                if data.command is expected.command
-                  expects.splice i, 1
-                  break
-
-              if expects.length is 0
-                done()
-              else
-                addListener()
-
-          addListener()
+          listener = (message) ->
+            data = JSON.parse message.utf8Data
+            validateSchema data, "/#{data.protocol}/output/#{data.command}"
+            return unless data.command is expects[0].command
+            expected = expects.shift()
+            if data.command is 'started'
+              delete data.payload.time
+              delete expected.payload.time
+            chai.expect(data.payload).to.eql expected.payload
+            return if expects.length
+            # Received all packets
+            connection.removeListener 'message', listener
+            done()
+            return
+          connection.on 'message', listener
+
           send 'network', 'start',
             graph: 'bar'
 

semver = require 'semver'
tv4 = require '../schema/index.js'

check = (done, f) ->
  try
    f()
  catch e
    done e

validateSchema = (payload, schema) ->
  res = tv4.validateMultiple payload, schema
  chai.expect(res.errors).to.eql []
  chai.expect(res.valid).to.equal true
  return res.valid

exports.testRuntime = (runtimeType, startServer, stopServer, host='localhost', port=8080, collection='core', version='0.5') ->

              running: false
              started: false
          ]
          receive expects, done
          send 'network', 'getstatus',
            graph: 'bar'
      # describe 'on console output', ->
