3
3
4
4
require "test_helper"
5
5
require "ruby_lsp/ruby_lsp_rails/server"
6
- require "timeout"
7
6
8
7
class ServerTest < ActiveSupport ::TestCase
9
8
setup do
@@ -276,36 +275,41 @@ def print_it!
276
275
277
276
addon_path = File . expand_path ( "my_addon.rb" )
278
277
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
+
279
287
class MyServerAddon < RubyLsp::Rails::ServerAddon
280
288
def name
281
289
"MyAddon"
282
290
end
283
291
284
292
def execute(request, params)
285
- parent_process_title = `ps -p \# {Process.pid} -o comm=`.lines.last.strip
286
293
file = "process_name.txt"
294
+
287
295
pid = fork do
288
296
# We can't directly send a message in these tests because we're using a StringIO as stdout instead of the
289
297
# 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)
292
299
end
293
300
294
301
Process.wait(pid)
295
302
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) })
298
304
File.delete(file)
299
- rescue => e
300
- send_message({ error: e.full_message })
301
305
end
302
306
end
303
307
RUBY
304
308
305
309
begin
306
310
@server . execute ( "server_addon/register" , server_addon_path : addon_path )
307
311
@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 } " } )
309
313
ensure
310
314
FileUtils . rm ( addon_path )
311
315
end
@@ -316,38 +320,41 @@ def execute(request, params)
316
320
317
321
addon_path = File . expand_path ( "my_other_addon.rb" )
318
322
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
+
319
332
class MyOtherServerAddon < RubyLsp::Rails::ServerAddon
320
333
def name
321
334
"MyOtherAddon"
322
335
end
323
336
324
337
def execute(request, params)
325
- parent_process_title = `ps -p \# {Process.pid} -o comm=`.lines.last.strip
326
338
file = "other_process_name.txt"
327
339
pid = fork
328
340
329
341
if pid
330
342
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) })
333
344
File.delete(file)
334
345
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)
338
347
# Exit from the child process or else we're stuck in the infinite loop of the server
339
348
exit!
340
349
end
341
- rescue => e
342
- send_message({ error: e.full_message })
343
350
end
344
351
end
345
352
RUBY
346
353
347
354
begin
348
355
@server . execute ( "server_addon/register" , server_addon_path : addon_path )
349
356
@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 } " } )
351
358
ensure
352
359
FileUtils . rm ( addon_path )
353
360
end
@@ -356,9 +363,7 @@ def execute(request, params)
356
363
private
357
364
358
365
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 )
363
368
end
364
369
end
0 commit comments