Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Allow not all stats to be equal in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed May 31, 2023
1 parent 1b6ede2 commit 75e3397
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions integration_test/test_videoroom/test/integration/simulcast_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ defmodule TestVideoroom.Integration.SimulcastTest do
# we set stats_number to 15 and stats interval to 1s -
# we will fetch stats every 2 seconds
@stats_number 15

@stats_interval 1_000
# time needed to request and receive a variant
@variant_request_time 2_000
Expand Down Expand Up @@ -348,11 +349,7 @@ defmodule TestVideoroom.Integration.SimulcastTest do
end
end

defp assert_receiver_encoding(receiver_stats, encoding) do
receiver_stats["encoding"] == encoding
end

defp assert_stats_equal(receiver_stats, sender_encoding_stats) do
defp are_stats_equal(receiver_stats, sender_encoding_stats) do
# According to WebRTC standard, receiver is never aware of simulcast. Sender sends multiple encodings to SFU,
# but SFU is switching between them transparently, forwarding always only one encoding to the receiver
correct_dimensions? =
Expand All @@ -368,15 +365,34 @@ defmodule TestVideoroom.Integration.SimulcastTest do
sender_stats_samples,
receiver_stats_samples
) do
sender_stats_samples
|> Enum.zip(receiver_stats_samples)
|> Enum.all?(fn {sender_stats, receiver_stats} ->
assert_stats_equal(receiver_stats, sender_stats[receiver_encoding]) and
assert_receiver_encoding(receiver_stats, receiver_encoding)
end)
|> assert("Failed on tag: #{tag} should be encoding: #{receiver_encoding},
receiver stats are: #{inspect(receiver_stats_samples, limit: :infinity, pretty: true)}
sender stats are: #{inspect(Enum.map(sender_stats_samples, & &1[receiver_encoding]), limit: :infinity, pretty: true)}
")
assert length(sender_stats_samples) == length(receiver_stats_samples)

# minimal number of consequtive stats that have to be
# equal. They are counted up to the end meaning
# [true, true, false] is not the same as
# [false, true, true] i.e. the first one will
# always fail as once we start getting equal
# stats we cannot have regression
min_equal_stats_number = div(length(sender_stats_samples), 2)

equal_stats_samples =
sender_stats_samples
|> Enum.zip(receiver_stats_samples)
|> Enum.map(fn {sender_stats, receiver_stats} ->
are_stats_equal(receiver_stats, sender_stats[receiver_encoding]) and
receiver_stats["encoding"] == receiver_encoding
end)
|> Enum.drop_while(fn result -> result == false end)

if Enum.all?(equal_stats_samples) and length(equal_stats_samples) >= min_equal_stats_number do
true
else
raise """
Failed on tag: #{tag} should be encoding: #{receiver_encoding},
required minimum #{min_equal_stats_number} of consequtive stats to be equal.
All receiver stats are: #{inspect(receiver_stats_samples, limit: :infinity, pretty: true)}
All sender stats are: #{inspect(Enum.map(sender_stats_samples, & &1[receiver_encoding]), limit: :infinity, pretty: true)}
"""
end
end
end

0 comments on commit 75e3397

Please sign in to comment.