Make some machine/unit agent tests more robust

Fixes: https://bugs.launchpad.net/juju-core/+bug/1361721

If a machine is marked as Dead part way through agent startup, as happens in some tests, the agent exits without realising it needs to terminate.
The issue is that if the machine is marked as dead after openAPIState is called, but before setupContainerSupport is called, the agent doesn't see the ErrTerminateAgent error. It's a race in the test.
But yes, you are right, entity is not refreshed. I'll have to rethink.