summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorJustin Berger <j.david.berger@gmail.com>2017-11-20 15:31:56 (GMT)
committerJustin Berger <jberger@melco.com>2017-11-29 19:35:42 (GMT)
commit9af5f6727716ab8b9b61815ec67e1c4ffe1213b6 (patch)
treebed835b1332ed7ff1306173ede449b723e9ff7cc /Tests
parentc7f175d637f9755ab53668f1c0f937e5c4cbf067 (diff)
downloadCMake-9af5f6727716ab8b9b61815ec67e1c4ffe1213b6.zip
CMake-9af5f6727716ab8b9b61815ec67e1c4ffe1213b6.tar.gz
CMake-9af5f6727716ab8b9b61815ec67e1c4ffe1213b6.tar.bz2
test: Updated server test harness to try to cause fragmentation
Diffstat (limited to 'Tests')
-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 39e3618..6e8761a 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