Skip to content

Commit 6dbbe97

Browse files
st0012nirvdrum
andcommitted
Wait for test process to die before closing IOs
Co-authored-by: Kevin Menard <[email protected]>
1 parent 21ef949 commit 6dbbe97

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

test/integration_test.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,22 @@ def teardown
4141
make_request("shutdown")
4242
send_request("exit")
4343

44-
# Make sure IOs are closed
45-
@stdin.close
46-
@stdout.close
47-
@stderr.close
44+
# Give the server some time to process the "shutdown" and "exit" messages before
45+
# closing the streams. Otherwise, it's possible the server misses one or both of them
46+
# depending on what it's currently processing. This is wrapped in a timeout in case
47+
# the server fails to process the messages.
48+
begin
49+
Timeout.timeout(60) do
50+
sleep(0.010) while @wait_thr.alive?
51+
end
52+
rescue Timeout::Error
53+
raise "The LSP server failed to shut down cleanly."
54+
ensure
55+
# Make sure IOs are closed
56+
@stdin.close
57+
@stdout.close
58+
@stderr.close
59+
end
4860

4961
# Make sure the exit status is zero
5062
assert_equal(0, @wait_thr.value)

0 commit comments

Comments
 (0)