diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2013-11-15 11:29:02 +0000 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2014-02-16 23:52:31 +0000 |
commit | f36c4b74355132bb6c46aa7bf06a2f2d7bfbefbf (patch) | |
tree | 1e4f4e5f66b839a52209958f5b0a91c09d0de071 | |
parent | 0f398ab516bb662727242a753f7fd0ac4a6eb123 (diff) |
bluez: Allow persona store update poll frequency to be modified
For unit testing, it’s nice to not have to wait 5s between polled
updates of the BlueZ persona store. Add a new environment variable,
FOLKS_BLUEZ_TIMEOUT_DIVISOR, which allows the poll frequency to be
divided by the specified amount.
This should speed up the unit tests 100×.
https://bugzilla.gnome.org/show_bug.cgi?id=712274
-rw-r--r-- | backends/bluez/bluez-persona-store.vala | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/backends/bluez/bluez-persona-store.vala b/backends/bluez/bluez-persona-store.vala index af341afe..cad039a4 100644 --- a/backends/bluez/bluez-persona-store.vala +++ b/backends/bluez/bluez-persona-store.vala @@ -935,7 +935,8 @@ public class Folks.Backends.BlueZ.PersonaStore : Folks.PersonaStore PersonaStore._MAX_CONSECUTIVE_FAILURES) return; - /* Calculate the timeout. */ + /* Calculate the timeout (in milliseconds). If no divisor is applied, the + * timeout should always be a whole number of seconds. */ var timeout = uint.min (PersonaStore._TIMEOUT_MIN + (uint) Math.pow (PersonaStore._TIMEOUT_BASE, @@ -943,9 +944,23 @@ public class Folks.Backends.BlueZ.PersonaStore : Folks.PersonaStore PersonaStore._TIMEOUT_MAX); this._update_contacts_n++; + timeout *= 1000; /* convert from seconds to milliseconds */ + + /* Allow the timeout to be tweaked for testing. */ + var divisor_str = + Environment.get_variable ("FOLKS_BLUEZ_TIMEOUT_DIVISOR"); + if (divisor_str != null) + { + uint64 divisor; + if (uint64.try_parse (divisor_str, out divisor) == true) + timeout /= (uint) divisor; + } + /* Schedule the update. */ - this._update_contacts_id = Timeout.add_seconds (timeout, () => + SourceFunc fn = () => { + debug ("Scheduled update firing for BlueZ store ‘%s’.", this.id); + /* Acknowledge the source has fired. */ this._update_contacts_id = 0; @@ -976,7 +991,18 @@ public class Folks.Backends.BlueZ.PersonaStore : Folks.PersonaStore }); return false; - }); + }; + + if (timeout % 1000 == 0) + { + this._update_contacts_id = + Timeout.add_seconds (timeout / 1000, (owned) fn); + } + else + { + this._update_contacts_id = + Timeout.add (timeout, (owned) fn); + } } /** |