Skip to content

Commit 8e144de

Browse files
authored
Fix Connection state created by build_direct_state (#480)
1 parent 0332faa commit 8e144de

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

grpc_client/lib/grpc/client/connection.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ defmodule GRPC.Client.Connection do
8383

8484
@type t :: %__MODULE__{
8585
virtual_channel: Channel.t(),
86-
real_channels: %{String.t() => Channel.t()},
86+
real_channels: %{String.t() => {:ok, Channel.t()} | {:error, any()}},
8787
lb_mod: module() | nil,
8888
lb_state: term() | nil,
8989
resolver: module() | nil,
@@ -446,7 +446,7 @@ defmodule GRPC.Client.Connection do
446446
%__MODULE__{
447447
base_state
448448
| virtual_channel: ch,
449-
real_channels: %{"#{host}:#{port}" => ch}
449+
real_channels: %{"#{host}:#{port}" => {:ok, ch}}
450450
}}
451451

452452
{:error, reason} ->

grpc_client/test/grpc/channel_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ defmodule GRPC.ChannelTest do
1010
GRPC.Stub.connect("http://#{unquote(addr)}:50051", adapter: ClientAdapter)
1111

1212
assert %Channel{host: unquote(addr), port: 50051, scheme: "http", cred: nil} = channel
13+
14+
assert {:ok, _} = GRPC.Stub.disconnect(channel)
1315
end
1416

1517
test "errors if credential is provided" do
@@ -31,6 +33,8 @@ defmodule GRPC.ChannelTest do
3133
assert Keyword.has_key?(cred.ssl, :verify)
3234
assert Keyword.has_key?(cred.ssl, :depth)
3335
assert Keyword.has_key?(cred.ssl, :cacert_file)
36+
37+
assert {:ok, _} = GRPC.Stub.disconnect(channel)
3438
end
3539

3640
test "allows overriding default credentials" do
@@ -40,13 +44,17 @@ defmodule GRPC.ChannelTest do
4044
GRPC.Stub.connect("https://#{unquote(addr)}:50051", adapter: ClientAdapter, cred: cred)
4145

4246
assert %Channel{host: unquote(addr), port: 50051, scheme: "https", cred: ^cred} = channel
47+
48+
assert {:ok, _} = GRPC.Stub.disconnect(channel)
4349
end
4450
end
4551

4652
describe "connect/2 with no scheme, #{kind} and" do
4753
test "no cred uses http" do
4854
{:ok, channel} = GRPC.Stub.connect("#{unquote(addr)}:50051", adapter: ClientAdapter)
4955
assert %Channel{host: unquote(addr), port: 50051, scheme: "http", cred: nil} = channel
56+
57+
assert {:ok, _} = GRPC.Stub.disconnect(channel)
5058
end
5159

5260
test "cred uses https" do
@@ -56,6 +64,8 @@ defmodule GRPC.ChannelTest do
5664
GRPC.Stub.connect("#{unquote(addr)}:50051", adapter: ClientAdapter, cred: cred)
5765

5866
assert %Channel{host: unquote(addr), port: 50051, scheme: "https", cred: ^cred} = channel
67+
68+
assert {:ok, _} = GRPC.Stub.disconnect(channel)
5969
end
6070
end
6171
end
@@ -67,5 +77,7 @@ defmodule GRPC.ChannelTest do
6777
GRPC.Stub.connect("http://10.0.0.1:50051", adapter: ClientAdapter, headers: headers)
6878

6979
assert %Channel{host: "10.0.0.1", port: 50051, headers: ^headers} = channel
80+
81+
assert {:ok, _} = GRPC.Stub.disconnect(channel)
7082
end
7183
end

0 commit comments

Comments
 (0)