summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-12-01 13:15:40 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-12-01 13:15:51 (GMT)
commit3c6dab8b72c1a0736a5ddb4c470cf7b7b544ceb1 (patch)
tree9b8454f2ba9a702d01fe311cc8402235f3b3b92c
parent006a4956a296ed5a9c01fbd5c242c240dc3aac99 (diff)
parent9af5f6727716ab8b9b61815ec67e1c4ffe1213b6 (diff)
downloadCMake-3c6dab8b72c1a0736a5ddb4c470cf7b7b544ceb1.zip
CMake-3c6dab8b72c1a0736a5ddb4c470cf7b7b544ceb1.tar.gz
CMake-3c6dab8b72c1a0736a5ddb4c470cf7b7b544ceb1.tar.bz2
Merge topic 'fix-cmake-server-bad-buffering-test'
9af5f672 test: Updated server test harness to try to cause fragmentation Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1508
-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