33
44require "test_helper"
55require "ruby_lsp/ruby_lsp_rails/server"
6- require "timeout"
76
87class ServerTest < ActiveSupport ::TestCase
98 setup do
@@ -276,36 +275,41 @@ def print_it!
276275
277276 addon_path = File . expand_path ( "my_addon.rb" )
278277 File . write ( addon_path , <<~RUBY )
278+ module Patch
279+ def setproctitle(title)
280+ $TEST_TITLE = title
281+ super
282+ end
283+
284+ Process.singleton_class.prepend(Patch)
285+ end
286+
279287 class MyServerAddon < RubyLsp::Rails::ServerAddon
280288 def name
281289 "MyAddon"
282290 end
283291
284292 def execute(request, params)
285- parent_process_title = `ps -p \# {Process.pid} -o comm=`.lines.last.strip
286293 file = "process_name.txt"
294+
287295 pid = fork do
288296 # We can't directly send a message in these tests because we're using a StringIO as stdout instead of the
289297 # actual pipe, which means that the child process doesn't have access to the same object
290- process_title = `ps -p \# {Process.pid} -o comm=`.lines.last.strip
291- File.write(file, process_title)
298+ File.write(file, $TEST_TITLE)
292299 end
293300
294301 Process.wait(pid)
295302
296- parent_process_title_changed = `ps -p \# {Process.pid} -o comm=`.lines.last.strip != parent_process_title
297- send_message({ process_name: File.read(file), changed_parent_title: parent_process_title_changed })
303+ send_message({ process_name: File.read(file) })
298304 File.delete(file)
299- rescue => e
300- send_message({ error: e.full_message })
301305 end
302306 end
303307 RUBY
304308
305309 begin
306310 @server . execute ( "server_addon/register" , server_addon_path : addon_path )
307311 @server . execute ( "server_addon/delegate" , server_addon_name : "MyAddon" , request_name : "dsl" )
308- assert_equal ( response , { process_name : "ruby-lsp-rails: #{ addon_path } " , changed_parent_title : false } )
312+ assert_equal ( response , { process_name : "ruby-lsp-rails: #{ addon_path } " } )
309313 ensure
310314 FileUtils . rm ( addon_path )
311315 end
@@ -316,38 +320,41 @@ def execute(request, params)
316320
317321 addon_path = File . expand_path ( "my_other_addon.rb" )
318322 File . write ( addon_path , <<~RUBY )
323+ module Patch
324+ def setproctitle(title)
325+ $TEST_TITLE = title
326+ super
327+ end
328+
329+ Process.singleton_class.prepend(Patch)
330+ end
331+
319332 class MyOtherServerAddon < RubyLsp::Rails::ServerAddon
320333 def name
321334 "MyOtherAddon"
322335 end
323336
324337 def execute(request, params)
325- parent_process_title = `ps -p \# {Process.pid} -o comm=`.lines.last.strip
326338 file = "other_process_name.txt"
327339 pid = fork
328340
329341 if pid
330342 Process.wait(pid)
331- parent_process_title_changed = `ps -p \# {Process.pid} -o comm=`.lines.last.strip != parent_process_title
332- send_message({ process_name: File.read(file), changed_parent_title: parent_process_title_changed })
343+ send_message({ process_name: File.read(file) })
333344 File.delete(file)
334345 else
335- process_title = `ps -p \# {Process.pid} -o comm=`.lines.last.strip
336- File.write(file, process_title)
337-
346+ File.write(file, $TEST_TITLE)
338347 # Exit from the child process or else we're stuck in the infinite loop of the server
339348 exit!
340349 end
341- rescue => e
342- send_message({ error: e.full_message })
343350 end
344351 end
345352 RUBY
346353
347354 begin
348355 @server . execute ( "server_addon/register" , server_addon_path : addon_path )
349356 @server . execute ( "server_addon/delegate" , server_addon_name : "MyOtherAddon" , request_name : "dsl" )
350- assert_equal ( response , { process_name : "ruby-lsp-rails: #{ addon_path } " , changed_parent_title : false } )
357+ assert_equal ( response , { process_name : "ruby-lsp-rails: #{ addon_path } " } )
351358 ensure
352359 FileUtils . rm ( addon_path )
353360 end
@@ -356,9 +363,7 @@ def execute(request, params)
356363 private
357364
358365 def response
359- Timeout . timeout ( 2 ) do
360- _headers , content = @stdout . string . split ( "\r \n \r \n " )
361- JSON . parse ( content , symbolize_names : true )
362- end
366+ _headers , content = @stdout . string . split ( "\r \n \r \n " )
367+ JSON . parse ( content , symbolize_names : true )
363368 end
364369end
0 commit comments