changeset 7912:1c6ef9113556 v7.4.1252

commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 3 22:20:29 2016 +0100 patch 7.4.1252 Problem: The channel test server may receive two messages concatenated. Solution: Split the messages.
author Christian Brabandt <cb@256bit.org>
date Wed, 03 Feb 2016 22:30:04 +0100
parents fd07525103a2
children a3d82880fca7
files src/testdir/test_channel.py src/version.c
diffstat 2 files changed, 62 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_channel.py
+++ b/src/testdir/test_channel.py
@@ -45,56 +45,69 @@ class ThreadedTCPRequestHandler(socketse
                 print("=== socket closed ===")
                 break
             print("received: {}".format(data))
-            try:
-                decoded = json.loads(data)
-            except ValueError:
-                print("json decoding failed")
-                decoded = [-1, '']
+
+            # We may receive two messages at once. Take the part up to the
+            # matching "]" (recognized by finding "][").
+            while data != '':
+                splitidx = data.find('][')
+                if splitidx < 0:
+                     todo = data
+                     data = ''
+                else:
+                     todo = data[:splitidx + 1]
+                     data = data[splitidx + 1:]
+                     print("using: {}".format(todo))
+
+                try:
+                    decoded = json.loads(todo)
+                except ValueError:
+                    print("json decoding failed")
+                    decoded = [-1, '']
 
-            # Send a response if the sequence number is positive.
-            if decoded[0] >= 0:
-                if decoded[1] == 'hello!':
-                    # simply send back a string
-                    response = "got it"
-                elif decoded[1] == 'make change':
-                    # Send two ex commands at the same time, before replying to
-                    # the request.
-                    cmd = '["ex","call append(\\"$\\",\\"added1\\")"]'
-                    cmd += '["ex","call append(\\"$\\",\\"added2\\")"]'
-                    print("sending: {}".format(cmd))
-                    thesocket.sendall(cmd.encode('utf-8'))
-                    response = "ok"
-                elif decoded[1] == 'eval-works':
-                    # Send an eval request.  We ignore the response.
-                    cmd = '["eval","\\"foo\\" . 123", -1]'
-                    print("sending: {}".format(cmd))
-                    thesocket.sendall(cmd.encode('utf-8'))
-                    response = "ok"
-                elif decoded[1] == 'eval-fails':
-                    # Send an eval request that will fail.
-                    cmd = '["eval","xxx", -2]'
-                    print("sending: {}".format(cmd))
-                    thesocket.sendall(cmd.encode('utf-8'))
-                    response = "ok"
-                elif decoded[1] == 'eval-result':
-                    # Send back the last received eval result.
-                    response = last_eval
-                elif decoded[1] == '!quit!':
-                    # we're done
-                    sys.exit(0)
-                elif decoded[1] == '!crash!':
-                    # Crash!
-                    42 / 0
-                else:
-                    response = "what?"
+                # Send a response if the sequence number is positive.
+                if decoded[0] >= 0:
+                    if decoded[1] == 'hello!':
+                        # simply send back a string
+                        response = "got it"
+                    elif decoded[1] == 'make change':
+                        # Send two ex commands at the same time, before replying to
+                        # the request.
+                        cmd = '["ex","call append(\\"$\\",\\"added1\\")"]'
+                        cmd += '["ex","call append(\\"$\\",\\"added2\\")"]'
+                        print("sending: {}".format(cmd))
+                        thesocket.sendall(cmd.encode('utf-8'))
+                        response = "ok"
+                    elif decoded[1] == 'eval-works':
+                        # Send an eval request.  We ignore the response.
+                        cmd = '["eval","\\"foo\\" . 123", -1]'
+                        print("sending: {}".format(cmd))
+                        thesocket.sendall(cmd.encode('utf-8'))
+                        response = "ok"
+                    elif decoded[1] == 'eval-fails':
+                        # Send an eval request that will fail.
+                        cmd = '["eval","xxx", -2]'
+                        print("sending: {}".format(cmd))
+                        thesocket.sendall(cmd.encode('utf-8'))
+                        response = "ok"
+                    elif decoded[1] == 'eval-result':
+                        # Send back the last received eval result.
+                        response = last_eval
+                    elif decoded[1] == '!quit!':
+                        # we're done
+                        sys.exit(0)
+                    elif decoded[1] == '!crash!':
+                        # Crash!
+                        42 / 0
+                    else:
+                        response = "what?"
 
-                encoded = json.dumps([decoded[0], response])
-                print("sending: {}".format(encoded))
-                thesocket.sendall(encoded.encode('utf-8'))
+                    encoded = json.dumps([decoded[0], response])
+                    print("sending: {}".format(encoded))
+                    thesocket.sendall(encoded.encode('utf-8'))
 
-            # Negative numbers are used for "eval" responses.
-            elif decoded[0] < 0:
-                last_eval = decoded
+                # Negative numbers are used for "eval" responses.
+                elif decoded[0] < 0:
+                    last_eval = decoded
 
         thesocket = None
 
--- a/src/version.c
+++ b/src/version.c
@@ -743,6 +743,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1252,
+/**/
     1251,
 /**/
     1250,