             out.send res
           , delay
 
+        err.on 'data', (data) ->
+          done data
         out.once 'data', (data) ->
           chai.expect(data).to.be.an 'object'
           chai.expect(data.p1).to.equal 'req'

      c.outPorts.point.attach p

      it 'should correctly bind component to `this` context', (done) ->
        p.removeAllListeners()
        noflo.helpers.WirePattern c,
          in: ['x', 'y', 'z']
          out: 'point'

        async: true
        forwardGroups: true
      , (data, groups, out, callback) ->
        setTimeout ->
          out.beginGroup data.path
          out.send data.message
          out.endGroup()
          do callback
        , 300

      ins = noflo.internalSocket.createSocket()
      msg = noflo.internalSocket.createSocket()
      rep = noflo.internalSocket.createSocket()
      pth = noflo.internalSocket.createSocket()
      tkn = noflo.internalSocket.createSocket()
      out = noflo.internalSocket.createSocket()
      err = noflo.internalSocket.createSocket()
      c.inPorts.in.attach ins
      c.inPorts.message.attach msg
      c.inPorts.repository.attach rep
      c.inPorts.path.attach pth
      c.inPorts.token.attach tkn
      c.outPorts.out.attach out
      c.outPorts.error.attach err

      it 'should handle mixed flow well', (done) ->
        groups = []
        refGroups = [
          'foo'
          'http://techcrunch.com/2013/03/26/embedly-now/'
          'path data'
        ]
        ends = 0
        packets = []
        refData = ['message data']
        out.on 'begingroup', (grp) ->
          groups.push grp
        out.on 'endgroup', ->
          ends++
        out.on 'data', (data) ->
          packets.push data
        out.on 'disconnect', ->
          chai.expect(groups).to.deep.equal refGroups
          chai.expect(ends).to.equal 3
          chai.expect(packets).to.deep.equal refData
          done()

        err.on 'data', (data) ->
          done data

        rep.beginGroup 'foo'
        rep.beginGroup 'http://techcrunch.com/2013/03/26/embedly-now/'
        rep.send 'repo data'
        rep.endGroup()
        rep.endGroup()
        ins.beginGroup 'foo'
        ins.beginGroup 'http://techcrunch.com/2013/03/26/embedly-now/'
        ins.send 'ins data'
        msg.beginGroup 'foo'
        msg.beginGroup 'http://techcrunch.com/2013/03/26/embedly-now/'
        msg.send 'message data'
        msg.endGroup()
        msg.endGroup()
        ins.endGroup()
        ins.endGroup()
        ins.disconnect()
        msg.disconnect()
        pth.beginGroup 'foo'
        pth.beginGroup 'http://techcrunch.com/2013/03/26/embedly-now/'
        pth.send 'path data'
        pth.endGroup()
        pth.endGroup()
        pth.disconnect()
        rep.disconnect()
    describe 'with many inputs and groups in sync mode', ->
      c = new noflo.Component
      c.token = null
      c.inPorts.add 'in', datatype: 'string'
      .add 'message', datatype: 'string'
      .add 'repository', datatype: 'string'
      .add 'path', datatype: 'string'
      .add 'token', datatype: 'string', (event, payload) ->
        c.token = payload if event is 'data'
      c.outPorts.add 'out', datatype: 'string'
      .add 'error', datatype: 'object'

      noflo.helpers.WirePattern c,
        in: ['in', 'message', 'repository', 'path']
        out: 'out'
        async: false
        forwardGroups: true
      , (data, groups, out) ->
        out.beginGroup data.path
        out.send data.message
        out.endGroup()

      ins = noflo.internalSocket.createSocket()
      msg = noflo.internalSocket.createSocket()
