Skip to content

Commit

Permalink
Improve tunnel client test case
Browse files Browse the repository at this point in the history
  • Loading branch information
xinz committed Oct 14, 2021
1 parent 5657b0d commit a68b13f
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions test/tunnel/client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,7 @@ defmodule ExAliyunOtsTest.Tunnel do
end

test "describe tunnel", context do
tunnel = context[:tunnel]

{:ok, response} =
Client.describe_tunnel(@instance_key,
table_name: @table_name,
tunnel_name: tunnel.tunnel_name,
tunnel_id: tunnel.tunnel_id
)

Logger.info("describe tunnel response: #{inspect(response)}")
[channel] = response.channels
assert channel.channel_rpo == 0
verify_describe_tunnel(context[:tunnel])
end

test "connect and heartbeat tunnel", context do
Expand All @@ -98,15 +87,7 @@ defmodule ExAliyunOtsTest.Tunnel do

assert length(heartbeat_response.channels) >= 0

{:ok, response} =
Client.describe_tunnel(@instance_key,
table_name: @table_name,
tunnel_name: tunnel.tunnel_name,
tunnel_id: tunnel_id
)

Logger.info("describe tunnel response: #{inspect(response)}")
[channel] = response.channels
channel = verify_describe_tunnel(tunnel)

channel_id = channel.channel_id

Expand Down Expand Up @@ -171,4 +152,27 @@ defmodule ExAliyunOtsTest.Tunnel do
updated_records = response.records ++ records
read_all_records(response.next_token, updated_records, tunnel_id, client_id, channel_id)
end

defp verify_describe_tunnel(tunnel) do
{:ok, response} =
Client.describe_tunnel(@instance_key,
table_name: @table_name,
tunnel_name: tunnel.tunnel_name,
tunnel_id: tunnel.tunnel_id
)

Logger.info("describe tunnel response: #{inspect(response)}")

case response.channels do
[] ->
assert response.tunnel.stage == "InitBaseDataAndStreamShard"
Process.sleep(1_000)
verify_describe_tunnel(tunnel)
[channel] ->
assert channel.channel_status in ["WAIT", "OPEN"]
assert response.tunnel.stage == "ProcessBaseData"
assert channel.channel_rpo == 0
channel
end
end
end

0 comments on commit a68b13f

Please sign in to comment.