       console.log e.message
     gearman.connect()
 
-  after (done) ->
+  afterEach (done) ->
     gearman.on "close", ->
       done()
     gearman.close()

describe 'worker and client', ->
  gearman = null

  before (done) ->
    gearman = new Gearman("localhost")
    gearman.on "connect", ->
      done()

    job.on 'data', (payload) ->
      assert.equal payload.toString('base64'), data2.toString('base64')

    job.on 'end', ->
      gearman.on 'idle', -> done()

  it 'allows for worker failure', (done) ->
    gearman.registerWorker 'test_error', (payload, worker) ->
      worker.error()

    job = gearman.submitJob('test_error', 'error')
    job.on 'error', (err) ->
      assert err, 'job should have an error'
      gearman.on "idle", -> done()

    job.on 'end', (err) ->
      console.log 'DONE', err
      assert false, "job should not have ended"

###
exports["Job timeout"] =
  setUp: (callback) ->
    @gearman = new Gearman("localhost")
