Bug 1469054 - Make sure that the adb.py sends all data. r?jdescottes draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 09 Aug 2018 14:27:57 +0900
changeset 827787 e8e8383858fd0af4f69d86355c4a0563d721451d
parent 827786 1423445d7a8d2e9bdd8b254c4c2b1a1b06b40282
child 827788 ca86398256fb76ecaae17485ac1c1202a4710cf1
child 827791 5711a5c7f5b30e2b0d0ee2ed6077b2032039a5e0
push id118583
push userhikezoe@mozilla.com
push dateThu, 09 Aug 2018 06:03:03 +0000
reviewersjdescottes
bugs1469054
milestone63.0a1
Bug 1469054 - Make sure that the adb.py sends all data. r?jdescottes It seems that, on chaos mode, we can't receive whole data set at once, i.e. sending data will be split into some chunks, so the adb mock should check the sent data length and if there remains still data which has to be sent, we have to continue sending the rest of the data. MozReview-Commit-ID: 5jeEH8KpNNW
devtools/shared/adb/test/adb.py
--- a/devtools/shared/adb/test/adb.py
+++ b/devtools/shared/adb/test/adb.py
@@ -15,19 +15,27 @@ import SocketServer
 import sys
 import thread
 
 HOST = '127.0.0.1'
 PORT = 5037
 
 class ADBServer(SocketServer.BaseRequestHandler):
     def sendData(self, data):
-        self.request.send('OKAY')
-        self.request.send('%04x' % len(data))
-        self.request.send(data)
+        header = 'OKAY%04x' % len(data)
+        all_data = header + data
+        total_length = len(all_data)
+        sent_length = 0
+        # Make sure send all data to the client.
+        # Though the data length here is pretty small but sometimes when the
+        # client is on heavy load (e.g. MOZ_CHAOSMODE) we can't send the whole
+        # data at once.
+        while sent_length < total_length:
+            sent = self.request.send(all_data[sent_length:])
+            sent_length = sent_length + sent
 
     def handle(self):
         while True:
             data = self.request.recv(4096)
             if 'kill-server' in data:
                 def shutdown(server):
                     server.shutdown()
                     thread.exit()