[telepathy-gabble/master] fd.o #25296: break race in test-send-file-provide-immediately.py and test-send-file-wait-to-provide.py

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Dec 4 08:19:51 PST 2009


bytestream.wait_bytestream_closed() may involve waiting for a socket
disconnection (if using SOCKS5). Waiting for the TransferredBytesChanged
before calling wait_bytestream_closed is racy as the ordering of socket and
D-Bus events is not garanteed.
We break this race by waiting for those signals *after* we called
wait_bytestream_closed(). As the TransferredBytesChanged signals are
manually catched using connect_to_signal we'll only wait for them if needed.
---
 .../twisted/file-transfer/file_transfer_helper.py  |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/twisted/file-transfer/file_transfer_helper.py b/tests/twisted/file-transfer/file_transfer_helper.py
index 5c4119f..039d99e 100644
--- a/tests/twisted/file-transfer/file_transfer_helper.py
+++ b/tests/twisted/file-transfer/file_transfer_helper.py
@@ -423,13 +423,6 @@ class SendFileTest(FileTransferTest):
 
         assert data == self.file.data[self.file.offset:]
 
-        # If not all the bytes transferred have been announced using
-        # TransferredBytesChanged, wait for them
-        while self.count < to_receive:
-            self.q.expect('dbus-signal', signal='TransferredBytesChanged')
-
-        assert self.count == to_receive
-
         if self.completed:
             # FileTransferStateChanged has already been received
             waiting = []
@@ -438,6 +431,13 @@ class SendFileTest(FileTransferTest):
 
         events = self.bytestream.wait_bytestream_closed(waiting)
 
+        # If not all the bytes transferred have been announced using
+        # TransferredBytesChanged, wait for them
+        while self.count < to_receive:
+            self.q.expect('dbus-signal', signal='TransferredBytesChanged')
+
+        assert self.count == to_receive
+
         if len(waiting) > 1:
             state, reason = events[0].args
             assert state == cs.FT_STATE_COMPLETED
-- 
1.5.6.5



More information about the telepathy-commits mailing list