Skip to content

Commit 3b77dc8

Browse files
committed
Refactor loading umbrella apps test
1 parent cadd374 commit 3b77dc8

File tree

2 files changed

+77
-57
lines changed

2 files changed

+77
-57
lines changed

apps/language_server/lib/language_server/protocol.ex

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,6 @@ defmodule ElixirLS.LanguageServer.Protocol do
191191
end
192192
end
193193

194-
defmacro shutdown_req(id) do
195-
quote do
196-
request(unquote(id), "shutdown", %{})
197-
end
198-
end
199-
200-
defmacro exit_req(id) do
201-
quote do
202-
request(unquote(id), "exit", %{})
203-
end
204-
end
205-
206194
# Other utilities
207195

208196
defmacro range(start_line, start_character, end_line, end_character) do

apps/language_server/test/server_test.exs

Lines changed: 77 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ defmodule ElixirLS.LanguageServer.ServerTest do
2020
SourceFile.path_to_uri(File.cwd!())
2121
end
2222

23-
setup do
24-
{:ok, server} = Server.start_link()
25-
{:ok, packet_capture} = PacketCapture.start_link(self())
26-
Process.group_leader(server, packet_capture)
27-
28-
{:ok, %{server: server}}
23+
setup context do
24+
unless context[:skip_server] do
25+
server = start_supervised!({Server, nil})
26+
packet_capture = start_supervised!({PacketCapture, self()})
27+
Process.group_leader(server, packet_capture)
28+
{:ok, %{server: server}}
29+
else
30+
:ok
31+
end
2932
end
3033

3134
test "textDocument/didChange when the client hasn't claimed ownership with textDocument/didOpen",
@@ -337,55 +340,84 @@ defmodule ElixirLS.LanguageServer.ServerTest do
337340
end)
338341
end
339342

340-
test "loading of umbrella app dependencies", %{server: server} do
343+
@tag :skip_server
344+
test "loading of umbrella app dependencies" do
341345
in_fixture(__DIR__, "umbrella", fn ->
342346
# We test this by opening the umbrella project twice.
343347
# First to compile the applications and build the cache.
344348
# Second time to see if loads modules
345-
initialize(server)
349+
with_new_server(fn server ->
350+
initialize(server)
351+
wait_until_compiled(server)
352+
end)
346353

347-
# Upon first vist, server complies and loads all umbrella applications and modules
348-
Process.sleep(1_500)
349-
350-
Server.receive_packet(server, shutdown_req(2))
351-
assert response(2, nil) = assert_receive(%{"id" => 2}, 5000)
352-
Server.receive_packet(server, exit_req(3))
353-
354-
Process.sleep(500)
355354
# unload App2.Foo
356355
purge([App2.Foo])
357356

358-
# Upon re-visiting, server does not attempt to compile umbrella applications
359-
initialize(server)
360-
Process.sleep(1_500)
357+
# re-visiting the same project
358+
with_new_server(fn server ->
359+
initialize(server)
360+
wait_until_compiled(server)
361361

362-
file_path = "apps/app1/lib/bar.ex"
363-
uri = SourceFile.path_to_uri(file_path)
362+
file_path = "apps/app1/lib/bar.ex"
363+
uri = SourceFile.path_to_uri(file_path)
364364

365-
code = """
366-
defmodule Bar do
367-
def fnuc, do: App2.Fo
368-
#____________________^
369-
end
370-
"""
371-
372-
Server.receive_packet(server, did_open(uri, "elixir", 1, code))
373-
Server.receive_packet(server, completion_req(2, uri, 1, 23))
374-
375-
resp = assert_receive(%{"id" => 2}, 5000)
376-
377-
assert response(2, %{
378-
"isIncomplete" => false,
379-
"items" => [
380-
%{
381-
"detail" => "module",
382-
"documentation" => _,
383-
"kind" => 9,
384-
"label" => "Foo"
385-
}
386-
| _
387-
]
388-
}) = resp
365+
code = """
366+
defmodule Bar do
367+
def fnuc, do: App2.Fo
368+
# ^
369+
end
370+
"""
371+
372+
Server.receive_packet(server, did_open(uri, "elixir", 1, code))
373+
Server.receive_packet(server, completion_req(3, uri, 1, 23))
374+
375+
resp = assert_receive(%{"id" => 3}, 5000)
376+
377+
assert response(3, %{
378+
"isIncomplete" => false,
379+
"items" => [
380+
%{
381+
"detail" => "module",
382+
"documentation" => _,
383+
"kind" => 9,
384+
"label" => "Foo"
385+
}
386+
| _
387+
]
388+
}) = resp
389+
end)
389390
end)
390391
end
392+
393+
defp with_new_server(func) do
394+
server = start_supervised!({Server, nil})
395+
packet_capture = start_supervised!({PacketCapture, self()})
396+
Process.group_leader(server, packet_capture)
397+
398+
try do
399+
func.(server)
400+
after
401+
stop_supervised(Server)
402+
stop_supervised(PacketCapture)
403+
flush_mailbox()
404+
end
405+
end
406+
407+
defp flush_mailbox do
408+
receive do
409+
_ -> flush_mailbox()
410+
after
411+
0 -> :ok
412+
end
413+
end
414+
415+
defp wait_until_compiled(pid) do
416+
state = :sys.get_state(pid)
417+
418+
if state.build_running? do
419+
Process.sleep(500)
420+
wait_until_compiled(pid)
421+
end
422+
end
391423
end

0 commit comments

Comments
 (0)