 
     describe 'when started', ->
       it 'sends definition on fbp queue', (done) ->
-        broker = state.broker
 
-        onDiscovery = (msg) ->
-          def = msg.data
+        waitDefinition name, (def) ->
           chai.expect(def).to.be.an 'object'
           chai.expect(def).to.have.keys ['id', 'icon', 'role', 'component', 'label', 'inports', 'outports']
-          state.broker.ackMessage msg
-          return if def.component != name
           done()
-        state.broker.subscribeParticipantChange onDiscovery
 
     describe 'sending data on inport queue', ->
+      @timeout 4000
       it 'repeats the same data on outport queue', (done) ->
         broker = state.broker
 
-        input = { bar: 'foo' }
         onReceive = (msg) ->
           broker.ackMessage msg
-          chai.expect(msg.data).to.eql input
+          chai.expect(msg.data).to.eql state.repeat
           done()
 
         # TODO: look up in definition
-        receiveQueue = 'test.RECEIVE'
-        inQueue = 'repeat.IN'
-        outQueue = 'repeat.OUT'
-        binding = { type: 'pubsub', src: outQueue, tgt: receiveQueue }
+        waitDefinition name, (def) ->
 
-        send = () ->
-          broker.sendTo 'inqueue', inQueue, input, (err) ->
+          inQueue = null
+          outQueue = null
+          for port in def.inports
+            inQueue = port.queue if port.id == 'in'
+          for port in def.outports
+            outQueue = port.queue if port.id == 'out'
+
+          receiveQueue = 'test.RECEIVE'
+          binding = { type: 'pubsub', src: outQueue, tgt: receiveQueue }
+
+          send = () ->
+            broker.sendTo 'inqueue', inQueue, state.repeat, (err) ->
+              chai.expect(err).to.not.exist
+
+          broker.createQueue 'inqueue', receiveQueue, (err) ->
             chai.expect(err).to.not.exist
-
-        broker.createQueue 'inqueue', receiveQueue, (err) ->
-          chai.expect(err).to.not.exist
-          broker.addBinding binding, (err) ->
-            chai.expect(err).to.not.exist
-            broker.subscribeToQueue receiveQueue, onReceive, (err) ->
+            broker.addBinding binding, (err) ->
               chai.expect(err).to.not.exist
-              setTimeout send, 1000 # HACK: wait for inqueue to be setup
+              broker.subscribeToQueue receiveQueue, onReceive, (err) ->
+                chai.expect(err).to.not.exist
+                setTimeout send, 1000 # HACK: wait for inqueue to be setup
 
 
 describe 'Heterogenous', ->

  return startProcess args, callback

exports.testParticipant = testParticipant = (state, name) ->

  describe "#{name} participant", ->
    participant = null
    beforeEach (done) ->
      @timeout 4000
      participant = startForeign state.commands, name, done
    afterEach (done) ->
      participant.kill()

  g =
    broker: null
    commands: foreignParticipants
    repeat: undefined # default

  beforeEach (done) ->
    g.broker = msgflo.transport.getBroker address
