summaryrefslogtreecommitdiff
path: root/Tests/Server
diff options
context:
space:
mode:
authorJustin Berger <j.david.berger@gmail.com>2017-11-20 08:31:56 -0700
committerJustin Berger <jberger@melco.com>2017-11-29 12:35:42 -0700
commit9af5f6727716ab8b9b61815ec67e1c4ffe1213b6 (patch)
treebed835b1332ed7ff1306173ede449b723e9ff7cc /Tests/Server
parentc7f175d637f9755ab53668f1c0f937e5c4cbf067 (diff)
downloadcmake-9af5f6727716ab8b9b61815ec67e1c4ffe1213b6.tar.gz
test: Updated server test harness to try to cause fragmentation
Diffstat (limited to 'Tests/Server')
-rw-r--r--Tests/Server/cmakelib.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/Tests/Server/cmakelib.py b/Tests/Server/cmakelib.py
index 39e3618405..6e8761aab9 100644
--- a/Tests/Server/cmakelib.py
+++ b/Tests/Server/cmakelib.py
@@ -100,6 +100,14 @@ def waitForRawMessage(cmakeCommand):
return jsonPayload
stdoutdata = stdoutdata[(end+len(']== "CMake Server" ==]')):]
+# Python2 has no problem writing the output of encodes directly,
+# but Python3 returns only 'int's for encode and so must be turned
+# into bytes. We use the existence of 'to_bytes' on an int to
+# determine which behavior is appropriate. It might be more clear
+# to do this in the code which uses the flag, but introducing
+# this lookup cost at every byte sent isn't ideal.
+has_to_bytes = "to_bytes" in dir(10)
+
def writeRawData(cmakeCommand, content):
writeRawData.counter += 1
payload = """
@@ -116,7 +124,25 @@ def writeRawData(cmakeCommand, content):
if print_communication:
printClient(content, "(Use \\r\\n:", rn, ")")
- cmakeCommand.write(payload.encode('utf-8'))
+ # To stress test how cmake deals with fragmentation in the
+ # communication channel, we send only one byte at a time.
+ # Certain communication methods / platforms might still buffer
+ # it all into one message since its so close together, but in
+ # general this will catch places where we assume full buffers
+ # come in all at once.
+ encoded_payload = payload.encode('utf-8')
+
+ # Python version 3+ can't write ints directly; but 'to_bytes'
+ # for int was only added in python 3.2. If this is a 3+ version
+ # of python without that conversion function; just write the whole
+ # thing out at once.
+ if sys.version_info[0] > 2 and not has_to_bytes:
+ cmakeCommand.write(encoded_payload)
+ else:
+ for c in encoded_payload:
+ if has_to_bytes:
+ c = c.to_bytes(1, byteorder='big')
+ cmakeCommand.write(c)
writeRawData.counter = 0