Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha@silbe.org>2009-11-07 22:34:27 (GMT)
committer Sascha Silbe <sascha@silbe.org>2009-11-07 22:34:27 (GMT)
commiteb7cfa029404bb305a542f138d5bf28cc36216bc (patch)
tree3dce208dcd557aaa11a952d24bf73dbf4177e429
parentfec0cf267072203dab5ee38a830192a9e3675aee (diff)
start a new data store instance for each group of tests
-rwxr-xr-xtests/runalltests.py41
1 files changed, 34 insertions, 7 deletions
diff --git a/tests/runalltests.py b/tests/runalltests.py
index bc34c29..e1a3426 100755
--- a/tests/runalltests.py
+++ b/tests/runalltests.py
@@ -22,6 +22,8 @@ import time
import unittest
import dbus
+import dbus.mainloop.glib
+import gobject
logging.basicConfig(level=logging.WARN,
@@ -125,6 +127,8 @@ class TestSuiteWrapper(unittest.TestCase):
def __init__(self, suite):
self._wrapped_suite = suite
+ self._bus = dbus.SessionBus()
+ self._loop = None
unittest.TestCase.__init__(self)
def runTest(self, result=None):
@@ -167,13 +171,34 @@ class TestSuiteWrapper(unittest.TestCase):
result.stopTest(self)
def tearDown(self):
- bus = dbus.SessionBus()
- datastore = dbus.Interface(bus.get_object(DS_DBUS_SERVICE,
- DS_DBUS_PATH), DS_DBUS_INTERFACE)
- for entry in datastore.find({}, ['uid'], byte_arrays=True)[0]:
- datastore.delete(entry['uid'])
-
- assert (not datastore.find({}, ['uid'], byte_arrays=True)[0])
+ self._kill_data_store()
+ self._clean_data_store()
+
+ def _kill_data_store(self):
+ pgrep = subprocess.Popen(['pgrep', '-g', os.environ['DBUS_PID'],
+ '-f', 'datastore-service'],
+ close_fds=True, stdout=subprocess.PIPE)
+ stdout, stderr_ = pgrep.communicate()
+ pids = stdout.strip().split('\n')
+ if len(pids) != 1 or not pids[0]:
+ raise ValueError("Can't find (a single) data store process "
+ "(pgrep output %r)" % (stdout, ))
+
+ pid = int(pids[0])
+ self._loop = gobject.MainLoop()
+ self._bus.watch_name_owner(DS_DBUS_SERVICE, self._service_changed_cb)
+ os.kill(pid, signal.SIGTERM)
+ self._loop.run()
+
+ def _service_changed_cb(self, new_owner):
+ if not new_owner:
+ self._loop.quit()
+
+ def _clean_data_store(self):
+ profile = os.environ.get('SUGAR_PROFILE', 'default')
+ base_dir = os.path.join(os.path.expanduser('~'), '.sugar', profile)
+ root_path = os.path.join(base_dir, 'datastore')
+ shutil.rmtree(root_path)
class TimedTestResult(unittest._TextTestResult):
@@ -251,6 +276,7 @@ def test_suite(tests=None):
def run_tests(tests):
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
runner = TimedTestRunner(verbosity=2)
suite = test_suite(tests)
result = runner.run(suite)
@@ -301,6 +327,7 @@ def main(my_name, arguments):
try:
dbus_pid, dbus_address = _start_dbus(environment)
environment['DBUS_SESSION_BUS_ADDRESS'] = dbus_address
+ environment['DBUS_PID'] = str(dbus_pid)
pipe = subprocess.Popen([os.path.abspath(my_name),
'--stage2']+arguments,