[tracker/sam/functional-test-runner: 12/15] WIP: store tests mostly work now



commit 537878dfe696d4c8a3f4634b7f18be05ee07701b
Author: Sam Thursfield <sam afuera me uk>
Date:   Tue Dec 30 01:08:01 2014 +0000

    WIP: store tests mostly work now

 tests/functional-tests/common/helpers.py           |   42 +++++++++++++++++++-
 tests/functional-tests/common/sandbox.py           |    5 ++-
 tests/functional-tests/common/utils/system.py      |   41 -------------------
 .../functional-tests/store/test_backup_restore.py  |   32 +++++++-------
 tests/functional-tests/store/test_transactions.py  |    8 ++--
 5 files changed, 64 insertions(+), 64 deletions(-)
---
diff --git a/tests/functional-tests/common/helpers.py b/tests/functional-tests/common/helpers.py
index 5df4e2e..44403ef 100644
--- a/tests/functional-tests/common/helpers.py
+++ b/tests/functional-tests/common/helpers.py
@@ -17,17 +17,23 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 #
+
 import dbus
+
+from dbus.mainloop.glib import DBusGMainLoop
 from gi.repository import GLib
 from gi.repository import GObject
+
 import os
+import shutil
 import sys
 import subprocess
 import time
-from dbus.mainloop.glib import DBusGMainLoop
-import re
+
+from logging import info
 
 import utils.configuration as cfg
+
 from utils import options
 
 
@@ -629,6 +635,38 @@ class StoreHelper (Helper):
         else:
             raise Exception("Something fishy is going on")
 
+    def remove_journal(self):
+        db_location = os.path.join(
+            os.environ['XDG_DATA_HOME'], 'tracker', 'data')
+        shutil.rmtree(db_location)
+        os.mkdir(db_location)
+
+    def remove_dbs(self):
+        db_location = os.path.join(
+            os.environ['XDG_CACHE_HOME'], 'tracker')
+        shutil.rmtree(db_location)
+        os.mkdir(db_location)
+
+    def corrupt_dbs(self):
+        for filename in ["meta.db", "meta.db-wal"]:
+            db_path = os.path.join(
+                os.environ['XDG_CACHE_HOME'], 'tracker', filename)
+            with open(db_path, "w") as f:
+                for i in range(0, 100):
+                    f.write(
+                        "Some stupid content... hohohoho, not a sqlite file "
+                        "anymore!\n")
+
+    def prepare_journal_replay(self):
+        db_location = os.path.join(
+            os.environ['XDG_CACHE_HOME'], 'tracker', 'meta.db')
+        os.unlink(db_location)
+
+        lockfile = os.path.join(
+            os.environ['XDG_DATA_HOME'], 'tracker', 'data', '.ismeta.running')
+        with open(lockfile, 'w') as f:
+            f.write(' ')
+
 
 class MinerFsHelper (Helper):
 
diff --git a/tests/functional-tests/common/sandbox.py b/tests/functional-tests/common/sandbox.py
index a84de97..3879b22 100644
--- a/tests/functional-tests/common/sandbox.py
+++ b/tests/functional-tests/common/sandbox.py
@@ -55,6 +55,9 @@ class TrackerSandbox(object):
         os.environ['HOME'] = tempdir
         info("HOME=%s" % tempdir)
 
+        os.environ['XDG_DATA_HOME'] = os.path.join(tempdir, 'data')
+        os.environ['XDG_CACHE_HOME'] = os.path.join(tempdir, 'cache')
+
         return tempdir
 
     def _sandbox_message_bus(self):
@@ -71,7 +74,7 @@ class TrackerSandbox(object):
     def _stop_message_bus(self, dbus_process):
         info('Stopping D-Bus daemon (PID %i) ...' % (dbus_process.pid))
         dbus_process.terminate()
-        dbus_process.stop()
+        dbus_process.wait()
 
     def _remove_tempdir(self, tempdir):
         shutil.rmtree(tempdir)
diff --git a/tests/functional-tests/common/utils/system.py b/tests/functional-tests/common/utils/system.py
index f829837..6aebb21 100644
--- a/tests/functional-tests/common/utils/system.py
+++ b/tests/functional-tests/common/utils/system.py
@@ -1,16 +1,8 @@
 #!/usr/bin/python
 import os
-import subprocess
 import shutil
 import configuration as cfg
 
-from gi.repository import GObject
-from gi.repository import GLib
-import dbus
-from dbus.mainloop.glib import DBusGMainLoop
-import time
-
-import options
 from dconf import DConfClient
 
 import helpers
@@ -78,39 +70,6 @@ class TrackerSystemAbstraction:
     def tracker_store_stop_brutally(self):
         self.store.kill()
 
