summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/conn-slacker.c41
-rw-r--r--tests/twisted/device-idleness.py16
2 files changed, 39 insertions, 18 deletions
diff --git a/src/conn-slacker.c b/src/conn-slacker.c
index 6d7aca8eb..fe17ece35 100644
--- a/src/conn-slacker.c
+++ b/src/conn-slacker.c
@@ -26,12 +26,28 @@
#include "util.h"
static void
+conn_slacker_send_command (
+ GabbleConnection *conn,
+ const gchar *command)
+{
+ LmMessage *stanza = lm_message_build_with_sub_type (NULL,
+ LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET,
+ '(', "query", "",
+ '@', "xmlns", NS_GOOGLE_QUEUE,
+ '(', command, "", ')',
+ ')',
+ NULL);
+
+ _gabble_connection_send_with_reply (conn, stanza, NULL, NULL, NULL, NULL);
+ lm_message_unref (stanza);
+}
+
+
+static void
conn_slacker_update_inactivity (
GabbleConnection *conn,
gboolean is_inactive)
{
- LmMessage *command;
-
if (DEBUGGING)
{
gchar *jid = gabble_connection_get_full_jid (conn);
@@ -43,15 +59,18 @@ conn_slacker_update_inactivity (
g_free (jid);
}
- command = lm_message_build_with_sub_type (NULL,
- LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET,
- '(', "query", "",
- '@', "xmlns", NS_GOOGLE_QUEUE,
- '(', (is_inactive ? "enable" : "disable"), "", ')',
- ')',
- NULL);
- _gabble_connection_send_with_reply (conn, command, NULL, NULL, NULL, NULL);
- lm_message_unref (command);
+ if (is_inactive)
+ {
+ conn_slacker_send_command (conn, "enable");
+ }
+ else
+ {
+ /* It seems that disabling the queue doesn't flush it, so we need to
+ * explicitly flush it too.
+ */
+ conn_slacker_send_command (conn, "disable");
+ conn_slacker_send_command (conn, "flush");
+ }
}
static void
diff --git a/tests/twisted/device-idleness.py b/tests/twisted/device-idleness.py
index 8d5bb6259..48e9e1069 100644
--- a/tests/twisted/device-idleness.py
+++ b/tests/twisted/device-idleness.py
@@ -51,10 +51,10 @@ class FakeMCE(dbus.service.Object):
self.inactive = new_value
-def expect_command(q, inactive):
+def expect_command(q, name):
event = q.expect('stream-iq', query_name='query', query_ns=ns.GOOGLE_QUEUE)
command = event.query.firstChildElement()
- assertEquals('enable' if inactive else 'disable', command.name)
+ assertEquals(name, command.name)
def test(q, bus, conn, stream, initially_inactive=False):
mce = FakeMCE(q, bus, initially_inactive)
@@ -63,20 +63,22 @@ def test(q, bus, conn, stream, initially_inactive=False):
q.expect('get-inactivity-called')
if initially_inactive:
- expect_command(q, True)
+ expect_command(q, 'enable')
else:
mce.InactivityChanged(True)
- expect_command(q, True)
+ expect_command(q, 'enable')
mce.InactivityChanged(False)
- expect_command(q, False)
+ expect_command(q, 'disable')
+ expect_command(q, 'flush')
# Just cycle it a bit to check it doesn't blow up slowly
mce.InactivityChanged(True)
- expect_command(q, True)
+ expect_command(q, 'enable')
mce.InactivityChanged(False)
- expect_command(q, False)
+ expect_command(q, 'disable')
+ expect_command(q, 'flush')
mce.remove_from_connection()