Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
LVala committed Aug 28, 2024
1 parent 9b3a2cc commit 8db9248
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/ex_webrtc/data_channel_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ defmodule ExWebRTC.DataChannelTest do
%{pc1: pc1, pc2: pc2, ref1: ref1, ref2: ref2}
end

test "message from initiating peer", %{pc1: pc1, pc2: pc2, ref1: ref1, ref2: ref2} do
test "from initiating peer", %{pc1: pc1, pc2: pc2, ref1: ref1, ref2: ref2} do
data1 = <<1, 2, 3>>
:ok = PeerConnection.send_data(pc1, ref1, data1)
assert_receive {:ex_webrtc, ^pc2, {:data, ^ref2, ^data1}}
Expand Down Expand Up @@ -200,5 +200,21 @@ defmodule ExWebRTC.DataChannelTest do
:ok = PeerConnection.send_data(pc2, ref2, msg)
assert_receive {:ex_webrtc, ^pc1, {:data, ^ref1, ^data}}
end

test "and collecting stats about it", %{pc1: pc1, pc2: pc2, ref1: ref1} do
for _ <- 1..10 do
:ok = PeerConnection.send_data(pc1, ref1, <<1, 2, 3>>)
end

stats1 = PeerConnection.get_stats(pc1)
assert {_ref, channel_stats1} = Enum.find(stats1, fn {_, v} -> v.type == :data_channel end)
assert channel_stats1.bytes_sent == 30
assert channel_stats1.messages_sent == 10

stats2 = PeerConnection.get_stats(pc2)
assert {_ref, channel_stats2} = Enum.find(stats2, fn {_, v} -> v.type == :data_channel end)
assert channel_stats2.bytes_received == 30
assert channel_stats2.messages_received == 10
end
end
end

0 comments on commit 8db9248

Please sign in to comment.