state/{api,apiserver}: don't leak heartbeat goroutine

- In api.State.Close, signal and wait for the heartbeat
  goroutine to stop before returning.
- Add various missing api.State.Close calls to apiserver
  tests.

Fixes https://bugs.launchpad.net/juju-core/+bug/1334531
Merge pull request #167 from axw/lp1334531-dont-leak-apistate

state/{api,apiserver}: don't leak heartbeat goroutine

- In api.State.Close, signal and wait for the heartbeat
  goroutine to stop before returning.
- Add various missing api.State.Close calls to apiserver
  tests.

Fixes https://bugs.launchpad.net/juju-core/+bug/1334531