diff options
author | Thomas Bernard <tbernard@go-engineering.de> | 2020-08-08 14:28:46 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-08-18 13:16:18 (GMT) |
commit | 116b06870d1645df63a4df91bb29d03bdafc5c50 (patch) | |
tree | d349be338211eb981409497f90a504ca9033835b /Tests/RunCMake/ExternalProject/DownloadServer.py | |
parent | f24e34975a34c7cad6422a517a59c310d6ea00c9 (diff) | |
download | CMake-116b06870d1645df63a4df91bb29d03bdafc5c50.zip CMake-116b06870d1645df63a4df91bb29d03bdafc5c50.tar.gz CMake-116b06870d1645df63a4df91bb29d03bdafc5c50.tar.bz2 |
ExternalProject: add INACTIVITY_TIMEOUT argument
In order to abort transfers on slow connections the ExternalProject
command support passing the INACTIVITY_TIMEOUT argument.
Fixes: #20992
Diffstat (limited to 'Tests/RunCMake/ExternalProject/DownloadServer.py')
-rw-r--r-- | Tests/RunCMake/ExternalProject/DownloadServer.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Tests/RunCMake/ExternalProject/DownloadServer.py b/Tests/RunCMake/ExternalProject/DownloadServer.py new file mode 100644 index 0000000..ac0769f --- /dev/null +++ b/Tests/RunCMake/ExternalProject/DownloadServer.py @@ -0,0 +1,42 @@ +from http.server import HTTPServer, BaseHTTPRequestHandler +import argparse +import time +import subprocess +import sys +import os +args = None +outerthread = None + +class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): + def do_GET(self): + self.send_response(200) + self.end_headers() + data = b'D' + + if args.speed_limit: + slow_deadline = time.time()+args.limit_duration + + while time.time() < slow_deadline: + self.wfile.write(data) + if args.speed_limit: + time.sleep(1.1) + + data = data * 100 + self.wfile.write(data) + self.close_connection = True + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--speed_limit', help='transfer rate limitation', action='store_true',default=False) + parser.add_argument('--limit_duration', help='duration of the transfer rate limitation',default=1, type=float) + parser.add_argument('--file', help='file to write the url to connect to') + parser.add_argument('--subprocess', action='store_true') + args = parser.parse_args() + if not args.subprocess: + subprocess.Popen([sys.executable]+sys.argv+['--subprocess'],stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL,stdout=subprocess.DEVNULL) + else: + httpd = HTTPServer(('localhost', 0), SimpleHTTPRequestHandler) + with open(args.file,"w") as f: + f.write('http://localhost:{}/test'.format(httpd.socket.getsockname()[1])) + httpd.handle_request() + os.remove(args.file) |