Permalink
Browse files

Add a test for sending stanzas within a terminate message.

Make sure that <body type='terminate'><presence/></body> sends
<presence/> to the server before terminating the connection.
  • Loading branch information...
1 parent d26c7b8 commit e10d0473c70f402e45f2d071c8cad6a3e687fcce @zewt zewt committed Apr 29, 2011
Showing with 38 additions and 1 deletion.
  1. +38 −1 tests/xep124.py
View
@@ -7,7 +7,7 @@
from twisted.words.protocols.jabber import jid
from twisted.internet import defer, protocol, reactor, task
from twisted.application import internet, service
-from twisted.words.xish import domish, xpath
+from twisted.words.xish import domish, xpath, xmlstream
from twisted.python import log
@@ -230,6 +230,43 @@ def _testSessionCreate(res):
@defer.inlineCallbacks
+ def testStreamFlushOnError(self):
+ """
+ Test that messages included in a <body type='terminate'> message from the
+ client are sent to the server before terminating.
+ """
+ yield self.connect(self.get_body_node(connect=True))
+
+ # Set got_testing_node to true when the XMPP server receives the <testing/> we
+ # send below.
+ got_testing_node = [False] # work around Python's 2.6 lack of nonlocal
+ wait = defer.Deferred()
+ def received_testing(a):
+ got_testing_node[0] = True
+ wait.callback(True)
+ self.server_protocol.addObserver("/testing", received_testing)
+
+ # Ensure that we always remove the received_testing listener.
+ try:
+ # Send <body type='terminate'><testing/></body>. This should result in a
+ # HTTPBNetworkTerminated exception.
+ try:
+ yield self.proxy.send(self.get_body_node(ext='<testing/>', type='terminate'))
+ except httpb_client.HTTPBNetworkTerminated as e:
+ self.failUnlessEqual(e.body_tag.getAttribute('condition', None), None)
+
+ # Wait until <testing/> is actually received by the XMPP server. The previous
+ # request completing only means that the proxy has received the stanza, not that
+ # it's been delivered to the XMPP server.
+ yield wait
+
+ finally:
+ self.server_protocol.removeObserver("/testing", received_testing)
+
+ # This should always be true, or we'd never have woken up from wait.
+ self.failUnless(got_testing_node[0])
+
+ @defer.inlineCallbacks
def testTerminateRace(self):
"""Test that buffered messages are flushed when the connection is terminated."""
yield self.connect(self.get_body_node(connect=True))

0 comments on commit e10d047

Please sign in to comment.