forked from OSchip/llvm-project
[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
This commit is contained in:
parent
7706c3022e
commit
d0beda1b66
|
@ -14,7 +14,13 @@ import subprocess
|
|||
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__':
|
||||
|
|
Loading…
Reference in New Issue