@@ -22,6 +22,7 @@
2222import os
2323import signal
2424import subprocess
25+import time
2526
2627from testtools.matchers._basic import Equals
2728from autopilot.matchers import Eventually
@@ -49,7 +50,25 @@ class UpstartIntegrationTests(UnityTestCase):
4950 def _launch_unity(self):
5051 self.patch_environment("QT_LOAD_TESTABILITY", "1")
5152 self.process = subprocess.Popen([get_binary_path()] + self.unity_geometry_args)
52− self.addCleanup(lambda: self.process.terminate())
53+ def ensure_stopped():
54+ self.process.terminate()
55+ for i in xrange(10):
56+ try:
57+ self._get_status()
58+ except OSError:
59+ break
60+ else:
61+ time.sleep(1)
62+ try:
63+ self._get_status()
64+ except OSError:
65+ pass
66+ else:
67+ self.process.kill()
68+
69+ self.process.wait()
70+
71+ self.addCleanup(ensure_stopped)
5372
5473 def _set_proxy(self):
5574 super(UpstartIntegrationTests, self)._set_proxy(get_proxy_object_for_existing_process(