 module.exports =
 
   'systems are started and stopped in the most efficient order': (test) ->
+    test.expect 28
 
     ###################################################################################
     # services

    stopped = new Set

    start = (names) ->
      console.log('starting:', names)
      starting.add names
      Promise.all names.map (name) ->
        callback = services[name].start
        promise = Promise.resolve(callback())
        promise.then ->
          console.log('running:  ' + name)
          starting.remove name
          running.add name
          # start all we can start now that have not been started
          toStart = new Set(dag.whereAllParentsIn(running.elements()))
            .remove(starting)
            .remove(running)
            .elements()
          start toStart

    stop = (names) ->
      console.log('stopping: ', names)
      stopping.add names
      return Promise.all names.map (name) ->
        callback = services[name].stop
        promise = Promise.resolve callback()
        promise.then ->
          console.log('stopped:  ' + name)
          stopping.remove name
          stopped.add name
          # stop all we can stop now that have not been stopped
          toStop = new Set(dag.whereAllChildrenIn(stopped.elements()))
            .remove(stopping)
            .remove(stopped)
            .elements()
          stop toStop

    start(dag.parentless())
      .then ->
        test.ok running.isEqual new Set Object.keys(services)
        test.ok starting.isEqual new Set
        stop dag.childless()
      .then ->
        test.ok stopped.isEqual new Set Object.keys(services)
        test.ok stopping.isEqual new Set
        test.done()

          Promise.delay(100)
      redisTwo:
        start: ->
          test.ok starting.equals(
            new Set('redisOne', 'redisTwo', 'postgres', 'elasticSearch', 'mailAPI')
          )
          test.ok running.equals(
            new Set
          )
          Promise.delay(20)
