[folks] eds: Move with-session-bus-eds.sh into test-case.vala



commit 3acaaeeb997f1240011806fabda95c17cbe0df1a
Author: Philip Withnall <philip tecnocode co uk>
Date:   Mon Nov 18 23:24:27 2013 +0000

    eds: Move with-session-bus-eds.sh into test-case.vala
    
    Eliminate some more of the shell scripting which plagues our test cases.
    This wipes up to 2s off the startup time for the EDS tests (which was
    previously hard-coded to spend waiting for the EDS processes to start up;
    now the processes are started through D-Bus service activation, so we only
    wait as long as necessary).

 tests/eds/Makefile.am                      |   12 ----
 tests/eds/helper-create-many-contacts.vala |    2 +-
 tests/eds/helper-delete-contacts.vala      |    2 +-
 tests/eds/helper-prepare-aggregator.vala   |    2 +-
 tests/lib/eds/test-case.vala               |   94 +++++++++++++++++++++++-----
 tests/tools/Makefile.am                    |    2 -
 tests/tools/eds.sh                         |   35 ----------
 tests/tools/with-session-bus-eds.sh        |   49 --------------
 8 files changed, 82 insertions(+), 116 deletions(-)
---
diff --git a/tests/eds/Makefile.am b/tests/eds/Makefile.am
index 687ebe6..29f7bb3 100644
--- a/tests/eds/Makefile.am
+++ b/tests/eds/Makefile.am
@@ -77,13 +77,6 @@ TESTS = \
        perf \
        $(NULL)
 
-RUN_WITH_PRIVATE_BUS = $(top_srcdir)/tests/tools/with-session-bus-eds.sh
-
-TESTS_ENVIRONMENT = \
-       $(RUN_WITH_PRIVATE_BUS) \
-       --session \
-       --
-
 noinst_PROGRAMS = \
        $(TESTS) \
        helper-create-many-contacts \
@@ -239,11 +232,6 @@ helper_prepare_aggregator_SOURCES = \
        helper-prepare-aggregator.vala \
        $(NULL)
 
-CLEANFILES = \
-       *.pid \
-       *.address \
-       $(NULL)
-
 -include $(top_srcdir)/git.mk
 -include $(top_srcdir)/check.mk
 -include $(top_srcdir)/valgrind.mk
