Skip to content

Commit f226e90

Browse files
vinistockgraphite-app[bot]
authored andcommitted
Ensure binmode and sync on LSP reporter socket (#3820)
### Motivation I believe this will close #3760 Since we're using JSON RPC to communicate test results between server and extension, we have to turn on - binmode: so that Windows preserves the `\r\n\r\n` sequences that are the key request separators - sync: so that the content of the pipe is not buffered, but immediately flushed We already do this one very stdio we use and we forgot to do the same for the socket used for tests. ### Implementation Added `binmode` and `sync` to our LSP reporter socket. ### Automated Tests I believe that turning `binmode` on our fake test client would've been enough to catch this.
1 parent 1104fdd commit f226e90

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/ruby_lsp/test_reporters/lsp_reporter.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def initialize
3535
@io = begin
3636
# The environment variable is only used for tests. The extension always writes to the temporary file
3737
if port
38-
TCPSocket.new("localhost", port)
38+
socket(port)
3939
elsif File.exist?(port_db_path)
4040
db = JSON.load_file(port_db_path)
41-
TCPSocket.new("localhost", db[Dir.pwd])
41+
socket(db[Dir.pwd])
4242
else
4343
# For tests that don't spawn the TCP server
4444
require "stringio"
@@ -209,6 +209,14 @@ def executed_under_test_runner?
209209

210210
private
211211

212+
#: (String) -> TCPSocket
213+
def socket(port)
214+
socket = TCPSocket.new("localhost", port)
215+
socket.binmode
216+
socket.sync = true
217+
socket
218+
end
219+
212220
#: (String?, **untyped) -> void
213221
def send_message(method_name, **params)
214222
json_message = { method: method_name, params: params }.to_json

test/test_reporters/minitest_reporter_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ def gather_events(uri, output: :stdout)
181181
receiver = Thread.new do
182182
socket = server.accept
183183
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
184+
socket.binmode
185+
socket.sync = true
184186

185187
loop do
186188
headers = socket.gets("\r\n\r\n")

test/test_reporters/test_unit_reporter_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def gather_events(uri, output: :stdout)
105105
receiver = Thread.new do
106106
socket = server.accept
107107
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
108+
socket.binmode
109+
socket.sync = true
108110

109111
loop do
110112
headers = socket.gets("\r\n\r\n")

0 commit comments

Comments
 (0)