summaryrefslogtreecommitdiff
path: root/sleekxmpp/test/livesocket.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-11-17 15:45:16 -0500
committerLance Stout <lancestout@gmail.com>2010-11-17 15:45:16 -0500
commitea48bb5ac58aa186c18c42c83e21a6a636bd22a9 (patch)
treed04eb4d423b9ec9c35e5636a649a0dccdd2ca862 /sleekxmpp/test/livesocket.py
parent6ee8a2980c2a7c9a8c65453b1d2c551717069ce5 (diff)
downloadslixmpp-ea48bb5ac58aa186c18c42c83e21a6a636bd22a9.tar.gz
slixmpp-ea48bb5ac58aa186c18c42c83e21a6a636bd22a9.tar.bz2
slixmpp-ea48bb5ac58aa186c18c42c83e21a6a636bd22a9.tar.xz
slixmpp-ea48bb5ac58aa186c18c42c83e21a6a636bd22a9.zip
Fixed some live stream test errors.
Added test demonstrating using multiple stream clients in a single test.
Diffstat (limited to 'sleekxmpp/test/livesocket.py')
-rw-r--r--sleekxmpp/test/livesocket.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/sleekxmpp/test/livesocket.py b/sleekxmpp/test/livesocket.py
index 5e8c5471..3e0f2135 100644
--- a/sleekxmpp/test/livesocket.py
+++ b/sleekxmpp/test/livesocket.py
@@ -7,6 +7,7 @@
"""
import socket
+import threading
try:
import queue
except ImportError:
@@ -40,6 +41,8 @@ class TestLiveSocket(object):
self.recv_buffer = []
self.recv_queue = queue.Queue()
self.send_queue = queue.Queue()
+ self.send_queue_lock = threading.Lock()
+ self.recv_queue_lock = threading.Lock()
self.is_live = True
def __getattr__(self, name):
@@ -108,7 +111,8 @@ class TestLiveSocket(object):
Placeholders. Same as for socket.recv.
"""
data = self.socket.recv(*args, **kwargs)
- self.recv_queue.put(data)
+ with self.recv_queue_lock:
+ self.recv_queue.put(data)
return data
def send(self, data):
@@ -120,7 +124,8 @@ class TestLiveSocket(object):
Arguments:
data -- String value to write.
"""
- self.send_queue.put(data)
+ with self.send_queue_lock:
+ self.send_queue.put(data)
self.socket.send(data)
# ------------------------------------------------------------------
@@ -143,3 +148,15 @@ class TestLiveSocket(object):
Placeholders, same as socket.recv()
"""
return self.recv(*args, **kwargs)
+
+ def clear(self):
+ """
+ Empty the send queue, typically done once the session has started to
+ remove the feature negotiation and log in stanzas.
+ """
+ with self.send_queue_lock:
+ for i in range(0, self.send_queue.qsize()):
+ self.send_queue.get(block=False)
+ with self.recv_queue_lock:
+ for i in range(0, self.recv_queue.qsize()):
+ self.recv_queue.get(block=False)