-    def tracker_store_prepare_journal_replay(self):
-        db_location = os.path.join(
-            TEST_ENV_DIRS['XDG_CACHE_HOME'], "tracker", "meta.db")
-        os.unlink(db_location)
-
-        lockfile = os.path.join(
-            TEST_ENV_DIRS['XDG_DATA_HOME'], "tracker", "data", ".ismeta.running")
-        f = open(lockfile, 'w')
-        f.write(" ")
-        f.close()
-
-    def tracker_store_corrupt_dbs(self):
-        for filename in ["meta.db", "meta.db-wal"]:
-            db_path = os.path.join(
-                TEST_ENV_DIRS['XDG_CACHE_HOME'], "tracker", filename)
-            f = open(db_path, "w")
-            for i in range(0, 100):
-                f.write(
-                    "Some stupid content... hohohoho, not a sqlite file anymore!\n")
-            f.close()
-
-    def tracker_store_remove_journal(self):
-        db_location = os.path.join(
-            TEST_ENV_DIRS['XDG_DATA_HOME'], "tracker", "data")
-        shutil.rmtree(db_location)
-        os.mkdir(db_location)
-
-    def tracker_store_remove_dbs(self):
-        db_location = os.path.join(
-            TEST_ENV_DIRS['XDG_CACHE_HOME'], "tracker")
-        shutil.rmtree(db_location)
-        os.mkdir(db_location)
-
     def tracker_miner_fs_testing_start(self, config, dbus_address):
         """
         Stops any previous instance of the store and miner, calls set_up_environment,
diff --git a/tests/functional-tests/store/test_backup_restore.py 
b/tests/functional-tests/store/test_backup_restore.py
index a232021..f356200 100644
--- a/tests/functional-tests/store/test_backup_restore.py
+++ b/tests/functional-tests/store/test_backup_restore.py
@@ -17,11 +17,11 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 #
+
+
 import os
 import dbus  # For the exception handling
 
-from common.utils.system import TrackerSystemAbstraction
-from common.utils.helpers import StoreHelper
 from common.utils import configuration as cfg
 from common.utils.expectedFailure import expectedFailureBug, expectedFailureJournal
 
@@ -180,10 +180,10 @@ class BackupRestoreTest (testcase.TrackerStoreTest):
         instances_before = self.tracker.count_instances("nco:Contact")
         self.tracker.backup(self.BACKUP_FILE)
 
-        self.system.tracker_store_stop_nicely()
-        self.system.tracker_store_remove_dbs()
-        self.system.tracker_store_remove_journal()
-        self.system.tracker_store_start()
+        self.store.stop()
+        self.store.remove_dbs()
+        self.store.remove_journal()
+        self.store.start(self.sandbox)
 
         instances_before_restore = self.tracker.count_instances(
             "nco:Contact")
@@ -207,10 +207,10 @@ class BackupRestoreTest (testcase.TrackerStoreTest):
         instances_before = self.tracker.count_instances("nco:Contact")
         self.tracker.backup(self.BACKUP_FILE)
 
-        self.system.tracker_store_stop_brutally()
-        self.system.tracker_store_corrupt_dbs()
-        self.system.tracker_store_remove_journal()
-        self.system.tracker_store_start()
+        self.store.kill()
+        self.store.corrupt_dbs()
+        self.store.remove_journal()
+        self.store.start(self.sandbox)
 
         instances_before_restore = self.tracker.count_instances(
             "nco:Contact")
@@ -276,9 +276,9 @@ class JournalReplayTest (testcase.TrackerStoreTest):
         ie = self.tracker.count_instances("nie:InformationElement")
         contacts = self.tracker.count_instances("nco:Contact")
 
-        self.system.tracker_store_stop_brutally()
-        self.system.tracker_store_corrupt_dbs()
-        self.system.tracker_store_start()
+        self.store.kill()
+        self.store.corrupt_dbs()
+        self.store.start(self.sandbox)
 
         emails_now = self.tracker.count_instances("nmo:Email")
         ie_now = self.tracker.count_instances("nie:InformationElement")
@@ -310,9 +310,9 @@ class JournalReplayTest (testcase.TrackerStoreTest):
         ie = self.tracker.count_instances("nie:InformationElement")
         contacts = self.tracker.count_instances("nco:Contact")
 
-        self.system.tracker_store_stop_brutally()
-        self.system.tracker_store_prepare_journal_replay()
-        self.system.tracker_store_start()
+        self.store.kill()
+        self.store.prepare_journal_replay()
+        self.store.start(self.sandbox)
 
         emails_now = self.tracker.count_instances("nmo:Email")
         ie_now = self.tracker.count_instances("nie:InformationElement")
diff --git a/tests/functional-tests/store/test_transactions.py 
b/tests/functional-tests/store/test_transactions.py
index 72d0952..d6a3b73 100644
--- a/tests/functional-tests/store/test_transactions.py
+++ b/tests/functional-tests/store/test_transactions.py
@@ -32,7 +32,7 @@ import testcase
 TEST_INSTANCE_PATTERN = "test://12-transactions-%d"
 
 
-class TrackerTransactionsTest(testcase.TrackerSToreTest):
+class TrackerTransactionsTest(testcase.TrackerStoreTest):
 
     """
     In a loop:
@@ -50,7 +50,6 @@ class TrackerTransactionsTest(testcase.TrackerSToreTest):
         self.instance_counter = 0
 
     def tearDown(self):
-        print "Tear down (will take some time to remove all resources)"
         delete_sparql = "DELETE { ?u a rdfs:Resource } WHERE { ?u a nmo:Email} \n"
         self.tracker.update(delete_sparql,
                             timeout=60000)
@@ -80,8 +79,9 @@ class TrackerTransactionsTest(testcase.TrackerSToreTest):
             NUMBER_OF_INSTANCES = 1000
             self.insert_and_commit(NUMBER_OF_INSTANCES)
 
-            self.system.tracker_store_stop_brutally()
-            self.system.tracker_store_start()
+            self.store.kill()
+            self.store.start(self.sandbox)
+
             try:
                 results = self.tracker.count_instances("nmo:Email")
             except:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]