   socket1 = null
   socket2 = null
   socket3 = null
+
+  cleanup = null
 
   afterEachFn = (done) ->
     endcb = -> redis.flushall done

    if socket3
      socket3.disconnect()
      socket3 = null
    if chatServer
      chatServer.close endcb
      chatServer = null
    else

          enableDestroy httpInst
          chatServer1 = new ChatService { http : httpInst }, null, state
          httpInst.listen port
          cleanup = (cb) ->
            chatServer1.close ->
              httpInst.destroy cb
          socket1 = ioClient.connect url1, makeParams(user1)
          socket1.on 'loginConfirmed', (u) ->
            expect(u).equal(user1)
            done()

        it 'should integrate with an existing io', (done) ->
          io = socketIO port
          chatServer1 = new ChatService { io : io }, null, state
          cleanup = (cb) ->
            chatServer1.close ->
              chatServer1.close()
              io.close()
              cb()
          socket1 = ioClient.connect url1, makeParams(user1)
          socket1.on 'loginConfirmed', (u) ->
            expect(u).equal(user1)
            done()

        it 'should spawn a new io server', (done) ->
          chatServer = new ChatService { port : port }, null, state