diff --git a/tests/eds/helper-create-many-contacts.vala b/tests/eds/helper-create-many-contacts.vala
index 000348f..bbeb184 100644
--- a/tests/eds/helper-create-many-contacts.vala
+++ b/tests/eds/helper-create-many-contacts.vala
@@ -131,7 +131,7 @@ public class Main
     {
       Intl.setlocale (LocaleCategory.ALL, "");
 
-      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS") != "eds")
+      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS") != "no-services")
         error ("e-d-s helpers must be run in a private D-Bus session with " +
             "e-d-s services");
 
diff --git a/tests/eds/helper-delete-contacts.vala b/tests/eds/helper-delete-contacts.vala
index 46d2e35..816767d 100644
--- a/tests/eds/helper-delete-contacts.vala
+++ b/tests/eds/helper-delete-contacts.vala
@@ -55,7 +55,7 @@ public class Main
     {
       Intl.setlocale (LocaleCategory.ALL, "");
 
-      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS") != "eds")
+      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS") != "no-services")
         error ("e-d-s helpers must be run in a private D-Bus session with " +
             "e-d-s services");
 
diff --git a/tests/eds/helper-prepare-aggregator.vala b/tests/eds/helper-prepare-aggregator.vala
index 1b71a6b..50bd439 100644
--- a/tests/eds/helper-prepare-aggregator.vala
+++ b/tests/eds/helper-prepare-aggregator.vala
@@ -62,7 +62,7 @@ public class Main
     {
       Intl.setlocale (LocaleCategory.ALL, "");
 
-      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS") != "eds" ||
+      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS") != "no-services" ||
           Environment.get_variable ("FOLKS_BACKENDS_ALLOWED") != "eds" ||
           Environment.get_variable ("FOLKS_PRIMARY_STORE") == null)
         error ("e-d-s helpers must be run in a private D-Bus session with " +
diff --git a/tests/lib/eds/test-case.vala b/tests/lib/eds/test-case.vala
index 456f46f..4422aad 100644
--- a/tests/lib/eds/test-case.vala
+++ b/tests/lib/eds/test-case.vala
@@ -26,8 +26,14 @@
  * A test case whose private D-Bus session contains the necessary daemons
  * for an Evolution address-book.
  *
- * FIXME: For now, this relies on running under with-session-bus-eds.sh
- * with FOLKS_BACKEND_PATH set.
+ * The EDS daemons are started through D-Bus service activation in
+ * { link TestCase.private_bus_up}, and should automatically exit when the mock
+ * D-Bus bus is torn down. All of their configuration and data storage is
+ * isolated in a temporary directory which is unique per test run.
+ *
+ * The EDS daemons are only torn down in { link TestCase.final_tear_down}, so
+ * remain running between test cases in the same test binary. Their state is
+ * soft-reset, but some state may be retained between test cases.
  */
 public class EdsTest.TestCase : Folks.TestCase
 {
@@ -42,14 +48,6 @@ public class EdsTest.TestCase : Folks.TestCase
 
   public TestCase (string name)
     {
-      /* This variable is set in the same place as the various variables we
-       * care about for sandboxing purposes, like XDG_CONFIG_HOME and
-       * DBUS_SESSION_BUS_ADDRESS. */
-      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS")
-          != "eds")
-        error ("e-d-s tests must be run in a private D-Bus session " +
-            "with e-d-s services");
-
       base (name);
 
       Environment.set_variable ("FOLKS_BACKENDS_ALLOWED", "eds", true);
@@ -59,15 +57,81 @@ public class EdsTest.TestCase : Folks.TestCase
 
   public override string? create_transient_dir ()
     {
-      /* Don't do anything. We're currently relying on
-       * being wrapped in with-session-bus-eds.sh. */
-      return null;
+      var transient = base.create_transient_dir ();
+
+      /* Evolution configuration directory. */
+      var config_dir = "%s/.config/evolution/sources".printf (transient);
+
+      if (GLib.DirUtils.create_with_parents (config_dir, 0700) != 0)
+        error ("unable to create '%s': %s",
+            config_dir, GLib.strerror (GLib.errno));
+
+      return transient;
     }
 
   public override void private_bus_up ()
     {
-      /* Don't do anything. We're currently relying on
-       * being wrapped in with-session-bus-eds.sh. */
+      base.private_bus_up ();
+
+      /* Find out the libexec directory to use. */
+      int exit_status = -1;
+      string capture_stdout = null;
+
+      try
+        {
+          Process.spawn_sync (null /* cwd */,
+              { "pkg-config", "--variable=libexecdir", "libedata-book-1.2" },
+              null /* envp */,
+              SpawnFlags.SEARCH_PATH /* flags */,
+              null /* child setup */,
+              out capture_stdout,
+              null /* do not capture stderr */,
+              out exit_status);
+
+          Process.check_exit_status (exit_status);
+        }
+      catch (GLib.Error e1)
+        {
+          error ("Error getting libexecdir from pkg-config: %s", e1.message);
+        }
+
+      var libexec = capture_stdout.strip ();
+
+      /* Create service files for the Evolution binaries. */
+      var service_file_name =
+          Path.build_filename (this.transient_dir, "dbus-1", "services",
+              "evolution-source-registry.service");
+      var service_file = ("[D-BUS Service]\n" +
+          "Name=org.gnome.evolution.dataserver.Sources3\n" +
+          "Exec=%s/evolution-source-registry\n").printf (libexec);
+
+      try
+        {
+          FileUtils.set_contents (service_file_name, service_file);
+        }
+      catch (FileError e2)
+        {
+          error ("Error creating D-Bus service file ā€˜%sā€™: %s",
+              service_file_name, e2.message);
+        }
+
+      /* Address book factory. */
+      service_file_name =
+          Path.build_filename (this.transient_dir, "dbus-1", "services",
+              "evolution-addressbook-factory.service");
+      service_file = ("[D-BUS Service]\n" +
+          "Name=org.gnome.evolution.dataserver.AddressBook6\n" +
+          "Exec=%s/evolution-addressbook-factory\n").printf (libexec);
+
+      try
+        {
+          FileUtils.set_contents (service_file_name, service_file);
+        }
+      catch (FileError e3)
+        {
+          error ("Error creating D-Bus service file ā€˜%sā€™: %s",
+              service_file_name, e3.message);
+        }
     }
 
   public override void set_up ()
diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am
index e98f35b..b74dcb4 100644
--- a/tests/tools/Makefile.am
+++ b/tests/tools/Makefile.am
@@ -1,10 +1,8 @@
 EXTRA_DIST = \
-       eds.sh \
        execute-test.sh \
        with-session-bus.sh \
        dbus-session.sh \
        manager-file.py \
-       with-session-bus-eds.sh \
        with-session-bus-tracker.sh \
        tracker.sh \
        $(NULL)


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