diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2013-11-18 23:24:27 +0000 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2014-02-16 23:52:32 +0000 |
commit | 3acaaeeb997f1240011806fabda95c17cbe0df1a (patch) | |
tree | d6f93123157806687b2d0bc67bfbedde84782219 | |
parent | 336b51e55633b9791b1bfc903bb40b48b2fa5b81 (diff) |
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).
-rw-r--r-- | tests/eds/Makefile.am | 12 | ||||
-rw-r--r-- | tests/eds/helper-create-many-contacts.vala | 2 | ||||
-rw-r--r-- | tests/eds/helper-delete-contacts.vala | 2 | ||||
-rw-r--r-- | tests/eds/helper-prepare-aggregator.vala | 2 | ||||
-rw-r--r-- | tests/lib/eds/test-case.vala | 94 | ||||
-rw-r--r-- | tests/tools/Makefile.am | 2 | ||||
-rw-r--r-- | tests/tools/eds.sh | 35 | ||||
-rwxr-xr-x | 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 687ebe62..29f7bb33 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 000348ff..bbeb1847 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 46d2e35c..816767da 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 1b71a6bb..50bd439f 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 456f46f4..4422aad9 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 e98f35b0..b74dcb4c 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) diff --git a/tests/tools/eds.sh b/tests/tools/eds.sh deleted file mode 100644 index e4821446..00000000 --- a/tests/tools/eds.sh +++ /dev/null @@ -1,35 +0,0 @@ -# -# Helper functions to start your own e-d-s instance. This depends -# on you having your own D-Bus session bus started (first). -# -# -# Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. - -eds_tmpdir=$(mktemp -d) -libexec=$(pkg-config --variable=libexecdir libedata-book-1.2) - -cur_dir=`dirname $0` - -eds_init_settings () { - export XDG_DATA_HOME=$eds_tmpdir/.local - export XDG_CACHE_HOME=$eds_tmpdir/.cache - export XDG_CONFIG_HOME=$eds_tmpdir/.config - mkdir -p $XDG_CONFIG_HOME/evolution/sources -} - -eds_start () { - $libexec/evolution-source-registry > /dev/null 2>&1 & - $libexec/evolution-addressbook-factory --wait-for-client > /dev/null 2>&1 & - sleep 2 -} - -# This should be called on INT TERM and EXIT -eds_stop () { - rm -rf $eds_tmpdir - rm -rf $eds_tmpdir -} - diff --git a/tests/tools/with-session-bus-eds.sh b/tests/tools/with-session-bus-eds.sh deleted file mode 100755 index 02f50af2..00000000 --- a/tests/tools/with-session-bus-eds.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# with-session-bus-eds.sh - run a program with a temporary D-Bus session daemon -# -# interesting bits have been move into dbus to permit reusability -# -# Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. - - -cur_dir=`dirname $0` - -. $cur_dir"/dbus-session.sh" -. $cur_dir"/eds.sh" - -dbus_parse_args $@ -while test "z$1" != "z--"; do - shift -done -shift -if test "z$1" = "z"; then dbus_usage; fi - -cleanup () -{ - eds_stop - dbus_stop -} - -trap cleanup INT HUP TERM - -eds_init_settings -dbus_init 0 - -dbus_start -eds_start - -e=0 - -FOLKS_TESTS_SANDBOXED_DBUS=eds -export FOLKS_TESTS_SANDBOXED_DBUS - -$cur_dir"/execute-test.sh" "$@" || e=$? - -trap - INT HUP TERM -cleanup - -exit $e |