[clang-tools-extra] d0beda1 - [clangd] Improve remote-index test
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 2 01:57:42 PST 2020
Author: Kirill Bobyrev
Date: 2020-11-02T10:55:17+01:00
New Revision: d0beda1b66617cda8a1f54978fca72832496b1fb
URL: https://github.com/llvm/llvm-project/commit/d0beda1b66617cda8a1f54978fca72832496b1fb
DIFF: https://github.com/llvm/llvm-project/commit/d0beda1b66617cda8a1f54978fca72832496b1fb.diff
LOG: [clangd] Improve remote-index test
Introduce a separate thread that will kill `clangd-index-server` after 10 seconds regardless. This helps shut down the test if the server hangs and `stderr.readline()` does not contain inititalizatiton message. It prevents "necessary" waiting delay for the server warm-up and only introduces additional delay if the test fails.
It also makes use of `subprocess.Popen.kill()` which is a portable way of handling process shutdown and avoids using signals.
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D90590
Added:
Modified:
clang-tools-extra/clangd/test/remote-index/pipeline_helper.py
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/test/remote-index/pipeline_helper.py b/clang-tools-extra/clangd/test/remote-index/pipeline_helper.py
index 99380c445be6..d062e29bd8ee 100644
--- a/clang-tools-extra/clangd/test/remote-index/pipeline_helper.py
+++ b/clang-tools-extra/clangd/test/remote-index/pipeline_helper.py
@@ -14,7 +14,13 @@
from socket import socket
import sys
import time
-import signal
+import threading
+
+
+def kill_server_after_delay(server_process):
+ time.sleep(10)
+ if server_process.poll() is None:
+ server_process.kill()
def main():
@@ -36,11 +42,17 @@ def main():
],
stderr=subprocess.PIPE)
+ # This will kill index_server_process if it hangs without printing init
+ # message.
+ shutdown_thread = threading.Thread(
+ target=kill_server_after_delay, args=(index_server_process,))
+ shutdown_thread.daemon = True
+ shutdown_thread.start()
+
# Wait for the server to warm-up.
- time.sleep(4)
found_init_message = False
- for line in index_server_process.stderr:
- if b'Server listening' in line:
+ while index_server_process.poll() is None:
+ if b'Server listening' in index_server_process.stderr.readline():
found_init_message = True
break
@@ -56,7 +68,7 @@ def main():
stdin=in_file)
clangd_process.wait()
- os.kill(index_server_process.pid, signal.SIGINT)
+ index_server_process.kill()
if __name__ == '__main__':
More information about the cfe-commits
mailing list