diff options
author | Philip Chimento <philip@endlessm.com> | 2016-07-06 17:43:08 -0700 |
---|---|---|
committer | Philip Chimento <philip@endlessm.com> | 2016-07-06 17:43:08 -0700 |
commit | b27a7533df82831aba2d7bdaf4f8ec470328c6a4 (patch) | |
tree | 98c1abcc849b831a60dba62997937073bec6d2b4 /test | |
parent | a6740546e3c94176035c99808901573c52c7293f (diff) |
Run tests with mock metrics event recorder
Since we're about to add a metrics event on unmaximize of the window, we
need to make sure it's not actually sent. In the absence of
https://phabricator.endlessm.com/T8253, the best way to do this is to set
up a mock metrics event recorder using dbusmock.
https://phabricator.endlessm.com/T12233
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am.inc | 7 | ||||
-rwxr-xr-x | test/gtester-mock-event-recorder.sh | 35 | ||||
-rwxr-xr-x | test/wait-for-service-helper.py | 26 |
3 files changed, 67 insertions, 1 deletions
diff --git a/test/Makefile.am.inc b/test/Makefile.am.inc index be76770..5a24fe7 100644 --- a/test/Makefile.am.inc +++ b/test/Makefile.am.inc @@ -79,7 +79,7 @@ AM_JS_LOG_FLAGS = \ @JASMINE_REPORT_ARGUMENT@ \ --no-config \ $(NULL) -LOG_COMPILER = gtester +LOG_COMPILER = $(top_srcdir)/test/gtester-mock-event-recorder.sh AM_LOG_FLAGS = -k --verbose EXTRA_DIST += \ test/run-with-dbus \ @@ -87,6 +87,11 @@ EXTRA_DIST += \ $(NULL) CLEANFILES += stderr.log +dist_noinst_SCRIPTS = \ + test/gtester-mock-event-recorder.sh \ + test/wait-for-service-helper.py \ + $(NULL) + # Use locally built versions of Endless-0.gir and libraries; this may need to be # changed to AM_TESTS_ENVIRONMENT in a future version of Automake # Set XDG_CONFIG_HOME so as to avoid cluttering the user's actual config diff --git a/test/gtester-mock-event-recorder.sh b/test/gtester-mock-event-recorder.sh new file mode 100755 index 0000000..dedfccc --- /dev/null +++ b/test/gtester-mock-event-recorder.sh @@ -0,0 +1,35 @@ +#!/bin/bash -e + +function finally() { + kill $DBUS_SESSION_BUS_PID +} + +# This brings up a new session bus and pretends that it is the system bus. +# dbus-launch initializes DBUS_SESSION_BUS_PID. +eval `dbus-launch` +export DBUS_SYSTEM_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS +export DBUS_SESSION_BUS_PID + +# Take down the mock DBus, no matter whether we exit successfully or +# fail the tests; think of a bash trap as a "finally" clause. +trap finally EXIT + +# Start the mock service and add its methods. +python3 -m dbusmock --system \ + com.endlessm.Metrics \ + /com/endlessm/Metrics \ + com.endlessm.Metrics.EventRecorderServer & + +# Wait for the service to come up +python3 `dirname $0`/wait-for-service-helper.py + +gdbus call --system \ + -d com.endlessm.Metrics \ + -o /com/endlessm/Metrics \ + -m org.freedesktop.DBus.Mock.AddMethods \ + com.endlessm.Metrics.EventRecorderServer \ + '[("RecordSingularEvent", "uayxbv", "", ""), + ("RecordAggregateEvent", "uayxxbv", "", ""), + ("RecordEventSequence", "uaya(xbv)", "", "")]' + +gtester "$@" diff --git a/test/wait-for-service-helper.py b/test/wait-for-service-helper.py new file mode 100755 index 0000000..97d0c00 --- /dev/null +++ b/test/wait-for-service-helper.py @@ -0,0 +1,26 @@ +# Copyright 2014, 2015, 2016 Endless Mobile, Inc. + +import sys +from gi.repository import GLib, Gio + +DBUS_NAME = 'com.endlessm.Metrics' + + +def on_name_appeared(connection, name, owner): + print(DBUS_NAME, 'appeared') + Gio.bus_unwatch_name(watcher_id) + loop.quit() + + +def on_timeout(): + print('Timed out') + Gio.bus_unwatch_name(watcher_id) + sys.exit(1) + +print('Watching for name', DBUS_NAME) +watcher_id = Gio.bus_watch_name(Gio.BusType.SYSTEM, DBUS_NAME, + Gio.BusNameWatcherFlags.NONE, on_name_appeared, None) +GLib.timeout_add_seconds(5, on_timeout) + +loop = GLib.MainLoop() +loop.run() |