Skip to content

Commit 318d0d6

Browse files
committed
Reintroduce full server testing with different approach
Now we start manually all application children instead of ensuring the application has started
1 parent fe14474 commit 318d0d6

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

apps/expert/test/expert_test.exs

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,83 @@
11
defmodule Expert.ExpertTest do
2-
use ExUnit.Case, async: true
2+
alias Forge.Test.Fixtures
3+
4+
use ExUnit.Case, async: false
5+
use Forge.Test.EventualAssertions
36
use Patch
47

58
require GenLSP.Test
69

710
import Expert.Test.Protocol.TransportSupport
811

12+
describe "server testing" do
13+
defp buffer_opts do
14+
[communication: {GenLSP.Communication.TCP, [port: 0]}]
15+
end
16+
17+
defp start_application_children do
18+
pids =
19+
for child_spec <- Expert.Application.children(buffer: buffer_opts()) do
20+
start_supervised!(child_spec)
21+
end
22+
23+
on_exit(fn ->
24+
# NOTE: The test hangs for some reason without manually exiting
25+
for pid <- pids do
26+
Process.exit(pid, :normal)
27+
end
28+
end)
29+
end
30+
31+
setup do
32+
start_application_children()
33+
34+
comm_state = GenLSP.Buffer.comm_state(Expert.Buffer)
35+
36+
{:ok, port} = :inet.port(comm_state.lsocket)
37+
%{lsp: lsp} = :sys.get_state(Expert.Buffer)
38+
39+
expert = %{lsp: lsp, port: port}
40+
client = GenLSP.Test.client(expert)
41+
42+
[expert: expert, client: client]
43+
end
44+
45+
test "replies to initialize with expert info and capabilities", %{client: client} do
46+
id = System.unique_integer([:positive])
47+
48+
project = Fixtures.project()
49+
50+
root_uri = project.root_uri
51+
root_path = Forge.Project.root_path(project)
52+
53+
assert :ok ==
54+
GenLSP.Test.request(client, %{
55+
"id" => id,
56+
"jsonrpc" => "2.0",
57+
"method" => "initialize",
58+
"params" => %{
59+
"rootPath" => root_path,
60+
"rootUri" => root_uri,
61+
"capabilities" => %{},
62+
"workspaceFolders" => [
63+
%{
64+
uri: root_uri,
65+
name: root_path
66+
}
67+
]
68+
}
69+
})
70+
71+
GenLSP.Test.assert_result(^id, result, 500)
72+
73+
{:ok, initialize_result} =
74+
GenLSP.Requests.Initialize.result()
75+
|> Schematic.dump(Expert.State.initialize_result())
76+
77+
assert result == initialize_result
78+
end
79+
end
80+
981
test "sends an error message on engine initialization error" do
1082
with_patched_transport()
1183

0 commit comments

Comments
 (0)